package cz.cuni.mff.d3s.spl.core.data.segment;

import cz.cuni.mff.d3s.spl.core.data.PrecomputedStatistics;
import cz.cuni.mff.d3s.spl.core.data.SampleBasedDataSource;
import cz.cuni.mff.d3s.spl.core.data.Statistics;

public class SlidingSlotDataSource implements SampleBasedDataSource {

	private long clockStart = Long.MIN_VALUE;
	private long clockEnd = Long.MAX_VALUE;
	private long sampleCount = 0;
	private double sampleSum = 0.0;
	
	
	public SlidingSlotDataSource(long start, long end) {
		clockStart = start;
		clockEnd = end;
	}

	@Override
	public Statistics get() {
		if (sampleCount == 0) {
			return PrecomputedStatistics.create(Double.NaN, 0);
		}
		return PrecomputedStatistics.create(sampleSum / (double) sampleCount, sampleCount);
	}

	@Override
	public void newSample(long sample, long clock) {
		if ((clock < clockStart) || (clock >= clockEnd)) {
			return;
		}
		
		sampleCount++;
		sampleSum += (double) sample;
	}

	@Override
	public void addSubSource(SampleBasedDataSource subSource) {
		throw new UnsupportedOperationException("Not implemented yet.");
	}

}

@@ -488,16 +488,121 @@
  end) %7B%0A
+%09%09if (start %3E end) %7B%0A%09%09%09throw new IllegalArgumentException(%22It is forbidden to have %60from %3E end'.%22);%0A%09%09%7D%0A
 %09%09clockS

Check input arguments to SlidingSlotDataSource