<commit_before>package etomica.util;
import java.io.Serializable;

import etomica.action.activity.ControllerEvent;
import etomica.action.activity.ControllerListener;
import etomica.integrator.mcmove.MCMoveEvent;
import etomica.integrator.mcmove.MCMoveListener;
import etomica.lattice.LatticeEvent;
import etomica.lattice.LatticeListener;
import etomica.phase.PhaseEvent;
import etomica.phase.PhaseListener;
import etomica.simulation.SimulationEvent;
import etomica.simulation.SimulationListener;

/**
 * Class to take care of listener lists and event firing for simulation elements.
 * A class can make an instance of this manager as a field, and delegate any 
 * listener management functions to it.  
 *
 * @see SimulationEvent
 * @see SimulationListener
 */
public abstract class EventManager implements java.io.Serializable {
    
    /**
     * Adds a listener.  Synchronized to avoid conflict with removeListener.
     */
    public synchronized void addListener(Object listener) {
        if (listener.getClass() == getListenerClass()) {
            throw new IllegalArgumentException("must add listeners of class "+getListenerClass());
        }
        //add listener to beginning of list 
        //placement at end causes problem if a listener removes and then adds itself to the list as part of its response to the event
        first = new EventManager.Linker(listener, first, null);
        if(first.next != null) first.next.previous = first;
        listenerCount++;
    }

    /**
     * Removes a listener.  Synchronized to avoid conflict with addListener.
     */
    public synchronized void removeListener(Object listener) {
        for(EventManager.Linker link=first; link!=null; link=link.next) {
            if(link.listener == listener) {
            	listenerCount--;
                if(link == first) {first = link.next;}
                if(link.previous != null) link.previous.next = link.next;
                if(link.next != null) link.next.previous = link.previous;<commit_msg>not sure how/why checking equality worked... this seems better<commit_after>package etomica.util;
import java.io.Serializable;

import etomica.action.activity.ControllerEvent;
import etomica.action.activity.ControllerListener;
import etomica.integrator.mcmove.MCMoveEvent;
import etomica.integrator.mcmove.MCMoveListener;
import etomica.lattice.LatticeEvent;
import etomica.lattice.LatticeListener;
import etomica.phase.PhaseEvent;
import etomica.phase.PhaseListener;
import etomica.simulation.SimulationEvent;
import etomica.simulation.SimulationListener;

/**
 * Class to take care of listener lists and event firing for simulation elements.
 * A class can make an instance of this manager as a field, and delegate any 
 * listener management functions to it.  
 *
 * @see SimulationEvent
 * @see SimulationListener
 */
public abstract class EventManager implements java.io.Serializable {
    
    /**
     * Adds a listener.  Synchronized to avoid conflict with removeListener.
     */
    public synchronized void addListener(Object listener) {
        if (listener.getClass().isInstance(getListenerClass())) {
            throw new IllegalArgumentException("must add listeners of class "+getListenerClass());
        }
        //add listener to beginning of list 
        //placement at end causes problem if a listener removes and then adds itself to the list as part of its response to the event
        first = new EventManager.Linker(listener, first, null);
        if(first.next != null) first.next.previous = first;
        listenerCount++;
    }

    /**
     * Removes a listener.  Synchronized to avoid conflict with addListener.
     */
    public synchronized void removeListener(Object listener) {
        for(EventManager.Linker link=first; link!=null; link=link.next) {
            if(link.listener == listener) {
            	listenerCount--;
                if(link == first) {first = link.next;}
                if(link.previous != null) link.previous.next = link.next;
                if(link.next != null) link.next.previous = link.previous;
{'fraction_non_alphanumeric': 0.08718074656188605, 'fraction_numerical': 0.0, 'mean_word_length': 3.269392033542977, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4015087', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1062, 'n_words': 336}