ReservoirSamplerWithBinaryHeap { public List<T> sample() { Iterator<ImmutablePair<Double, T>> it = buffer.iterator(); List<T> samples = new ArrayList<T>(); while (it.hasNext()) { ImmutablePair<Double, T> pair = it.next(); samples.add(pair.getRight()); } return samples; } ReservoirSamplerWithBinaryHeap(int nbSamples, long seed);  ReservoirSamplerWithBinaryHeap(int nbSamples); void onCompleted(boolean b); void onNext(T v); List<T> sample(); Iterable<ImmutablePair<Double, T>> samplePairs(); void clear();  }
@Test public void testSample() { sampler = new ReservoirSamplerWithBinaryHeap<TestRowStruct>(SAMPLE_SIZE, TestConstants.RANDOM_SEED); sampler.clear(); for (TestRowStruct row : testers) { sampler.onNext(row); } sampler.onCompleted(true); List<TestRowStruct> sampleList = sampler.sample(); for (int i = 0; i < sampleList.size(); i++) { assertEquals(EXPECTED_SAMPLES[i], sampleList.get(i).getId()); } }