<commit_before>package org.zeroxlab.momodict;

import android.content.Context;
import android.support.annotation.NonNull;

import org.zeroxlab.momodict.db.realm.RealmStore;
import org.zeroxlab.momodict.model.Book;
import org.zeroxlab.momodict.model.Card;
import org.zeroxlab.momodict.model.Entry;
import org.zeroxlab.momodict.model.Record;
import org.zeroxlab.momodict.model.Store;

import java.util.Collections;
import java.util.List;

import rx.Observable;

public class Controller {

    private Context mCtx;
    private Store mStore;

    public Controller(@NonNull Context ctx) {
        mCtx = ctx;
        mStore = new RealmStore(mCtx);
    }

    public Observable<Book> getBooks() {
        return Observable.from(mStore.getBooks());
    }

    public Observable<Entry> queryEntries(String keyWord) {
        List<Entry> list = mStore.queryEntries(keyWord);

        Collections.sort(list, (left, right) -> {
            return left.wordStr.indexOf(keyWord) - right.wordStr.indexOf(keyWord);
        });
        return Observable.from(list).distinct((item) -> item.wordStr);
    }

    public Observable<Entry> getEntries(String keyWord) {
        List<Entry> list = mStore.getEntries(keyWord);

        Collections.sort(list, (left, right) -> {
            return left.wordStr.indexOf(keyWord) - right.wordStr.indexOf(keyWord);
        });
        return Observable.from(list).distinct((item) -> item.wordStr);
    }

    public Observable<Record> getRecords() {
        List<Record> records = mStore.getRecords();
        Collections.sort(records, (left, right) -> {
            // sorting by time. Move latest one to head
            return left.time.before(right.time) ? 1 : -1;
        });
        return Observable.from(records);
    }

    public void clearRecords() {
        getRecords().subscribe(
                (record -> mStore.removeRecords(record.wordStr)));
    }

    public boolean setRecord(@NonNull Record record) {
        return mStore.upsertRecord(record);
    }

    public boolean removeRecord(@NonNull String keyWord) {
        return mStore.removeRecords(keyWord);
    }
<commit_msg>fix: this API should not use distinct<commit_after>package org.zeroxlab.momodict;

import android.content.Context;
import android.support.annotation.NonNull;

import org.zeroxlab.momodict.db.realm.RealmStore;
import org.zeroxlab.momodict.model.Book;
import org.zeroxlab.momodict.model.Card;
import org.zeroxlab.momodict.model.Entry;
import org.zeroxlab.momodict.model.Record;
import org.zeroxlab.momodict.model.Store;

import java.util.Collections;
import java.util.List;

import rx.Observable;

public class Controller {

    private Context mCtx;
    private Store mStore;

    public Controller(@NonNull Context ctx) {
        mCtx = ctx;
        mStore = new RealmStore(mCtx);
    }

    public Observable<Book> getBooks() {
        return Observable.from(mStore.getBooks());
    }

    public Observable<Entry> queryEntries(String keyWord) {
        List<Entry> list = mStore.queryEntries(keyWord);

        Collections.sort(list, (left, right) -> {
            return left.wordStr.indexOf(keyWord) - right.wordStr.indexOf(keyWord);
        });
        return Observable.from(list).distinct((item) -> item.wordStr);
    }

    public Observable<Entry> getEntries(String keyWord) {
        List<Entry> list = mStore.getEntries(keyWord);

        Collections.sort(list, (left, right) -> {
            return left.wordStr.indexOf(keyWord) - right.wordStr.indexOf(keyWord);
        });
        return Observable.from(list);
    }

    public Observable<Record> getRecords() {
        List<Record> records = mStore.getRecords();
        Collections.sort(records, (left, right) -> {
            // sorting by time. Move latest one to head
            return left.time.before(right.time) ? 1 : -1;
        });
        return Observable.from(records);
    }

    public void clearRecords() {
        getRecords().subscribe(
                (record -> mStore.removeRecords(record.wordStr)));
    }

    public boolean setRecord(@NonNull Record record) {
        return mStore.upsertRecord(record);
    }

    public boolean removeRecord(@NonNull String keyWord) {
        return mStore.removeRecords(keyWord);
    }

{'fraction_non_alphanumeric': 0.11646586345381527, 'fraction_numerical': 0.0009449562957713206, 'mean_word_length': 2.9349442379182156, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 28, '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': '4666006', 'n_tokens_mistral': 1273, 'n_tokens_neox': 1240, 'n_words': 249}