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)));
}
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());
}
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());
}
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]);
}
Aggregations