Search in sources :

Example 1 with IntPredicate

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);
}
Also used : IntPredicate(java8.util.function.IntPredicate) IntConsumer(java8.util.function.IntConsumer) Test(org.testng.annotations.Test)

Example 2 with IntPredicate

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IntPredicate(java8.util.function.IntPredicate) IntConsumer(java8.util.function.IntConsumer) Test(org.testng.annotations.Test)

Example 3 with IntPredicate

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);
}
Also used : IntPredicate(java8.util.function.IntPredicate) IntConsumer(java8.util.function.IntConsumer) Test(org.testng.annotations.Test)

Example 4 with IntPredicate

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);
}
Also used : IntPredicate(java8.util.function.IntPredicate) IntUnaryOperator(java8.util.function.IntUnaryOperator)

Example 5 with IntPredicate

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));
        }
    }
}
Also used : IntPredicate(java8.util.function.IntPredicate) Test(org.testng.annotations.Test)

Aggregations

IntPredicate (java8.util.function.IntPredicate)5 Test (org.testng.annotations.Test)4 IntConsumer (java8.util.function.IntConsumer)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IntUnaryOperator (java8.util.function.IntUnaryOperator)1