use of com.annimon.stream.DoubleStream 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]++;
}
};
DoubleStream stream = DoubleStream.of(2, 3, 4).onClose(runnable).onClose(runnable).flatMap(new DoubleFunction<DoubleStream>() {
@Override
public DoubleStream apply(final double i) {
return DoubleStream.of(2, 3, 4).onClose(runnable);
}
});
stream.count();
assertThat(counter[0], is(3));
stream.close();
assertThat(counter[0], is(5));
}
use of com.annimon.stream.DoubleStream 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]++;
}
};
DoubleStream stream1 = DoubleStream.of(0, 1).onClose(runnable);
DoubleStream stream2 = DoubleStream.of(2, 3).onClose(runnable);
DoubleStream stream = DoubleStream.concat(stream1, stream2).onClose(runnable);
stream.count();
assertThat(counter[0], is(0));
stream.close();
assertThat(counter[0], is(3));
}
use of com.annimon.stream.DoubleStream in project Lightweight-Stream-API by aNNiMON.
the class GenerateTest method testStreamGenerate.
@Test
public void testStreamGenerate() {
DoubleStream stream = DoubleStream.generate(new DoubleSupplier() {
@Override
public double getAsDouble() {
return 1.234;
}
});
assertThat(stream.limit(3), elements(arrayContaining(1.234, 1.234, 1.234)));
}
use of com.annimon.stream.DoubleStream in project Lightweight-Stream-API by aNNiMON.
the class ObjFlatMapToDouble 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 DoubleStream 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.DoubleStream in project Lightweight-Stream-API by aNNiMON.
the class ConcatTest method testStreamConcat.
@Test
public void testStreamConcat() {
DoubleStream a1 = DoubleStream.empty();
DoubleStream b1 = DoubleStream.empty();
assertThat(DoubleStream.concat(a1, b1), isEmpty());
DoubleStream a2 = DoubleStream.of(10.123, Math.PI);
DoubleStream b2 = DoubleStream.empty();
DoubleStream.concat(a2, b2).custom(assertElements(arrayContaining(10.123, Math.PI)));
DoubleStream a3 = DoubleStream.of(10.123, Math.PI);
DoubleStream b3 = DoubleStream.empty();
DoubleStream.concat(a3, b3).custom(assertElements(arrayContaining(10.123, Math.PI)));
DoubleStream a4 = DoubleStream.of(10.123, Math.PI, -1e11, -1e8);
DoubleStream b4 = DoubleStream.of(1.617, 9.81);
DoubleStream.concat(a4, b4).custom(assertElements(arrayContaining(10.123, Math.PI, -1e11, -1e8, 1.617, 9.81)));
}
Aggregations