<commit_before>package etomica.integrator;

import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;

import etomica.action.Action;
import etomica.exception.ConfigurationOverlapException;
import etomica.space.IVector;

/**
 * Integrator implements the algorithm used to move the atoms around and
 * generate new configurations in one or more boxs. All integrator techniques,
 * such as molecular dynamics or Monte Carlo, are implemented via subclasses of
 * this Integrator class. The Integrator's activities are managed via the
 * actions of the governing Controller.
 * 
 * @author <NAME> and <NAME>
 */
public abstract class Integrator implements java.io.Serializable, IIntegrator {

    protected boolean initialized = false;
    private final LinkedList intervalListeners = new LinkedList();
    private final LinkedList listeners = new LinkedList();
    private ListenerWrapper[] listenerWrapperArray = new ListenerWrapper[0];
    protected int interval;
    private int iieCount;
    protected int stepCount;

    public Integrator() {
        setEventInterval(1);
        stepCount = 0;
    }

    /**
     * @return value of interval (number of doStep calls) between
     * firing of interval events by integrator.
     */
    public int getEventInterval() {
        return interval;
    }
    
    /**
     * Sets value of interval between successive firing of integrator interval events.
     * @param interval
     */
    public void setEventInterval(int interval) {
        this.interval = interval;
        if (iieCount > interval) {
            iieCount = interval;
        }
    }
    
    public final void doStep() {
        stepCount++;
        doStepInternal();
        if(--iieCount == 0) {
            fireIntervalEvent();
            iieCount = interval;
        }
    }
    
    /**
     * Performs the elementary integration step, such as a molecular dynamics
     * time step, or a Monte Carlo trial.
     */
    protected abstract void doStepInternal();

    /**
     * Returns the number of steps performed by the integrator since it was
     * initialized.
     */
    public int getStepCount() {
        return stepCount;
    }
    
    /**
     * Defines the actions taken by the integrator to reset itself, such as
     * required if a perturbation is applied to the simulated box (e.g.,
     * addition or deletion of a molecule). Also invoked when the
     * integrator is started or initialized.
     */
    //This should be called by subclasses /after/ they have performed their own
    //reset
    public void reset() throws ConfigurationOverlapException {
        fireNonintervalEvent(new IntegratorNonintervalEvent(this, IntegratorNonintervalEvent.RESET));
    }

    /**
     * Initializes the integrator, performing the following steps: (1) deploys
     * agents in all atoms; (2) call reset method; (3) fires an event
     * indicating to registered listeners indicating that initialization has
     * been performed (i.e. fires IntervalEvent of type field set to
     * INITIALIZE).
     */
    public final void initialize() throws ConfigurationOverlapException {
        stepCount = 0;
        initialized = false;
        setup();
        initialized = true;
        reset();
        iieCount = interval;
    }
    
    /**
     * Returns true if initialize method has been called.
     */
    public boolean isInitialized() {<commit_msg>set iieCount before invoking reset.  If reset throws an exception, we still want iieCount to be valid<commit_after>package etomica.integrator;

import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;

import etomica.action.Action;
import etomica.exception.ConfigurationOverlapException;
import etomica.space.IVector;

/**
 * Integrator implements the algorithm used to move the atoms around and
 * generate new configurations in one or more boxs. All integrator techniques,
 * such as molecular dynamics or Monte Carlo, are implemented via subclasses of
 * this Integrator class. The Integrator's activities are managed via the
 * actions of the governing Controller.
 * 
 * @author <NAME> and <NAME>
 */
public abstract class Integrator implements java.io.Serializable, IIntegrator {

    protected boolean initialized = false;
    private final LinkedList intervalListeners = new LinkedList();
    private final LinkedList listeners = new LinkedList();
    private ListenerWrapper[] listenerWrapperArray = new ListenerWrapper[0];
    protected int interval;
    private int iieCount;
    protected int stepCount;

    public Integrator() {
        setEventInterval(1);
        stepCount = 0;
    }

    /**
     * @return value of interval (number of doStep calls) between
     * firing of interval events by integrator.
     */
    public int getEventInterval() {
        return interval;
    }
    
    /**
     * Sets value of interval between successive firing of integrator interval events.
     * @param interval
     */
    public void setEventInterval(int interval) {
        this.interval = interval;
        if (iieCount > interval) {
            iieCount = interval;
        }
    }
    
    public final void doStep() {
        stepCount++;
        doStepInternal();
        if(--iieCount == 0) {
            fireIntervalEvent();
            iieCount = interval;
        }
    }
    
    /**
     * Performs the elementary integration step, such as a molecular dynamics
     * time step, or a Monte Carlo trial.
     */
    protected abstract void doStepInternal();

    /**
     * Returns the number of steps performed by the integrator since it was
     * initialized.
     */
    public int getStepCount() {
        return stepCount;
    }
    
    /**
     * Defines the actions taken by the integrator to reset itself, such as
     * required if a perturbation is applied to the simulated box (e.g.,
     * addition or deletion of a molecule). Also invoked when the
     * integrator is started or initialized.
     */
    //This should be called by subclasses /after/ they have performed their own
    //reset
    public void reset() throws ConfigurationOverlapException {
        fireNonintervalEvent(new IntegratorNonintervalEvent(this, IntegratorNonintervalEvent.RESET));
    }

    /**
     * Initializes the integrator, performing the following steps: (1) deploys
     * agents in all atoms; (2) call reset method; (3) fires an event
     * indicating to registered listeners indicating that initialization has
     * been performed (i.e. fires IntervalEvent of type field set to
     * INITIALIZE).
     */
    public final void initialize() throws ConfigurationOverlapException {
        stepCount = 0;
        initialized = false;
        setup();
        iieCount = interval;
        initialized = true;
        reset();
    }
    
    /**
     * Returns true if initialize method has been called.
     */
    public boolean isInitialized() {
{'fraction_non_alphanumeric': 0.0734741105004339, 'fraction_numerical': 0.0023141452126120912, 'mean_word_length': 2.6645468998410173, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '5505968', 'n_tokens_mistral': 1741, 'n_tokens_neox': 1713, 'n_words': 674}