<commit_before>package com.ironz.binaryprefs.events;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import com.ironz.binaryprefs.Preferences;
import com.ironz.binaryprefs.cache.CacheProvider;
import com.ironz.binaryprefs.encryption.ByteEncryption;

import java.util.ArrayList;
import java.util.List;

/**
 * Uses global broadcast receiver mechanism for delivering all key change events.
 * Main propose for using this implementation is IPC mechanism.
 */
@SuppressWarnings("unused")
public class BroadcastPreferenceEventBridgeImpl implements PreferenceEventBridge {

    private static final String ACTION_PREFERENCE_UPDATED = "com.ironz.binaryprefs.ACTION_PREFERENCE_UPDATED";
    private static final String ACTION_PREFERENCE_REMOVED = "com.ironz.binaryprefs.ACTION_PREFERENCE_REMOVED";

    private static final String PREFERENCE_NAME = "preference_name";
    private static final String PREFERENCE_KEY = "preference_update_key";
    private static final String PREFERENCE_VALUE = "preference_update_value";

    private final List<OnSharedPreferenceChangeListener> listeners = new ArrayList<>();
    private final IntentFilter updateFilter = new IntentFilter(ACTION_PREFERENCE_UPDATED);
    private final IntentFilter removeFilter = new IntentFilter(ACTION_PREFERENCE_REMOVED);

    private final BroadcastReceiver updateReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            notifyUpdate(intent);
        }
    };

    private final BroadcastReceiver removeReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            notifyRemove(intent);
        }
    };

    private final Context context;
    private final String prefName;
    private final CacheProvider cacheProvider;
    private final ByteEncryption byteEncryption;

    public BroadcastPreferenceEventBridgeImpl(Context context,
                                              String prefName,
                                              CacheProvider cacheProvider,
                                              ByteEncryption byteEncryption) {
        this.context = context;
        this.prefName = prefName;
        this.cacheProvider = cacheProvider;
        this.byteEncryption = byteEncryption;
    }

    private void notifyUpdate(Intent intent) {
        if (!prefName.equals(intent.getStringExtra(PREFERENCE_NAME))) {
            return;
        }
        String key = intent.getStringExtra(PREFERENCE_KEY);
        byte[] bytes = intent.getByteArrayExtra(PREFERENCE_VALUE);
        notify(key, bytes);
    }

    public void notify(String key, byte[] bytes) {
        byte[] decrypt = byteEncryption.decrypt(bytes);
        cacheProvider.put(key, decrypt);
        notifyListeners(key);
    }

    private void notifyRemove(Intent intent) {<commit_msg>inlined some method<commit_after>package com.ironz.binaryprefs.events;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import com.ironz.binaryprefs.Preferences;
import com.ironz.binaryprefs.cache.CacheProvider;
import com.ironz.binaryprefs.encryption.ByteEncryption;

import java.util.ArrayList;
import java.util.List;

/**
 * Uses global broadcast receiver mechanism for delivering all key change events.
 * Main propose for using this implementation is IPC mechanism.
 */
@SuppressWarnings("unused")
public final class BroadcastPreferenceEventBridgeImpl implements PreferenceEventBridge {

    private static final String ACTION_PREFERENCE_UPDATED = "com.ironz.binaryprefs.ACTION_PREFERENCE_UPDATED";
    private static final String ACTION_PREFERENCE_REMOVED = "com.ironz.binaryprefs.ACTION_PREFERENCE_REMOVED";

    private static final String PREFERENCE_NAME = "preference_name";
    private static final String PREFERENCE_KEY = "preference_update_key";
    private static final String PREFERENCE_VALUE = "preference_update_value";

    private final List<OnSharedPreferenceChangeListener> listeners = new ArrayList<>();
    private final IntentFilter updateFilter = new IntentFilter(ACTION_PREFERENCE_UPDATED);
    private final IntentFilter removeFilter = new IntentFilter(ACTION_PREFERENCE_REMOVED);

    private final BroadcastReceiver updateReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            notifyUpdate(intent);
        }
    };

    private final BroadcastReceiver removeReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            notifyRemove(intent);
        }
    };

    private final Context context;
    private final String prefName;
    private final CacheProvider cacheProvider;
    private final ByteEncryption byteEncryption;

    public BroadcastPreferenceEventBridgeImpl(Context context,
                                              String prefName,
                                              CacheProvider cacheProvider,
                                              ByteEncryption byteEncryption) {
        this.context = context;
        this.prefName = prefName;
        this.cacheProvider = cacheProvider;
        this.byteEncryption = byteEncryption;
    }

    private void notifyUpdate(Intent intent) {
        if (!prefName.equals(intent.getStringExtra(PREFERENCE_NAME))) {
            return;
        }
        String key = intent.getStringExtra(PREFERENCE_KEY);
        byte[] bytes = intent.getByteArrayExtra(PREFERENCE_VALUE);
        byte[] decrypt = byteEncryption.decrypt(bytes);
        cacheProvider.put(key, decrypt);
        notifyListeners(key);
    }

    private void notifyRemove(Intent intent) {
{'fraction_non_alphanumeric': 0.0680079813767875, 'fraction_numerical': 0.0, 'mean_word_length': 3.361856417693981, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3441254', 'n_tokens_mistral': 1495, 'n_tokens_neox': 1479, 'n_words': 371}