Search in sources :

Example 1 with LongUnaryOperator

use of com.annimon.stream.function.LongUnaryOperator 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 LongUnaryOperator

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

the class MapTest method testMap.

@Test
public void testMap() {
    LongUnaryOperator negator = new LongUnaryOperator() {

        @Override
        public long applyAsLong(long operand) {
            return -operand;
        }
    };
    LongStream.of(10L, 20L, 30L).map(negator).custom(assertElements(arrayContaining(-10L, -20L, -30L)));
    LongStream.empty().map(negator).custom(assertIsEmpty());
}
Also used : LongUnaryOperator(com.annimon.stream.function.LongUnaryOperator) Test(org.junit.Test)

Example 3 with LongUnaryOperator

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

the class OptionalLongTest method testMap.

@Test
public void testMap() {
    final LongUnaryOperator negatorFunction = new LongUnaryOperator() {

        @Override
        public long applyAsLong(long operand) {
            return -operand;
        }
    };
    OptionalLong result;
    result = OptionalLong.empty().map(negatorFunction);
    assertThat(result, isEmpty());
    result = OptionalLong.of(10).map(negatorFunction);
    assertThat(result, hasValue(-10));
}
Also used : LongUnaryOperator(com.annimon.stream.function.LongUnaryOperator) Test(org.junit.Test)

Example 4 with LongUnaryOperator

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

the class IterateTest method testStreamIterate.

@Test
public void testStreamIterate() {
    LongUnaryOperator operator = new LongUnaryOperator() {

        @Override
        public long applyAsLong(long operand) {
            return operand + 1000000;
        }
    };
    LongStream.iterate(0L, operator).limit(4).custom(assertElements(arrayContaining(0L, 1000000L, 2000000L, 3000000L)));
}
Also used : LongUnaryOperator(com.annimon.stream.function.LongUnaryOperator) Test(org.junit.Test)

Aggregations

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