use of java8.util.stream.DoubleStream in project streamsupport by stefan-zobel.
the class WhileOpStatefulTest method testWhileMulti.
private void testWhileMulti(Map<String, Supplier<Stream<Integer>>> sources, Consumer<Stream<Integer>> mRef, Consumer<IntStream> mInt, Consumer<LongStream> mLong, Consumer<DoubleStream> mDouble) {
Map<String, Function<Stream<Integer>, Stream<Integer>>> transforms = new HashMap<>();
transforms.put("Stream.sequential()", s -> {
BooleanSupplier isWithinExecutionPeriod = within(System.currentTimeMillis(), EXECUTION_TIME_LIMIT);
return s.peek(e -> {
if (!isWithinExecutionPeriod.getAsBoolean()) {
throw new RuntimeException();
}
});
});
transforms.put("Stream.parallel()", s -> {
BooleanSupplier isWithinExecutionPeriod = within(System.currentTimeMillis(), EXECUTION_TIME_LIMIT);
return s.parallel().peek(e -> {
if (!isWithinExecutionPeriod.getAsBoolean()) {
throw new RuntimeException();
}
});
});
Map<String, Consumer<Stream<Integer>>> actions = new HashMap<>();
actions.put("Ref", mRef);
actions.put("Int", s -> mInt.accept(s.mapToInt(e -> e)));
actions.put("Long", s -> mLong.accept(s.mapToLong(e -> e)));
actions.put("Double", s -> mDouble.accept(s.mapToDouble(e -> e)));
actions.put("Ref using defaults", s -> mRef.accept(DefaultMethodStreams.delegateTo(s)));
actions.put("Int using defaults", s -> mInt.accept(DefaultMethodStreams.delegateTo(s.mapToInt(e -> e))));
actions.put("Long using defaults", s -> mLong.accept(DefaultMethodStreams.delegateTo(s.mapToLong(e -> e))));
actions.put("Double using defaults", s -> mDouble.accept(DefaultMethodStreams.delegateTo(s.mapToDouble(e -> e))));
for (Map.Entry<String, Supplier<Stream<Integer>>> s : sources.entrySet()) {
setContext("source", s.getKey());
for (Map.Entry<String, Function<Stream<Integer>, Stream<Integer>>> t : transforms.entrySet()) {
setContext("transform", t.getKey());
for (Map.Entry<String, Consumer<Stream<Integer>>> a : actions.entrySet()) {
setContext("shape", a.getKey());
Stream<Integer> stream = s.getValue().get();
stream = t.getValue().apply(stream);
a.getValue().accept(stream);
}
}
}
}
use of java8.util.stream.DoubleStream in project streamsupport by stefan-zobel.
the class WhileOpTest method testDoubleDefaultClose.
@Test(groups = { "serialization-hostile" })
public void testDoubleDefaultClose() {
AtomicBoolean isClosed = new AtomicBoolean();
DoubleStream s = DoubleStreams.of(1, 2, 3).onClose(() -> isClosed.set(true));
DoubleStream ds = null;
try {
ds = DefaultMethodStreams.delegateTo(s).takeWhile(e -> e < 3);
ds.count();
} finally {
if (ds != null) {
ds.close();
}
}
assertTrue(isClosed.get());
}
use of java8.util.stream.DoubleStream in project streamsupport by stefan-zobel.
the class FindAnyOpTest method exerciseDoubleStream.
void exerciseDoubleStream(TestData.OfDouble data, Function<DoubleStream, DoubleStream> fs) {
OptionalDouble or = withData(data).terminal(fs, s -> s.findAny()).equalator(DOUBLE_VALID_ANSWER).exercise();
if (or.isPresent()) {
double r = or.getAsDouble();
PrimitiveIterator.OfDouble it = fs.apply(data.stream()).iterator();
boolean contained = false;
while (!contained && it.hasNext()) {
contained = r == it.nextDouble();
}
assertTrue(contained);
} else {
assertFalse(fs.apply(data.stream()).iterator().hasNext());
}
}
Aggregations