<commit_before>package org.matrix.console;


import android.util.Log;

import java.util.HashSet;
import java.util.Set;

public class EventEmitter<T> {
    private static final String LOG_TAG = "EventEmitter";

    private Set<Listener<T>> mCallbacks;

    public EventEmitter() {
        mCallbacks = new HashSet<>();
    }

    public void register(Listener<T> cb) {
        mCallbacks.add(cb);
    }

    public void unregister(Listener<T> cb) {
        mCallbacks.remove(cb);
    }

    public void fire(T t) {
        Set<Listener<T>> callbacks = new HashSet<>(mCallbacks);
        for (Listener<T> cb : callbacks) {
            try {
                cb.onEventFired(this, t);
            } catch(Exception e) {
                Log.e(LOG_TAG, "Callback threw: " + e.getMessage(), e);
            }
        }
    }

    public interface Listener<T> {
        void onEventFired(EventEmitter<T> emitter, T t);
    }
}<commit_msg>Fire events on UI thread<commit_after>package org.matrix.console;


import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import java.util.HashSet;
import java.util.Set;

public class EventEmitter<T> {
    private static final String LOG_TAG = "EventEmitter";

    private Set<Listener<T>> mCallbacks;

    public EventEmitter() {
        mCallbacks = new HashSet<>();
    }

    public void register(Listener<T> cb) {
        mCallbacks.add(cb);
    }

    public void unregister(Listener<T> cb) {
        mCallbacks.remove(cb);
    }

    /**
     * Fires all registered callbacks on the UI thread.
     * @param t
     */
    public void fire(final T t) {
        final Set<Listener<T>> callbacks = new HashSet<>(mCallbacks);

        Looper looper = Looper.getMainLooper();
        Handler uiHandler = new Handler(looper);
        uiHandler.post(new Runnable() {
               @Override
               public void run() {
                   for (Listener<T> cb : callbacks) {
                       try {
                           cb.onEventFired(EventEmitter.this, t);
                       } catch (Exception e) {
                           Log.e(LOG_TAG, "Callback threw: " + e.getMessage(), e);
                       }
                   }
               }
           }
        );
    }

    public interface Listener<T> {
        void onEventFired(EventEmitter<T> emitter, T t);
    }
}
{'fraction_non_alphanumeric': 0.11214953271028037, 'fraction_numerical': 0.0, 'mean_word_length': 1.9182156133828996, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '3630190', 'n_tokens_mistral': 711, 'n_tokens_neox': 695, 'n_words': 164}