<commit_before>package com.jamieadkins.gwent.data.interactor;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.google.firebase.database.ValueEventListener;
import com.jamieadkins.gwent.base.BaseSingleObserver;
import com.jamieadkins.gwent.card.CardFilter;
import com.jamieadkins.gwent.data.CardDetails;
import com.jamieadkins.gwent.data.FirebaseUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;

import io.reactivex.Completable;
import io.reactivex.CompletableEmitter;
import io.reactivex.CompletableOnSubscribe;
import io.reactivex.CompletableSource;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.ObservableSource;
import io.reactivex.Single;
import io.reactivex.SingleEmitter;
import io.reactivex.SingleOnSubscribe;
import io.reactivex.SingleSource;
import io.reactivex.schedulers.Schedulers;

/**
 * Deals with firebase.
 */

public class CardsInteractorFirebase implements CardsInteractor {
    private static final String PATCH_PATH = "card-data/latest-patch";

    private final FirebaseDatabase mDatabase = FirebaseDatabase.getInstance();
    private DatabaseReference mCardsReference;
    private final DatabaseReference mMistakesReference;
    private final DatabaseReference mPatchReference;

    private Query mCardsQuery;
    private ValueEventListener mCardListener;
    private String mLocale = "en-US";

    private static CardsInteractorFirebase mInstance;

    public static CardsInteractorFirebase getInstance() {
        if (mInstance == null) {
            mInstance = new CardsInteractorFirebase();
        }

        return mInstance;
    }

    private CardsInteractorFirebase() {
        mPatchReference = mDatabase.getReference(PATCH_PATH);
        mMistakesReference = mDatabase.getReference("reported-mistakes");
    }

    private void onPatchUpdated(String patch) {
        mCardsReference = mDatabase.getReference("card-data/" + patch);
        // Keep Cards data in cache at all times.
        mCardsReference.keepSynced(true);<commit_msg>Use a different latest-patch path for debug builds<commit_after>package com.jamieadkins.gwent.data.interactor;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.google.firebase.database.ValueEventListener;
import com.jamieadkins.gwent.BuildConfig;
import com.jamieadkins.gwent.base.BaseSingleObserver;
import com.jamieadkins.gwent.card.CardFilter;
import com.jamieadkins.gwent.data.CardDetails;
import com.jamieadkins.gwent.data.FirebaseUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;

import io.reactivex.Completable;
import io.reactivex.CompletableEmitter;
import io.reactivex.CompletableOnSubscribe;
import io.reactivex.CompletableSource;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.ObservableSource;
import io.reactivex.Single;
import io.reactivex.SingleEmitter;
import io.reactivex.SingleOnSubscribe;
import io.reactivex.SingleSource;
import io.reactivex.schedulers.Schedulers;

/**
 * Deals with firebase.
 */

public class CardsInteractorFirebase implements CardsInteractor {
    private static final String PATCH_PATH =
            !BuildConfig.DEBUG ? "card-data/latest-patch" : "card-data/latest-patch-debug";

    private final FirebaseDatabase mDatabase = FirebaseDatabase.getInstance();
    private DatabaseReference mCardsReference;
    private final DatabaseReference mMistakesReference;
    private final DatabaseReference mPatchReference;

    private Query mCardsQuery;
    private ValueEventListener mCardListener;
    private String mLocale = "en-US";

    private static CardsInteractorFirebase mInstance;

    public static CardsInteractorFirebase getInstance() {
        if (mInstance == null) {
            mInstance = new CardsInteractorFirebase();
        }

        return mInstance;
    }

    private CardsInteractorFirebase() {
        mPatchReference = mDatabase.getReference(PATCH_PATH);
        mMistakesReference = mDatabase.getReference("reported-mistakes");
    }

    private void onPatchUpdated(String patch) {
        mCardsReference = mDatabase.getReference("card-data/" + patch);
        // Keep Cards data in cache at all times.
        mCardsReference.keepSynced(true);
{'fraction_non_alphanumeric': 0.08303702154361012, 'fraction_numerical': 0.0, 'mean_word_length': 4.81044957472661, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1377434', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1340, 'n_words': 274}