use of java8.util.function.LongPredicate 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.LongPredicate in project streamsupport by stefan-zobel.
the class LongPrimitiveOpsTests method testSum.
public void testSum() {
long sum;
sum = LongStreams.range(1, 10).filter(new LongPredicate() {
@Override
public boolean test(long i) {
return i % 2 == 0;
}
}).sum();
assertEquals(sum, 20);
}
use of java8.util.function.LongPredicate in project streamsupport by stefan-zobel.
the class MatchOpTest method testLongStream.
@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class)
public void testLongStream(String name, TestData.OfLong data) {
for (LongPredicate p : LONG_PREDICATES) {
setContext("p", p);
for (Kind kind : Kind.values()) {
setContext("kind", kind);
exerciseTerminalOps(data, longKinds.get(kind).apply(p));
exerciseTerminalOps(data, s -> s.filter(lpFalse), longKinds.get(kind).apply(p));
exerciseTerminalOps(data, s -> s.filter(lpEven), longKinds.get(kind).apply(p));
}
}
}
use of java8.util.function.LongPredicate in project streamsupport by stefan-zobel.
the class LongPrimitiveOpsTests method testMap.
public void testMap() {
long sum = LongStreams.range(1, 10).filter(new LongPredicate() {
@Override
public boolean test(long i) {
return i % 2 == 0;
}
}).map(new LongUnaryOperator() {
@Override
public long applyAsLong(long i) {
return i * 2;
}
}).sum();
assertEquals(sum, 40);
}
use of java8.util.function.LongPredicate 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);
}
Aggregations