use of java8.util.stream.Stream in project streamsupport by stefan-zobel.
the class ConcatTest method assertDoubleConcat.
private void assertDoubleConcat(Stream<Integer> s1, Stream<Integer> s2, boolean parallel, boolean ordered) {
DoubleStream result = DoubleStreams.concat(s1.mapToDouble(Integer::doubleValue), s2.mapToDouble(Integer::doubleValue));
assertEquals(result.isParallel(), parallel);
assertConcatContent(result.spliterator(), ordered, StreamSupport.stream(expected).mapToDouble(Integer::doubleValue).spliterator());
}
use of java8.util.stream.Stream in project streamsupport by stefan-zobel.
the class ConcatTest method assertIntConcat.
private void assertIntConcat(Stream<Integer> s1, Stream<Integer> s2, boolean parallel, boolean ordered) {
IntStream result = IntStreams.concat(s1.mapToInt(Integer::intValue), s2.mapToInt(Integer::intValue));
assertEquals(result.isParallel(), parallel);
assertConcatContent(result.spliterator(), ordered, StreamSupport.stream(expected).mapToInt(Integer::intValue).spliterator());
}
use of java8.util.stream.Stream in project streamsupport by stefan-zobel.
the class FlatMapOpTest method testClose.
@Test
public void testClose() {
AtomicInteger before = new AtomicInteger();
AtomicInteger onClose = new AtomicInteger();
Supplier<Stream<Integer>> s = () -> {
before.set(0);
onClose.set(0);
return RefStreams.of(1, 2).peek(e -> before.getAndIncrement());
};
s.get().flatMap(i -> RefStreams.of(i, i).onClose(onClose::getAndIncrement)).count();
assertEquals(before.get(), onClose.get());
s.get().flatMapToInt(i -> IntStreams.of(i, i).onClose(onClose::getAndIncrement)).count();
assertEquals(before.get(), onClose.get());
s.get().flatMapToLong(i -> LongStreams.of(i, i).onClose(onClose::getAndIncrement)).count();
assertEquals(before.get(), onClose.get());
s.get().flatMapToDouble(i -> DoubleStreams.of(i, i).onClose(onClose::getAndIncrement)).count();
assertEquals(before.get(), onClose.get());
}
use of java8.util.stream.Stream in project streamsupport by stefan-zobel.
the class SplittableRandomTest method longsDataProvider.
@DataProvider(name = "longs")
public static Object[][] longsDataProvider() {
List<Object[]> data = new ArrayList<>();
// Function to create a stream using a RandomBoxedSpliterator
Function<Function<SplittableRandom, Long>, LongStream> rbsf = sf -> StreamSupport.stream(new RandomBoxedSpliterator<>(new SplittableRandom(), 0, SIZE, sf), false).mapToLong(i -> i);
// Unbounded
data.add(new Object[] { TestData.Factory.ofLongSupplier(String.format("new SplittableRandom().longs().limit(%d)", SIZE), () -> new SplittableRandom().longs().limit(SIZE)), randomAsserter(SIZE, Long.MAX_VALUE, 0L) });
data.add(new Object[] { TestData.Factory.ofLongSupplier(String.format("new SplittableRandom().longs(%d)", SIZE), () -> new SplittableRandom().longs(SIZE)), randomAsserter(SIZE, Long.MAX_VALUE, 0L) });
data.add(new Object[] { TestData.Factory.ofLongSupplier(String.format("new RandomBoxedSpliterator(0, %d, sr -> sr.nextLong())", SIZE), () -> rbsf.apply(sr -> sr.nextLong())), randomAsserter(SIZE, Long.MAX_VALUE, 0L) });
for (int b : BOUNDS) {
for (int o : ORIGINS) {
final long origin = o;
final long bound = b;
data.add(new Object[] { TestData.Factory.ofLongSupplier(String.format("new SplittableRandom().longs(%d, %d).limit(%d)", origin, bound, SIZE), () -> new SplittableRandom().longs(origin, bound).limit(SIZE)), randomAsserter(SIZE, origin, bound) });
data.add(new Object[] { TestData.Factory.ofLongSupplier(String.format("new SplittableRandom().longs(%d, %d, %d)", SIZE, origin, bound), () -> new SplittableRandom().longs(SIZE, origin, bound)), randomAsserter(SIZE, origin, bound) });
if (origin == 0) {
data.add(new Object[] { TestData.Factory.ofLongSupplier(String.format("new RandomBoxedSpliterator(0, %d, sr -> sr.nextLong(%d))", SIZE, bound), () -> rbsf.apply(sr -> sr.nextLong(bound))), randomAsserter(SIZE, origin, bound) });
}
data.add(new Object[] { TestData.Factory.ofLongSupplier(String.format("new RandomBoxedSpliterator(0, %d, sr -> sr.nextLong(%d, %d))", SIZE, origin, bound), () -> rbsf.apply(sr -> sr.nextLong(origin, bound))), randomAsserter(SIZE, origin, bound) });
}
}
return data.toArray(new Object[0][]);
}
use of java8.util.stream.Stream in project streamsupport by stefan-zobel.
the class SplittableRandomTest method doublesDataProvider.
@DataProvider(name = "doubles")
public static Object[][] doublesDataProvider() {
List<Object[]> data = new ArrayList<>();
// Function to create a stream using a RandomBoxedSpliterator
Function<Function<SplittableRandom, Double>, DoubleStream> rbsf = sf -> StreamSupport.stream(new RandomBoxedSpliterator<>(new SplittableRandom(), 0, SIZE, sf), false).mapToDouble(i -> i);
// Unbounded
data.add(new Object[] { TestData.Factory.ofDoubleSupplier(String.format("new SplittableRandom().doubles().limit(%d)", SIZE), () -> new SplittableRandom().doubles().limit(SIZE)), randomAsserter(SIZE, Double.MAX_VALUE, 0d) });
data.add(new Object[] { TestData.Factory.ofDoubleSupplier(String.format("new SplittableRandom().doubles(%d)", SIZE), () -> new SplittableRandom().doubles(SIZE)), randomAsserter(SIZE, Double.MAX_VALUE, 0d) });
data.add(new Object[] { TestData.Factory.ofDoubleSupplier(String.format("new RandomBoxedSpliterator(0, %d, sr -> sr.nextDouble())", SIZE), () -> rbsf.apply(sr -> sr.nextDouble())), randomAsserter(SIZE, Double.MAX_VALUE, 0d) });
for (int b : BOUNDS) {
for (int o : ORIGINS) {
final double origin = o;
final double bound = b;
data.add(new Object[] { TestData.Factory.ofDoubleSupplier(String.format("new SplittableRandom().doubles(%f, %f).limit(%d)", origin, bound, SIZE), () -> new SplittableRandom().doubles(origin, bound).limit(SIZE)), randomAsserter(SIZE, origin, bound) });
data.add(new Object[] { TestData.Factory.ofDoubleSupplier(String.format("new SplittableRandom().doubles(%d, %f, %f)", SIZE, origin, bound), () -> new SplittableRandom().doubles(SIZE, origin, bound)), randomAsserter(SIZE, origin, bound) });
if (origin == 0) {
data.add(new Object[] { TestData.Factory.ofDoubleSupplier(String.format("new RandomBoxedSpliterator(0, %d, sr -> sr.nextDouble(%f))", SIZE, bound), () -> rbsf.apply(sr -> sr.nextDouble(bound))), randomAsserter(SIZE, origin, bound) });
}
data.add(new Object[] { TestData.Factory.ofDoubleSupplier(String.format("new RandomBoxedSpliterator(0, %d, sr -> sr.nextDouble(%f, %f))", SIZE, origin, bound), () -> rbsf.apply(sr -> sr.nextDouble(origin, bound))), randomAsserter(SIZE, origin, bound) });
}
}
return data.toArray(new Object[0][]);
}
Aggregations