@Test public void stream() { final long seed = 0xdeadbeef; final int capacity = 10; final Random random = new Random(seed); final Buffer buffer = new Buffer(capacity); for (int i = 0; i < buffer.capacity(); ++i) { final double value = random.nextDouble(); buffer.accept(value); } random.setSeed(seed); buffer.stream().forEach(d -> Assert.assertEquals(d, random.nextDouble())); random.setSeed(seed); for (int i = 0; i < 5; ++i) random.nextDouble(); buffer.stream(5).forEach(d -> Assert.assertEquals(d, random.nextDouble())); }
/** * Return the double moment statistics of the last {@code windowSize} * buffer values. * * @param windowSize the number of the last double values the statistics * consists of * @return the double moment statistics of the last {@code windowSize} * buffer values */ public DoubleMoments doubleMoments(final int windowSize) { return DoubleMoments.of( stream(windowSize).collect( DoubleMomentStatistics::new, DoubleMomentStatistics::accept, DoubleMomentStatistics::combine ) ); }
/** * Return the double stream of the buffer values. * * @return the double stream of the buffer values */ public DoubleStream stream() { return stream(_length); }