<commit_before>package de.fau.amos.virtualledger.android.api.contacts;

import android.util.Log;

import java.util.List;

import de.fau.amos.virtualledger.android.api.RestApi;
import de.fau.amos.virtualledger.android.api.auth.AuthenticationProvider;
import de.fau.amos.virtualledger.dtos.Contact;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subjects.PublishSubject;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Simon on 01.07.2017.
 */

public class HTTPContactsProvider implements ContactsProvider{

    private static final String TAG = "HTTPContactsProvider";

    private RestApi restApi;
    private AuthenticationProvider authenticationProvider;

    public HTTPContactsProvider(RestApi restApi, AuthenticationProvider authenticationProvider) {
        this.restApi = restApi;
        this.authenticationProvider = authenticationProvider;
    }

    @Override
    public Observable<List<Contact>> getContacts() {

        final PublishSubject observable = PublishSubject.create();

        authenticationProvider.getToken()
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<String>() {
                    @Override
                    public void accept(@NonNull final String token) throws Exception {
                        // got token
                        final retrofit2.Call<List<Contact>> responseMessage = restApi.getContacts(token);

                        responseMessage.enqueue(new Callback<List<Contact>>() {
                            @Override
                            public void onResponse(retrofit2.Call<List<Contact>> call, Response<List<Contact>> response) {
                                // got response from server
                                if (response.isSuccessful()) {
                                    List<Contact> contacts = response.body();
                                    Log.v(TAG, "Fetching of contacts was successful " + response.code());
                                    observable.onNext(contacts);
                                } else {
                                    Log.e(TAG, "Fetchin of contacts was not successful! ERROR " + response.code());
                                    observable.onError(new Throwable("Fetching of contacts was not successful!"));<commit_msg>Generify observables in HTTPContactsProvider.java<commit_after>package de.fau.amos.virtualledger.android.api.contacts;

import android.util.Log;

import java.util.List;

import de.fau.amos.virtualledger.android.api.RestApi;
import de.fau.amos.virtualledger.android.api.auth.AuthenticationProvider;
import de.fau.amos.virtualledger.dtos.Contact;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subjects.PublishSubject;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Simon on 01.07.2017.
 */

public class HTTPContactsProvider implements ContactsProvider{

    private static final String TAG = "HTTPContactsProvider";

    private RestApi restApi;
    private AuthenticationProvider authenticationProvider;

    public HTTPContactsProvider(RestApi restApi, AuthenticationProvider authenticationProvider) {
        this.restApi = restApi;
        this.authenticationProvider = authenticationProvider;
    }

    @Override
    public Observable<List<Contact>> getContacts() {

        final PublishSubject<List<Contact>> observable = PublishSubject.create();

        authenticationProvider.getToken()
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<String>() {
                    @Override
                    public void accept(@NonNull final String token) throws Exception {
                        // got token
                        final retrofit2.Call<List<Contact>> responseMessage = restApi.getContacts(token);

                        responseMessage.enqueue(new Callback<List<Contact>>() {
                            @Override
                            public void onResponse(retrofit2.Call<List<Contact>> call, Response<List<Contact>> response) {
                                // got response from server
                                if (response.isSuccessful()) {
                                    List<Contact> contacts = response.body();
                                    Log.v(TAG, "Fetching of contacts was successful " + response.code());
                                    observable.onNext(contacts);
                                } else {
                                    Log.e(TAG, "Fetchin of contacts was not successful! ERROR " + response.code());
                                    observable.onError(new Throwable("Fetching of contacts was not successful!"));
{'fraction_non_alphanumeric': 0.08575833493929466, 'fraction_numerical': 0.0046251686259394876, 'mean_word_length': 2.2417239225484074, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '263893', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1244, 'n_words': 262}