List of usage examples for java.util TreeSet pollFirst
public E pollFirst()
From source file:ro.hasna.ts.math.representation.AdaptivePiecewiseConstantApproximation.java
@Override public MeanLastPair[] transform(double[] values) { int length = values.length; if (length < 2 * segments) { throw new ArrayLengthIsTooSmallException(length, 2 * segments, true); }//w w w . j a v a 2s .c om int numberOfSegments = length / 2; // create segments with two values Segment first = createSegments(values, length); if (numberOfSegments > segments) { // compute error by unifying current segment with the next segment TreeSet<Segment> set = createSegmentsSet(values, first); // unify concurrent segments with minimum error while (numberOfSegments > segments) { Segment minSegment = set.pollFirst(); minSegment.mean = getUnifiedMean(minSegment, minSegment.next); minSegment.error = getUnifiedError(minSegment, minSegment.next, values, minSegment.mean); minSegment.end = minSegment.next.end; deleteSubsequentSegment(minSegment, set); if (minSegment.next != null) { double mean = getUnifiedMean(minSegment, minSegment.next); minSegment.errorWithNext = getUnifiedError(minSegment, minSegment.next, values, mean); set.add(minSegment); } if (minSegment.prev != null) { set.remove(minSegment.prev); double mean = getUnifiedMean(minSegment.prev, minSegment); minSegment.prev.errorWithNext = getUnifiedError(minSegment.prev, minSegment, values, mean); set.add(minSegment.prev); } numberOfSegments--; } } return getMeanLastPairs(first, numberOfSegments); }