use of com.annimon.stream.IntStream in project Lightweight-Stream-API by aNNiMON.
the class OnCloseTest method testOnClose.
@Test
public void testOnClose() {
final boolean[] state = new boolean[] { false };
IntStream stream = IntStream.of(0, 1, 2).onClose(new Runnable() {
@Override
public void run() {
state[0] = true;
}
});
stream.findFirst();
stream.close();
assertTrue(state[0]);
}
use of com.annimon.stream.IntStream in project Lightweight-Stream-API by aNNiMON.
the class SortedTest method testSortedLazy.
@Test
public void testSortedLazy() {
int[] expected = { -7, 0, 3, 6, 9, 19 };
List<Integer> input = new ArrayList<Integer>(6);
input.addAll(Arrays.asList(6, 3, 9));
IntStream stream = Stream.of(input).mapToInt(Functions.toInt()).sorted();
input.addAll(Arrays.asList(0, -7, 19));
assertThat(stream.toArray(), is(expected));
}
use of com.annimon.stream.IntStream in project Lightweight-Stream-API by aNNiMON.
the class CustomTest method testCustomIntermediateOperator_Zip.
@Test
@SuppressWarnings("unchecked")
public void testCustomIntermediateOperator_Zip() {
final DoubleBinaryOperator op = new DoubleBinaryOperator() {
@Override
public double applyAsDouble(double left, double right) {
return left * right;
}
};
DoubleStream s1 = DoubleStream.of(1.01, 2.02, 3.03);
IntStream s2 = IntStream.range(2, 5);
DoubleStream result = s1.custom(new CustomOperators.ZipWithIntStream(s2, op));
assertThat(result, elements(arrayContaining(closeTo(2.02, 0.00001), closeTo(6.06, 0.00001), closeTo(12.12, 0.00001))));
}
use of com.annimon.stream.IntStream in project Lightweight-Stream-API by aNNiMON.
the class ObjFlatMapToInt 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 IntStream 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.IntStream in project Lightweight-Stream-API by aNNiMON.
the class IntFlatMap method hasNext.
@Override
public boolean hasNext() {
if (inner != null && inner.hasNext()) {
return true;
}
while (iterator.hasNext()) {
if (innerStream != null) {
innerStream.close();
innerStream = null;
}
final int arg = iterator.nextInt();
final IntStream 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;
}
Aggregations