<commit_before>package com.google.moviestvsentiments.service.assetSentiment;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MediatorLiveData;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import com.google.moviestvsentiments.model.Asset;
import com.google.moviestvsentiments.model.AssetSentiment;
import com.google.moviestvsentiments.model.AssetType;
import com.google.moviestvsentiments.model.SentimentType;
import java.util.ArrayList;
import java.util.List;

@Dao
public abstract class AssetSentimentDao {

    /**
     * Adds the given asset into the assets table. If the asset already exists, it is ignored.
     * @param asset The asset to insert.
     */
    @Insert(onConflict = OnConflictStrategy.IGNORE)
    public abstract void addAsset(Asset asset);

    /**
     * Returns a LiveData view of the asset with the given id and type or null if the asset does not
     * exist.
     * @param assetId The id of the asset.
     * @param assetType The type of the asset.
     * @return A LiveData object containing the asset matching the id and type.
     */
    @Query("SELECT L.*, sentiment_type AS sentimentType " +
            "FROM assets_table AS L " +
            "LEFT JOIN user_sentiments_table AS R " +
            "ON L.asset_id = R.asset_id AND account_name = :accountName AND L.asset_type = R.asset_type " +
            "WHERE L.asset_id = :assetId AND L.asset_type = :assetType")
    public abstract LiveData<AssetSentiment> getAsset(String accountName, String assetId,
                                                      AssetType assetType);

    /**
     * Returns a LiveData list of assets matching the given type that have been reacted to with the
     * given sentiment by the given account. If the sentiment type is UNSPECIFIED, assets with no
     * corresponding user sentiment record will also be returned.
     * @param assetType The type of asset to include in the results.
     * @param accountName The account name to use when checking assets for sentiments.
     * @param sentimentType The sentiment type to check for.
     * @return A LiveData list of assets with reactions matching the given account name and
     * sentiment type.
     */
    public LiveData<List<AssetSentiment>> getAssets(AssetType assetType, String accountName,
                                                    SentimentType sentimentType) {
        LiveData<List<AssetSentiment>> reactionResults = getAssetsWithSentiment(assetType,
                accountName, sentimentType);
        if (sentimentType != SentimentType.UNSPECIFIED) {
            return reactionResults;
        }

        LiveData<List<AssetSentiment>> noReactionResults = getAssetsWithoutSentiment(assetType,
                accountName);
        MediatorLiveData<List<AssetSentiment>> allResults = new MediatorLiveData<>();
        allResults.addSource(reactionResults, values -> combineLiveDataLists(allResults, values,
                noReactionResults));
        allResults.addSource(noReactionResults, values -> combineLiveDataLists(allResults, values,
                reactionResults));
        return allResults;
    }

    /**
     * Returns a LiveData list of assets with reactions that match the given account name and
     * sentiment type.
     * @param assetType The type of asset to include in the results.
     * @param accountName The account name to use when checking assets for sentiments.
     * @param sentimentType The sentiment type to check for.
     * @return A LiveData list of assets with reactions matching the given account name and
     * sentiment type.
     */
    @Query("SELECT *, :sentimentType AS sentimentType " +
            "FROM assets_table as L " +
            "WHERE EXISTS " +
            "(SELECT * FROM user_sentiments_table AS R " +
                "WHERE L.asset_id = R.asset_id AND account_name = :accountName " +
                "AND asset_type = :assetType AND sentiment_type = :sentimentType)")
    protected abstract LiveData<List<AssetSentiment>> getAssetsWithSentiment(AssetType assetType,
                                                 String accountName, SentimentType sentimentType);

    /**
     * Returns a LiveData list of assets that have not been reacted to by the given account name and
     * therefore have no matching user sentiment record.
     * @param assetType The type of asset to include in the results.
     * @param accountName The account name to use when checking for sentiments.
     * @return A LiveData list of assets that have not been reacted to by the given account.
     */
    @Query("SELECT *, NULL AS sentimentType " +
            "FROM assets_table AS L " +
            "WHERE L.asset_type = :assetType AND NOT EXISTS " +
            "(SELECT * FROM user_sentiments_table AS R " +
                "WHERE L.asset_id = R.asset_id AND account_name = :accountName " +
                "AND L.asset_type = R.asset_type)")
    protected abstract LiveData<List<AssetSentiment>> getAssetsWithoutSentiment(AssetType assetType,
                                                                                String accountName);
<commit_msg>Update return types in Javadoc<commit_after>package com.google.moviestvsentiments.service.assetSentiment;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MediatorLiveData;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import com.google.moviestvsentiments.model.Asset;
import com.google.moviestvsentiments.model.AssetSentiment;
import com.google.moviestvsentiments.model.AssetType;
import com.google.moviestvsentiments.model.SentimentType;
import java.util.ArrayList;
import java.util.List;

@Dao
public abstract class AssetSentimentDao {

