<commit_before>package com.cookingfox.android.prefer.sample.prefs;

import com.cookingfox.android.prefer.api.pref.PrefGroup;
import com.cookingfox.android.prefer_rx.api.pref.typed.BooleanRxPref;
import com.cookingfox.android.prefer_rx.api.pref.typed.LongRxPref;
import com.cookingfox.android.prefer_rx.api.pref.typed.StringRxPref;
import com.cookingfox.android.prefer_rx.impl.pref.AndroidRxPrefGroup;
import com.cookingfox.android.prefer_rx.impl.pref.typed.AndroidBooleanRxPref;
import com.cookingfox.android.prefer_rx.impl.pref.typed.AndroidLongRxPref;
import com.cookingfox.android.prefer_rx.impl.pref.typed.AndroidStringRxPref;
import com.cookingfox.android.prefer_rx.impl.prefer.SharedPreferencesRxPrefer;

/**
 * Implementation of {@link RestApiPrefs}.
 */
public class AndroidRestApiPrefs implements RestApiPrefs {

    private final AndroidRxPrefGroup<Key> group;
    private final AndroidStringRxPref<Key> authToken;
    private final AndroidBooleanRxPref<Key> cacheEnabled;
    private final AndroidLongRxPref<Key> updateIntervalSeconds;

    public AndroidRestApiPrefs(SharedPreferencesRxPrefer prefer) {
        group = prefer.addNewGroup(Key.class);
        group.setTitle("REST API");
        group.setSummary("REST API preferences.");

        authToken = group.addNewString(Key.AuthToken, "");
        authToken.setTitle("Authentication token");
        authToken.setSummary("Token for the REST API.");

        cacheEnabled = group.addNewBoolean(Key.CacheEnabled, true);
        cacheEnabled.setTitle("Cache enabled");
        cacheEnabled.setSummary("Whether API results should be cached.");

        updateIntervalSeconds = group.addNewLong(Key.UpdateIntervalSeconds, 60);
        updateIntervalSeconds.setTitle("Update interval (seconds)");
        updateIntervalSeconds.setSummary("How often to fetch new data from the API.");
    }

    @Override
    public StringRxPref<Key> authToken() {
        return authToken;
    }

    @Override
    public BooleanRxPref<Key> cacheEnabled() {
        return cacheEnabled;
    }

    @Override
    public LongRxPref<Key> updateIntervalSeconds() {
        return updateIntervalSeconds;
    }

    @Override
    public PrefGroup<Key> getPrefGroup() {
        return group;
    }

}<commit_msg>Adds validator to sample<commit_after>package com.cookingfox.android.prefer.sample.prefs;

import com.cookingfox.android.prefer.api.pref.PrefGroup;
import com.cookingfox.android.prefer.api.pref.PrefValidator;
import com.cookingfox.android.prefer_rx.api.pref.typed.BooleanRxPref;
import com.cookingfox.android.prefer_rx.api.pref.typed.LongRxPref;
import com.cookingfox.android.prefer_rx.api.pref.typed.StringRxPref;
import com.cookingfox.android.prefer_rx.impl.pref.AndroidRxPrefGroup;
import com.cookingfox.android.prefer_rx.impl.pref.typed.AndroidBooleanRxPref;
import com.cookingfox.android.prefer_rx.impl.pref.typed.AndroidLongRxPref;
import com.cookingfox.android.prefer_rx.impl.pref.typed.AndroidStringRxPref;
import com.cookingfox.android.prefer_rx.impl.prefer.SharedPreferencesRxPrefer;

/**
 * Implementation of {@link RestApiPrefs}.
 */
public class AndroidRestApiPrefs implements RestApiPrefs {

    private final AndroidRxPrefGroup<Key> group;
    private final AndroidStringRxPref<Key> authToken;
    private final AndroidBooleanRxPref<Key> cacheEnabled;
    private final AndroidLongRxPref<Key> updateIntervalSeconds;

    public AndroidRestApiPrefs(SharedPreferencesRxPrefer prefer) {
        group = prefer.addNewGroup(Key.class);
        group.setTitle("REST API");
        group.setSummary("REST API preferences.");

        authToken = group.addNewString(Key.AuthToken, "");
        authToken.setTitle("Authentication token");
        authToken.setSummary("Token for the REST API.");

        cacheEnabled = group.addNewBoolean(Key.CacheEnabled, true);
        cacheEnabled.setTitle("Cache enabled");
        cacheEnabled.setSummary("Whether API results should be cached.");

        updateIntervalSeconds = group.addNewLong(Key.UpdateIntervalSeconds, 60);
        updateIntervalSeconds.setTitle("Update interval (seconds)");
        updateIntervalSeconds.setSummary("How often to fetch new data from the API.");
        updateIntervalSeconds.setValidator(new PrefValidator<Long>() {
            @Override
            public boolean validate(Long value) throws Exception {
                if (value < 1) {
                    throw new Exception("Minimum value must be 1");
                }

                return true;
            }
        });
    }

    @Override
    public StringRxPref<Key> authToken() {
        return authToken;
    }

    @Override
    public BooleanRxPref<Key> cacheEnabled() {
        return cacheEnabled;
    }

    @Override
    public LongRxPref<Key> updateIntervalSeconds() {
        return updateIntervalSeconds;
    }

    @Override
    public PrefGroup<Key> getPrefGroup() {
        return group;
    }

}
{'fraction_non_alphanumeric': 0.09672164528609245, 'fraction_numerical': 0.0012217470983506415, 'mean_word_length': 3.75968992248062, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 20, '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': '5632845', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1381, 'n_words': 254}