/** * @return A stream of samples starting after dropping. Down-sampling is handled outside of the stream (i.e. the * stream will be the final result after dropping and down-sampling) */ public Stream<NetworkSample> stream() { StatusBar statusBar = statusBarSupplier.get(); dropSamples(dropCount, statusBar); final AtomicInteger sampleNumber = new AtomicInteger(0); return Stream.generate(() -> { sampleNumber.getAndIncrement(); for (int i = 0; i < downSampleInterval - 1; i++) { algorithm.step(); } NetworkSample sample = algorithm.sample(); statusBar.setMessage(String.format("Sample #%,d completed", sampleNumber.get())); return sample; }).onClose(statusBar::finish); }
private void dropSamples(int dropCount, StatusBar statusBar) { if (dropCount == 0) { return; } statusBar.setMessage("Dropping samples..."); PercentageComponent statusPercent = newPercentageComponentAndAddToStatusBar(statusBar); for (int i = 0; i < dropCount; i++) { algorithm.step(); statusPercent.progress((i + 1) / (double) dropCount); } statusBar.removeComponent(statusPercent); }
sampleCount++; } else { algorithm.step();