Search in sources :

Example 6 with LongPredicate

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