All Downloads are FREE. Search and download functionalities are using the official Maven repository.

be.bagofwords.util.OccasionalAction Maven / Gradle / Ivy

package be.bagofwords.util;

public abstract class OccasionalAction {

    private final long interval;
    private long previous;
    private long start;

    public OccasionalAction(long interval) {
        this.interval = interval;
        previous = System.currentTimeMillis();
        start = -1;
    }

    public void doOccasionalAction(T curr) {
        long timeNow = System.currentTimeMillis();
        if (start == -1) {
            start = timeNow;
        }
        if (timeNow - previous > interval) {
            previous = timeNow;
            doAction(curr);
        }
    }

    public long getStart() {
        return start;
    }

    protected abstract void doAction(T curr);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy