Search in sources :

Example 6 with IntPredicate

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

the class IterateTest method testStreamIterateWithPredicate.

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

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

        @Override
        public int applyAsInt(int t) {
            return t + 5;
        }
    };
    IntStream.iterate(0, condition, increment).custom(assertElements(arrayContaining(0, 5, 10, 15)));
}
Also used : IntPredicate(com.annimon.stream.function.IntPredicate) IntUnaryOperator(com.annimon.stream.function.IntUnaryOperator) Test(org.junit.Test)

Example 7 with IntPredicate

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

the class AllMatchTest method testAllMatch.

@Test
public void testAllMatch() {
    IntStream.empty().allMatch(new IntPredicate() {

        @Override
        public boolean test(int value) {
            throw new IllegalStateException();
        }
    });
    assertTrue(IntStream.of(42).allMatch(new IntPredicate() {

        @Override
        public boolean test(int value) {
            return value == 42;
        }
    }));
    assertFalse(IntStream.of(5, 7, 9, 10, 7, 5).allMatch(IntPredicate.Util.negate(Functions.remainderInt(2))));
    assertTrue(IntStream.of(5, 7, 9, 11, 7, 5).allMatch(IntPredicate.Util.negate(Functions.remainderInt(2))));
}
Also used : IntPredicate(com.annimon.stream.function.IntPredicate) Test(org.junit.Test)

Aggregations

IntPredicate (com.annimon.stream.function.IntPredicate)7 Test (org.junit.Test)7 IntUnaryOperator (com.annimon.stream.function.IntUnaryOperator)2 IntStream (com.annimon.stream.IntStream)1 IntFunction (com.annimon.stream.function.IntFunction)1