<commit_before>package addons.protocolchangers;

import simulation.Engine;
import simulation.State;
import simulation.TimeListener;


/**
 * Periodical protocol changer. It calls the onTimeToChange() method periodically according to the defined
 * change period.
 */
public abstract class PeriodicProtocolChanger extends ProtocolChanger implements TimeListener {

    private long changePeriod;
    private long timeToChange;

    /**
     * Creates a protocol changer by assigning it an engine and a state.
     *
     * @param engine engine to assign to.
     * @param state  state to assign to.
     */
    public PeriodicProtocolChanger(Engine engine, State state, long changePeriod) {
        super(engine, state);
        this.changePeriod = changePeriod;
        this.timeToChange = changePeriod;
    }

    @Override
    public void onTimeChange(long newTime) {
        if (newTime >= timeToChange) {
            onTimeToChange();
            timeToChange += changePeriod;
        }
    }

    /**
     * Called periodically according to the defined change period.
     */
    public abstract void onTimeToChange();
}<commit_msg>fixed error: periodic protocol changer was not registering with the engines time property<commit_after>package addons.protocolchangers;

import simulation.Engine;
import simulation.State;
import simulation.TimeListener;


/**
 * Periodical protocol changer. It calls the onTimeToChange() method periodically according to the defined
 * change period.
 */
public abstract class PeriodicProtocolChanger extends ProtocolChanger implements TimeListener {

    private long changePeriod;
    private long timeToChange;

    /**
     * Creates a protocol changer by assigning it an engine and a state.
     *
     * @param engine engine to assign to.
     * @param state  state to assign to.
     */
    public PeriodicProtocolChanger(Engine engine, State state, long changePeriod) {
        super(engine, state);
        this.changePeriod = changePeriod;
        this.timeToChange = changePeriod;
    }

    /**
     * Assigns the protocol changer to an engine and state and registers the protocol changer to the time
     * property of the engine.
     *
     * @param engine engine to assign to.
     * @param state  state to assign to.
     */
    @Override
    public void assignTo(Engine engine, State state) {
        super.assignTo(engine, state);
        engine.timeProperty().addListener(this);
    }

    @Override
    public void onTimeChange(long newTime) {
        if (newTime >= timeToChange) {
            onTimeToChange();
            timeToChange += changePeriod;
        }
    }

    /**
     * Called periodically according to the defined change period.
     */
    public abstract void onTimeToChange();
}
{'fraction_non_alphanumeric': 0.07254261878853827, 'fraction_numerical': 0.0, 'mean_word_length': 2.8573426573426572, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3136218', 'n_tokens_mistral': 707, 'n_tokens_neox': 685, 'n_words': 249}