in application/org.openjdk.jmc.greychart/src/main/java/org/openjdk/jmc/greychart/providers/SubsamplingProvider.java [195:254]
private AbstractSampler createSampleBuffer(int width) {
Iterator<IXYData> it = m_dataSeries.createIterator(m_requestedStartX, m_requestedEndX);
if (!it.hasNext()) {
return isIntegrate() ? new IntegratingSubsamplingBuffer(0) : new SubsamplingBuffer(0);
}
AbstractSampler sampleBuffer = isIntegrate() ? new IntegratingSubsamplingBuffer(width)
: new SubsamplingBuffer(width);
long worldWidth = m_xAxis.getMax().longValue() - m_xAxis.getMin().longValue();
long leftEdge = m_xAxis.getMin().longValue();
long rightEdge = leftEdge + worldWidth;
IXYData leftMost = null;
IXYData rightMost = null;
IXYData rightMostWithin = null;
IXYData leftMostWithin = null;
while (it.hasNext() && m_cancelService.isNotCancelled()) {
IXYData newData = it.next();
long x = getXAsLong(newData);
if (x < leftEdge && (leftMost == null || x >= getXAsLong(leftMost))) {
leftMost = newData;
} else if (x > rightEdge && (rightMost == null || x < getXAsLong(rightMost))) {
rightMost = newData;
}
if (x >= leftEdge && x <= rightEdge) {
addXYDataPoint(sampleBuffer, worldWidth, leftEdge, newData);
if (leftMostWithin == null) {
leftMostWithin = newData;
rightMostWithin = newData;
} else {
if (getXAsLong(leftMostWithin) > x) {
leftMostWithin = newData;
} else if (getXAsLong(rightMostWithin) <= x) {
rightMostWithin = newData;
}
}
}
}
if (isIntegrate()) {
((IntegratingSubsamplingBuffer) sampleBuffer).fixSamples();
} else {
// If we had a sample left of the left edge, or right of the right edge, we must add an interpolated
// sample at the edge (unless the actual internal values were already on the borders).
leftMostWithin = leftMostWithin == null ? rightMost : leftMostWithin;
rightMostWithin = rightMostWithin == null ? leftMost : rightMostWithin;
if (leftMost != null && leftMostWithin != null && getXAsLong(leftMostWithin) != leftEdge
&& getXAsLong(leftMost) < leftEdge) {
addInterpolatedNormalizedPoint((SubsamplingBuffer) sampleBuffer, 0.0, leftMost, leftMostWithin,
worldWidth, leftEdge);
}
if (rightMost != null && rightMostWithin != null && getXAsLong(rightMostWithin) != rightEdge
&& getXAsLong(rightMost) > rightEdge) {
addInterpolatedNormalizedPoint((SubsamplingBuffer) sampleBuffer, 1.0, rightMostWithin, rightMost,
worldWidth, leftEdge);
}
}
return sampleBuffer;
}