Search in sources :

Example 1 with LongPredicate

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

Example 2 with LongPredicate

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

Example 3 with LongPredicate

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

Example 4 with LongPredicate

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

Example 5 with LongPredicate

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

Aggregations

LongPredicate (java8.util.function.LongPredicate)6 Test (org.testng.annotations.Test)4 LongConsumer (java8.util.function.LongConsumer)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 LongUnaryOperator (java8.util.function.LongUnaryOperator)1