use of com.annimon.stream.function.IntPredicate in project Lightweight-Stream-API by aNNiMON.
the class AnyMatchTest method testAnyMatch.
@Test
public void testAnyMatch() {
IntStream.empty().anyMatch(new IntPredicate() {
@Override
public boolean test(int value) {
throw new IllegalStateException();
}
});
assertTrue(IntStream.of(42).anyMatch(new IntPredicate() {
@Override
public boolean test(int value) {
return value == 42;
}
}));
assertTrue(IntStream.of(5, 7, 9, 10, 7, 5).anyMatch(Functions.remainderInt(2)));
assertFalse(IntStream.of(5, 7, 9, 11, 7, 5).anyMatch(Functions.remainderInt(2)));
}
use of com.annimon.stream.function.IntPredicate in project Lightweight-Stream-API by aNNiMON.
the class FilterTest method testFilter.
@Test
public void testFilter() {
IntStream.rangeClosed(1, 10).filter(Functions.remainderInt(2)).custom(assertElements(arrayContaining(2, 4, 6, 8, 10)));
assertTrue(IntStream.iterate(0, new IntUnaryOperator() {
@Override
public int applyAsInt(int operand) {
return operand + 1;
}
}).filter(new IntPredicate() {
@Override
public boolean test(int value) {
return value == 0;
}
}).findFirst().getAsInt() == 0);
}
use of com.annimon.stream.function.IntPredicate in project Lightweight-Stream-API by aNNiMON.
the class FilterTest method testFilterWithMap.
@Test
public void testFilterWithMap() {
final List<Integer> items = Arrays.asList(0, 1, 2, 3, 4);
IntStream.range(0, items.size()).filter(new IntPredicate() {
@Override
public boolean test(int value) {
return items.get(value) % 2 == 0;
}
}).mapToObj(new IntFunction<String>() {
@Override
public String apply(int value) {
return Integer.toString(value);
}
}).custom(StreamMatcher.assertElements(contains("0", "2", "4")));
}
use of com.annimon.stream.function.IntPredicate in project Lightweight-Stream-API by aNNiMON.
the class NoneMatchTest method testNoneMatch.
@Test
public void testNoneMatch() {
IntStream.empty().noneMatch(new IntPredicate() {
@Override
public boolean test(int value) {
throw new IllegalStateException();
}
});
assertFalse(IntStream.of(42).noneMatch(new IntPredicate() {
@Override
public boolean test(int value) {
return value == 42;
}
}));
assertFalse(IntStream.of(5, 7, 9, 10, 7, 5).noneMatch(Functions.remainderInt(2)));
assertTrue(IntStream.of(5, 7, 9, 11, 7, 5).noneMatch(Functions.remainderInt(2)));
}
use of com.annimon.stream.function.IntPredicate in project Lightweight-Stream-API by aNNiMON.
the class OnCloseTest method testOnCloseWithOtherOperators.
@Test
public void testOnCloseWithOtherOperators() {
final boolean[] state = new boolean[] { false };
IntStream stream = IntStream.of(0, 1, 2, 2, 3, 4, 4, 5).filter(new IntPredicate() {
@Override
public boolean test(int 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