    /**
     * Adds the given asset into the assets table. If the asset already exists, it is ignored.
     * @param asset The asset to insert.
     */
    @Insert(onConflict = OnConflictStrategy.IGNORE)
    public abstract void addAsset(Asset asset);

    /**
     * Returns a LiveData view of the asset with the given id and type or null if the asset does not
     * exist. The asset is combined with the matching user sentiment and returned as an
     * AssetSentiment object.
     * @param accountName The name of the account to match with the sentiment.
     * @param assetId The id of the asset.
     * @param assetType The type of the asset.
     * @return A LiveData object containing the AssetSentiment matching the account name, asset id
     * and asset type.
     */
    @Query("SELECT L.*, sentiment_type AS sentimentType " +
            "FROM assets_table AS L " +
            "LEFT JOIN user_sentiments_table AS R " +
            "ON L.asset_id = R.asset_id AND account_name = :accountName AND L.asset_type = R.asset_type " +
            "WHERE L.asset_id = :assetId AND L.asset_type = :assetType")
    public abstract LiveData<AssetSentiment> getAsset(String accountName, String assetId,
                                                      AssetType assetType);

    /**
     * Returns a LiveData list of AssetSentiments matching the given type that have been reacted to
     * with the given sentiment by the given account. If the sentiment type is UNSPECIFIED, assets
     * with no corresponding user sentiment record will also be returned.
     * @param assetType The type of asset to include in the results.
     * @param accountName The account name to use when checking assets for sentiments.
     * @param sentimentType The sentiment type to check for.
     * @return A LiveData list of AssetSentiments with reactions matching the given account
     * name and sentiment type.
     */
    public LiveData<List<AssetSentiment>> getAssets(AssetType assetType, String accountName,
                                                    SentimentType sentimentType) {
        LiveData<List<AssetSentiment>> reactionResults = getAssetsWithSentiment(assetType,
                accountName, sentimentType);
        if (sentimentType != SentimentType.UNSPECIFIED) {
            return reactionResults;
        }

        LiveData<List<AssetSentiment>> noReactionResults = getAssetsWithoutSentiment(assetType,
                accountName);
        MediatorLiveData<List<AssetSentiment>> allResults = new MediatorLiveData<>();
        allResults.addSource(reactionResults, values -> combineLiveDataLists(allResults, values,
                noReactionResults));
        allResults.addSource(noReactionResults, values -> combineLiveDataLists(allResults, values,
                reactionResults));
        return allResults;
    }

    /**
     * Returns a LiveData list of AssetSentiments with reactions that match the given account name
     * and sentiment type.
     * @param assetType The type of asset to include in the results.
     * @param accountName The account name to use when checking assets for sentiments.
     * @param sentimentType The sentiment type to check for.
     * @return A LiveData list of AssetSentiments with reactions matching the given asset type,
     * account name and sentiment type.
     */
    @Query("SELECT *, :sentimentType AS sentimentType " +
            "FROM assets_table as L " +
            "WHERE EXISTS " +
            "(SELECT * FROM user_sentiments_table AS R " +
                "WHERE L.asset_id = R.asset_id AND account_name = :accountName " +
                "AND asset_type = :assetType AND sentiment_type = :sentimentType)")
    protected abstract LiveData<List<AssetSentiment>> getAssetsWithSentiment(AssetType assetType,
                                                 String accountName, SentimentType sentimentType);

    /**
     * Returns a LiveData list of assets that have not been reacted to by the given account name and
     * therefore have no matching user sentiment record.
     * @param assetType The type of asset to include in the results.
     * @param accountName The account name to use when checking for sentiments.
     * @return A LiveData list of AssetSentiments that have not been reacted to by the given account.
     */
    @Query("SELECT *, NULL AS sentimentType " +
            "FROM assets_table AS L " +
            "WHERE L.asset_type = :assetType AND NOT EXISTS " +
            "(SELECT * FROM user_sentiments_table AS R " +
                "WHERE L.asset_id = R.asset_id AND account_name = :accountName " +
                "AND L.asset_type = R.asset_type)")
    protected abstract LiveData<List<AssetSentiment>> getAssetsWithoutSentiment(AssetType assetType,
                                                                                String accountName);

{'fraction_non_alphanumeric': 0.06661053419403125, 'fraction_numerical': 0.0, 'mean_word_length': 2.645975443383356, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7156549', 'n_tokens_mistral': 2727, 'n_tokens_neox': 2632, 'n_words': 973}