SampleBuffer implements Sampling<T> { @SuppressWarnings({"unchecked", "rawtypes"}) public int publish() { final Object[] values = _buffer.snapshot(); SampleList<T> snapshot = null; if (values != null && values.length > 0) { final List samples = Arrays.asList(values); snapshot = new SampleList(samples); } try { return snapshot != null ? snapshot.size() : 0; } finally { _snapshot = snapshot; } } SampleBuffer(final int size); void add(final Sample<T> sample); void addAll(final Collection<? extends Sample<T>> samples); @SuppressWarnings({"unchecked", "rawtypes"}) int publish(); @Override Result<T> eval(final Tree<? extends Op<T>, ?> program);  }
@Test public void publish() { final SampleBuffer<Double> buffer = new SampleBuffer<>(33); for (int i = 0; i < 10; ++i) { buffer.add(Sample.ofDouble(i, 2*i)); } buffer.publish(); Assert.assertEquals( buffer.samples().stream() .map(p -> p.argAt(0).intValue()) .collect(Collectors.toList()), List.of(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) ); }