<commit_before>package edu.rpi.cs.yacs.retrofit;

import android.app.Activity;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import java.lang.annotation.Retention;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * Created by <NAME> on 9/24/16.
 */

class ServiceHelper {
    @Retention(RUNTIME)
    @interface Json {
    }

    private YACSService service;
    private Activity activity;

    private ServiceHelper(Activity activity) {
        this.activity = activity;

        invalidateService();
    }

    public YACSService getService() {
        return service;
    }

    /**
     * This method is used when we need to invalidate the YACSService
     * @return new YACSService that uses the latest "House of YACS" setting
     */
    public YACSService invalidateService() {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);

        // If exists, return String value
        // Otherwise, return "unknown"
        String houseOfYACS = preferences.getString("House of YACS", "unknown");

        String baseURL = convertHouseToURL(houseOfYACS);

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(baseURL)
                .addConverterFactory(new JsonStringConverterFactory(GsonConverterFactory.create()))
                .build();

        service = retrofit.create(YACSService.class);

        return service;
    }

    /**
     * This method returns the YACS URL of the input college name.
     * @param house College name
     * @return College YACS URL if College supports YACS. Otherwise, returns "not supported yet"
     */
    private String convertHouseToURL(String house) {<commit_msg>Modify ServiceHelper<commit_after>package edu.rpi.cs.yacs.retrofit;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import java.lang.annotation.Retention;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * Created by <NAME> on 9/24/16.
 */

public class ServiceHelper {
    @Retention(RUNTIME)
    @interface Json {
    }

    private YACSService service;
    private Context context;

    public ServiceHelper(Context context) {
        this.context = context;

        invalidateService();
    }

    public YACSService getService() {
        return service;
    }

    /**
     * This method is used when we need to invalidate the YACSService
     * @return new YACSService that uses the latest "House of YACS" setting
     */
    public YACSService invalidateService() {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);

        // If exists, set to String value
        // Otherwise, set to "unknown"
        String houseOfYACS = preferences.getString("House of YACS", "unknown");

        String baseURL = convertHouseToURL(houseOfYACS);

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(baseURL)
                .addConverterFactory(new JsonStringConverterFactory(GsonConverterFactory.create()))
                .build();

        service = retrofit.create(YACSService.class);

        return service;
    }

    /**
     * This method returns the YACS URL of the input college name.
     * @param house College name
     * @return College YACS URL if College supports YACS. Otherwise, returns "not supported yet"
     */
    private String convertHouseToURL(String house) {
{'fraction_non_alphanumeric': 0.08335618316424459, 'fraction_numerical': 0.003838771593090211, 'mean_word_length': 2.995618838992333, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '979541', 'n_tokens_mistral': 1025, 'n_tokens_neox': 968, 'n_words': 270}