use of com.annimon.stream.LongStream in project Lightweight-Stream-API by aNNiMON.
the class ObjFlatMapToLong method nextIteration.
@Override
protected void nextIteration() {
if ((inner != null) && inner.hasNext()) {
next = inner.next();
hasNext = true;
return;
}
while (iterator.hasNext()) {
if (inner == null || !inner.hasNext()) {
final T arg = iterator.next();
final LongStream result = mapper.apply(arg);
if (result != null) {
inner = result.iterator();
}
}
if ((inner != null) && inner.hasNext()) {
next = inner.next();
hasNext = true;
return;
}
}
hasNext = false;
}
use of com.annimon.stream.LongStream in project Lightweight-Stream-API by aNNiMON.
the class LongFlatMap method hasNext.
@Override
public boolean hasNext() {
if (inner != null && inner.hasNext()) {
return true;
}
while (iterator.hasNext()) {
if (innerStream != null) {
innerStream.close();
innerStream = null;
}
final long arg = iterator.nextLong();
final LongStream result = mapper.apply(arg);
if (result == null) {
continue;
}
innerStream = result;
if (result.iterator().hasNext()) {
inner = result.iterator();
return true;
}
}
if (innerStream != null) {
innerStream.close();
innerStream = null;
}
return false;
}
use of com.annimon.stream.LongStream in project Lightweight-Stream-API by aNNiMON.
the class CustomTest method testCustomLongermediateOperator_Zip.
@Test
public void testCustomLongermediateOperator_Zip() {
final LongBinaryOperator op = new LongBinaryOperator() {
@Override
public long applyAsLong(long left, long right) {
return left + right;
}
};
LongStream s1 = LongStream.of(1, 3, 5, 7, 9);
LongStream s2 = LongStream.of(2, 4, 6, 8);
long[] expected = { 3, 7, 11, 15 };
LongStream result = s1.custom(new CustomOperators.ZipLong(s2, op));
assertThat(result.toArray(), is(expected));
}
use of com.annimon.stream.LongStream in project Lightweight-Stream-API by aNNiMON.
the class LongStreamMatcherTest method testElements.
@Test
public void testElements() {
final LongStream stream = LongStream.of(-813, 123456, Integer.MAX_VALUE);
final Long[] expected = new Long[] { -813L, 123456L, (long) Integer.MAX_VALUE };
final Matcher<LongStream> matcher = elements(arrayContaining(expected));
assertThat(stream, matcher);
assertTrue(matcher.matches(stream));
assertFalse(elements(arrayContaining(expected)).matches(LongStream.empty()));
assertThat(matcher, description(allOf(containsString("LongStream elements"), containsString(Stream.of(expected).map(new Function<Long, String>() {
@Override
public String apply(Long t) {
return String.format("<%sL>", t.toString());
}
}).collect(Collectors.joining(", "))))));
}
use of com.annimon.stream.LongStream in project Lightweight-Stream-API by aNNiMON.
the class OnCloseTest method testOnCloseConcat.
@Test
public void testOnCloseConcat() {
final int[] counter = new int[] { 0 };
final Runnable runnable = new Runnable() {
@Override
public void run() {
counter[0]++;
}
};
LongStream stream1 = LongStream.range(0, 2).onClose(runnable);
LongStream stream2 = LongStream.range(0, 2).onClose(runnable);
LongStream stream = LongStream.concat(stream1, stream2).onClose(runnable);
stream.count();
assertThat(counter[0], is(0));
stream.close();
assertThat(counter[0], is(3));
}
Aggregations