package com.jifalops.wsnlocalize.data;

/**
 * {@link SampleWindow} has minimum and maximum counts and times.
 * {@link #reached} can be used to check if both minimums ({@link #minCount}, {@link #minTime}),
 * or either maximum ({@link #maxCount}, {@link #maxTime}) have been reached.
 */
public class SampleWindow {
    public final int minCount, maxCount;
    public final long minTime, maxTime;

    public SampleWindow(int minCount, long minTimeMillis, int maxCount, long maxTimeMillis) {
        this.minCount = minCount;
        this.minTime = minTimeMillis;
        this.maxCount = maxCount;
        this.maxTime = maxTimeMillis;
    }

    /**
     * @return true if both minimums have been met, or either maximum has been met.
     */
    public boolean reached(int count, long time) {
        return (count >= minCount && time >= minTime)
                || count >= maxCount
                || time >= maxTime;
    }

    @Override
    public String toString() {
        return minCount +","+ minTime +","+ maxCount +","+ maxTime;
    }

    @Override
    public boolean equals(Object o) {
        if (o instanceof SampleWindow) {
            SampleWindow window = (SampleWindow) o;
            return minCount == window.minCount && minTime == window.minTime &&
                    maxCount == window.maxCount && maxTime == window.maxTime;
        } else return false;
    }

    @Override
    public int hashCode() {
        return toString().hashCode();
    }
}

@@ -33,16 +33,77 @@
 .data;%0A%0A
+import com.jifalops.wsnlocalize.toolbox.util.ResettingList;%0A%0A
 /**%0A * %7B
@@ -373,91 +373,39 @@
 dow 
-%7B%0A    public final int minCount, maxCount;%0A    public final long minTime, maxTime;%0A
+extends ResettingList.Trigger %7B
 %0A   
@@ -507,971 +507,62 @@
     
-this.minCount = minCount;%0A        this.minTime = minTimeMillis;%0A        this.maxCount = maxCount;%0A        this.maxTime = maxTimeMillis;%0A    %7D%0A%0A    /**%0A     * @return true if both minimums have been met, or either maximum has been met.%0A     */%0A    public boolean reached(int count, long time) %7B%0A        return (count %3E= minCount && time %3E= minTime)%0A                %7C%7C count %3E= maxCount%0A                %7C%7C time %3E= maxTime;%0A    %7D%0A%0A    @Override%0A    public String toString() %7B%0A        return minCount +%22,%22+ minTime +%22,%22+ maxCount +%22,%22+ maxTime;%0A    %7D%0A%0A    @Override%0A    public boolean equals(Object o) %7B%0A        if (o instanceof SampleWindow) %7B%0A            SampleWindow window = (SampleWindow) o;%0A            return minCount == window.minCount && minTime == window.minTime &&%0A                    maxCount == window.maxCount && maxTime == window.maxTime;%0A        %7D else return false;%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A        return toString().hashCode(
+super(minCount, minTimeMillis, maxCount, maxTimeMillis
 );%0A 

extend ResettingList.Trigger