Search in sources :

Example 1 with LongPredicate

use of com.annimon.stream.function.LongPredicate in project Lightweight-Stream-API by aNNiMON.

the class IterateTest method testStreamIterateWithPredicate.

@Test
public void testStreamIterateWithPredicate() {
    LongPredicate condition = new LongPredicate() {

        @Override
        public boolean test(long value) {
            return value < 20;
        }
    };
    LongUnaryOperator increment = new LongUnaryOperator() {

        @Override
        public long applyAsLong(long t) {
            return t + 5;
        }
    };
    LongStream.iterate(0, condition, increment).custom(assertElements(arrayContaining(0L, 5L, 10L, 15L)));
}
Also used : LongUnaryOperator(com.annimon.stream.function.LongUnaryOperator) LongPredicate(com.annimon.stream.function.LongPredicate) Test(org.junit.Test)

Example 2 with LongPredicate

use of com.annimon.stream.function.LongPredicate in project Lightweight-Stream-API by aNNiMON.

the class FilterTest method testFilter.

@Test
public void testFilter() {
    final LongPredicate predicate = Functions.remainderLong(111);
    LongStream.of(322, 555, 666, 1984, 1998).filter(predicate).custom(assertElements(arrayContaining(555L, 666L, 1998L)));
    LongStream.of(12, -10).filter(predicate).custom(assertIsEmpty());
}
Also used : LongPredicate(com.annimon.stream.function.LongPredicate) Test(org.junit.Test)

Example 3 with LongPredicate

use of com.annimon.stream.function.LongPredicate in project Lightweight-Stream-API by aNNiMON.

the class FilterNotTest method testFilterNot.

@Test
public void testFilterNot() {
    final LongPredicate predicate = Functions.remainderLong(111);
    LongStream.of(322, 555, 666, 1984, 1998).filterNot(predicate).custom(assertElements(arrayContaining(322L, 1984L)));
    LongStream.of(777, 999).filterNot(predicate).custom(assertIsEmpty());
}
Also used : LongPredicate(com.annimon.stream.function.LongPredicate) Test(org.junit.Test)

Example 4 with LongPredicate

use of com.annimon.stream.function.LongPredicate in project Lightweight-Stream-API by aNNiMON.

the class OnCloseTest method testOnCloseWithOtherOperators.

@Test
public void testOnCloseWithOtherOperators() {
    final boolean[] state = new boolean[] { false };
    LongStream stream = LongStream.of(0, 1, 2, 2, 3, 4, 4, 5).filter(new LongPredicate() {

        @Override
        public boolean test(long value) {
            return value < 4;
        }
    }).onClose(new Runnable() {

        @Override
        public void run() {
            state[0] = true;
        }
    }).distinct().limit(2);
    stream.findFirst();
    stream.close();
    assertTrue(state[0]);
}
Also used : LongStream(com.annimon.stream.LongStream) LongPredicate(com.annimon.stream.function.LongPredicate) Test(org.junit.Test)

Aggregations

LongPredicate (com.annimon.stream.function.LongPredicate)4 Test (org.junit.Test)4 LongStream (com.annimon.stream.LongStream)1 LongUnaryOperator (com.annimon.stream.function.LongUnaryOperator)1