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