public void testEveryMapShape() { assertCountSum( StreamSupport.stream(countTo(1000)) .mapToInt(i -> i - 1) .mapToObj(i -> i + 1) .mapToLong(i -> i - 1) .mapToObj(i -> i + 1) .mapToDouble(i -> i - 1) .mapToObj(i -> i + 1) .mapToInt(i -> (int) (double) i) .mapToLong(i -> i) .mapToDouble(i -> i) .mapToLong(i -> (long) i) .mapToInt(i -> (int) i) .mapToObj(i -> i), 1000, StreamSupport.stream(countTo(1000)).mapToInt(i -> i).sum()); }
public void testMap() { assertCountSum(StreamSupport.stream(countTo(0)).map(mId), 0, 0); assertCountSum(StreamSupport.stream(countTo(10)).map(mId), 10, 55); assertCountSum(StreamSupport.stream(countTo(10)).map(mZero), 10, 0); assertCountSum(StreamSupport.stream(countTo(0)).map(mDoubler), 0, 0); assertCountSum(StreamSupport.stream(countTo(10)).map(mDoubler), 10, 110); assertCountSum(StreamSupport.stream(countTo(10)).map(mDoubler).map(mDoubler), 10, 220); exerciseOps(countTo(0), s -> s.map(LambdaTestHelpers.identity()), countTo(0)); exerciseOps(countTo(1000), s -> s.map(LambdaTestHelpers.identity()), countTo(1000)); // @@@ Force cast to integer so output is Stream<Integer> rather an IntStream // this just ensures that no warnings are logged about boxing // when the result is compared with the output exerciseOps(countTo(1000), s -> s.map(e -> (Integer) (1000 + e)), range(1001, 2000)); }
static { { List<Object[]> list = new ArrayList<>(); for (Object[] data : arrays) { final Object name = data[0]; final Integer[] ints = (Integer[]) data[1]; final List<Integer> intsAsList = Arrays.asList(ints); list.add(arrayDataDescr("array:" + name, ints)); list.add(collectionDataDescr("ArrayList.asList:" + name, intsAsList)); list.add(collectionDataDescr("ArrayList:" + name, new ArrayList<>(intsAsList))); list.add( streamDataDescr( "DelegatingStream(ArrayList):" + name, () -> StreamSupport.stream( new ArrayList<>( intsAsList) /*, new ArrayList<>().spliterator().characteristics()*/))); List<Integer> aList = new ArrayList<>(intsAsList); if (LambdaTestMode.isNormalMode()) { // Only include sub-lists for normal test execution mode // This data is serialization-hostile since the state of the // deserialized sub-list will be out of sync with the // enclosing list. list.add( collectionDataDescr( "ArrayList.Sublist:" + name, (ints.length) <= 1 ? aList.subList(0, 0) : aList.subList(1, ints.length / 2))); } list.add(collectionDataDescr("LinkedList:" + name, new LinkedList<>(intsAsList))); list.add(collectionDataDescr("HashSet:" + name, new HashSet<>(intsAsList))); list.add(collectionDataDescr("LinkedHashSet:" + name, new LinkedHashSet<>(intsAsList))); list.add(collectionDataDescr("TreeSet:" + name, new TreeSet<>(intsAsList))); SpinedBuffer<Integer> spinedBuffer = new SpinedBuffer<>(); java8.lang.Iterables.forEach(intsAsList, spinedBuffer); list.add(sbDataDescr("SpinedBuffer:" + name, spinedBuffer)); // @@@ Add more } testData = list.toArray(new Object[0][]); } // Simple combination of numbers and null values, probably excessive but may catch // errors for initialization/termination/sequence // @@@ This is separate from the other data for now until nulls are consistently supported by // all operations { List<Object[]> list = new ArrayList<>(); int size = 5; for (int i = 0; i < (1 << size) - 2; i++) { Integer[] content = new Integer[size]; for (int e = 0; e < size; e++) { content[e] = (i & (1 << e)) > 0 ? e + 1 : null; } // ORDERED list.add(arrayDataDescr("array(with null):" + i, content)); // not ORDERED, DISTINCT list.add( collectionDataDescr("HashSet(with null):" + i, new HashSet<>(Arrays.asList(content)))); } withNullTestData = list.toArray(new Object[0][]); } { List<Object[]> spliterators = new ArrayList<>(); for (Object[] data : arrays) { final Object name = data[0]; final Integer[] ints = (Integer[]) data[1]; spliterators.add( splitDescr("Arrays.s(array):" + name, () -> java8.util.J8Arrays.spliterator(ints))); spliterators.add( splitDescr( "arrays.s(array,o,l):" + name, () -> java8.util.J8Arrays.spliterator(ints, 0, ints.length / 2))); spliterators.add( splitDescr( "SpinedBuffer.s():" + name, () -> { SpinedBuffer<Integer> sb = new SpinedBuffer<>(); for (Integer i : ints) sb.accept(i); return sb.getSpliterator(); })); spliterators.add( splitDescr( "Iterators.s(Arrays.s(array).iterator(), size):" + name, () -> Spliterators.spliterator(Arrays.asList(ints).iterator(), ints.length, 0))); spliterators.add( splitDescr( "Iterators.s(Arrays.s(array).iterator()):" + name, () -> Spliterators.spliteratorUnknownSize(Arrays.asList(ints).iterator(), 0))); // @@@ Add map and collection spliterators when spliterator() is exposed on Collection or // Iterable } spliteratorTestData = spliterators.toArray(new Object[0][]); } }
public Stream<Pair<String, Function<Command, Observable<Event>>>> parallelStream() { return StreamSupport.stream(spliterator(), true); }