use of java8.util.function.LongConsumer in project streamsupport by stefan-zobel.
the class LongPrimitiveOpsTests method testTee.
@Test(groups = { "serialization-hostile" })
public void testTee() {
final long[] teeSum = new long[1];
long sum;
sum = LongStreams.range(1, 10).filter(new LongPredicate() {
@Override
public boolean test(long i) {
return i % 2 == 0;
}
}).peek(new LongConsumer() {
@Override
public void accept(long i) {
teeSum[0] = teeSum[0] + i;
}
}).sum();
assertEquals(teeSum[0], sum);
}
use of java8.util.function.LongConsumer in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testUnsizedLongsCountSeq.
/**
* A sequential unsized stream of longs generates at least 100 values
*/
public void testUnsizedLongsCountSeq() {
final LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 100;
r.longs().limit(size).forEach(new LongConsumer() {
@Override
public void accept(long x) {
counter.increment();
}
});
assertEquals(counter.sum(), size);
}
use of java8.util.function.LongConsumer in project streamsupport by stefan-zobel.
the class LongPrimitiveOpsTests method testParForEach.
@Test(groups = { "serialization-hostile" })
public void testParForEach() {
final AtomicLong ai = new AtomicLong(0);
LongStreams.range(1, 10).parallel().filter(new LongPredicate() {
@Override
public boolean test(long i) {
return i % 2 == 0;
}
}).forEach((LongConsumer) new LongConsumer() {
@Override
public void accept(long l) {
ai.addAndGet(l);
}
});
assertEquals(ai.get(), 20);
}
use of java8.util.function.LongConsumer in project streamsupport by stefan-zobel.
the class LongPrimitiveOpsTests method testForEach.
@Test(groups = { "serialization-hostile" })
public void testForEach() {
final long[] sum = new long[1];
LongStreams.range(1, 10).filter(new LongPredicate() {
@Override
public boolean test(long i) {
return i % 2 == 0;
}
}).forEach(new LongConsumer() {
@Override
public void accept(long i) {
sum[0] = sum[0] + i;
}
});
assertEquals(sum[0], 20);
}
Aggregations