use of com.annimon.stream.LongStream in project Lightweight-Stream-API by aNNiMON.
the class OnCloseTest method testOnCloseFlatMap.
@Test
public void testOnCloseFlatMap() {
final int[] counter = new int[] { 0 };
final Runnable runnable = new Runnable() {
@Override
public void run() {
counter[0]++;
}
};
LongStream stream = LongStream.rangeClosed(2, 4).onClose(runnable).onClose(runnable).flatMap(new LongFunction<LongStream>() {
@Override
public LongStream apply(final long i) {
return LongStream.rangeClosed(2, 4).onClose(runnable);
}
});
stream.count();
assertThat(counter[0], is(3));
stream.close();
assertThat(counter[0], is(5));
}
use of com.annimon.stream.LongStream in project Lightweight-Stream-API by aNNiMON.
the class OfPrimitiveIteratorTest method testStreamOfPrimitiveIterator.
@Test
public void testStreamOfPrimitiveIterator() {
LongStream stream = LongStream.of(new PrimitiveIterator.OfLong() {
private int index = 0;
@Override
public boolean hasNext() {
return index < 3;
}
@Override
public long nextLong() {
return ++index;
}
});
assertThat(stream, elements(arrayContaining(1L, 2L, 3L)));
}
use of com.annimon.stream.LongStream in project Lightweight-Stream-API by aNNiMON.
the class ConcatTest method testStreamConcat.
@Test
public void testStreamConcat() {
LongStream a1 = LongStream.empty();
LongStream b1 = LongStream.empty();
LongStream.concat(a1, b1).custom(assertIsEmpty());
LongStream a2 = LongStream.of(100200300L, 1234567L);
LongStream b2 = LongStream.empty();
LongStream.concat(a2, b2).custom(assertElements(arrayContaining(100200300L, 1234567L)));
LongStream a3 = LongStream.of(100200300L, 1234567L);
LongStream b3 = LongStream.empty();
LongStream.concat(a3, b3).custom(assertElements(arrayContaining(100200300L, 1234567L)));
LongStream a4 = LongStream.of(-5L, 1234567L, -Integer.MAX_VALUE, Long.MAX_VALUE);
LongStream b4 = LongStream.of(Integer.MAX_VALUE, 100200300L);
LongStream.concat(a4, b4).custom(assertElements(arrayContaining(-5L, 1234567L, (long) -Integer.MAX_VALUE, Long.MAX_VALUE, (long) Integer.MAX_VALUE, 100200300L)));
}
use of com.annimon.stream.LongStream 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]);
}
use of com.annimon.stream.LongStream in project Lightweight-Stream-API by aNNiMON.
the class OnCloseTest method testOnClose.
@Test
public void testOnClose() {
final boolean[] state = new boolean[] { false };
LongStream stream = LongStream.of(0, 1, 2).onClose(new Runnable() {
@Override
public void run() {
state[0] = true;
}
});
stream.findFirst();
stream.close();
assertTrue(state[0]);
}
Aggregations