use of java8.util.function.IntPredicate in project streamsupport by stefan-zobel.
the class IntPrimitiveOpsTests method testForEach.
@Test(groups = { "serialization-hostile" })
public void testForEach() {
final int[] sum = new int[1];
IntStreams.range(1, 10).filter(new IntPredicate() {
@Override
public boolean test(int i) {
return i % 2 == 0;
}
}).forEach(new IntConsumer() {
@Override
public void accept(int i) {
sum[0] = sum[0] + i;
}
});
assertEquals(sum[0], 20);
}
use of java8.util.function.IntPredicate in project streamsupport by stefan-zobel.
the class IntPrimitiveOpsTests method testParForEach.
@Test(groups = { "serialization-hostile" })
public void testParForEach() {
final AtomicInteger ai = new AtomicInteger(0);
IntStreams.range(1, 10).parallel().filter(new IntPredicate() {
@Override
public boolean test(int i) {
return i % 2 == 0;
}
}).forEach((IntConsumer) new IntConsumer() {
@Override
public void accept(int i) {
ai.addAndGet(i);
}
});
assertEquals(ai.get(), 20);
}
use of java8.util.function.IntPredicate in project streamsupport by stefan-zobel.
the class IntPrimitiveOpsTests method testTee.
@Test(groups = { "serialization-hostile" })
public void testTee() {
final int[] teeSum = new int[1];
long sum;
sum = IntStreams.range(1, 10).filter(new IntPredicate() {
@Override
public boolean test(int i) {
return i % 2 == 0;
}
}).peek(new IntConsumer() {
@Override
public void accept(int i) {
teeSum[0] = teeSum[0] + i;
}
}).sum();
assertEquals(teeSum[0], sum);
}
use of java8.util.function.IntPredicate in project streamsupport by stefan-zobel.
the class IntPrimitiveOpsTests method testMap.
public void testMap() {
long sum = IntStreams.range(1, 10).filter(new IntPredicate() {
@Override
public boolean test(int i) {
return i % 2 == 0;
}
}).map(new IntUnaryOperator() {
@Override
public int applyAsInt(int i) {
return i * 2;
}
}).sum();
assertEquals(sum, 40);
}
use of java8.util.function.IntPredicate in project streamsupport by stefan-zobel.
the class MatchOpTest method testIntStream.
@Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class)
public void testIntStream(String name, TestData.OfInt data) {
for (IntPredicate p : INT_PREDICATES) {
setContext("p", p);
for (Kind kind : Kind.values()) {
setContext("kind", kind);
exerciseTerminalOps(data, intKinds.get(kind).apply(p));
exerciseTerminalOps(data, s -> s.filter(ipFalse), intKinds.get(kind).apply(p));
exerciseTerminalOps(data, s -> s.filter(ipEven), intKinds.get(kind).apply(p));
}
}
}
Aggregations