List of usage examples for java.util Spliterators iterator
public static PrimitiveIterator.OfDouble iterator(Spliterator.OfDouble spliterator)
From source file:com.wrmsr.kleist.util.Itertools.java
public static <L, R> Spliterator<Pair<L, R>> zip(Spliterator<L> left, Spliterator<R> right) { return Spliterators.spliteratorUnknownSize(zip(Spliterators.iterator(left), Spliterators.iterator(right)), 0);/*ww w . j a va2 s . c o m*/ }
From source file:com.github.steveash.guavate.Guavate.java
/** * Creates a stream that wraps a stream with the index. * <p>/*from w w w. ja va 2 s .c o m*/ * Each input object is decorated with an {@link ObjIntPair}. * The {@code int} is the index of the element in the stream. * @param <T> the type of the stream * @param stream the stream to index * @return a stream of pairs, containing the element and index */ public static <T> Stream<ObjIntPair<T>> zipWithIndex(Stream<T> stream) { Spliterator<T> split1 = stream.spliterator(); Iterator<T> it1 = Spliterators.iterator(split1); Iterator<ObjIntPair<T>> it = new Iterator<ObjIntPair<T>>() { int index = 0; @Override public boolean hasNext() { return it1.hasNext(); } @Override public ObjIntPair<T> next() { return ObjIntPair.of(it1.next(), index++); } }; Spliterator<ObjIntPair<T>> split = Spliterators.spliterator(it, split1.getExactSizeIfKnown(), split1.characteristics()); return StreamSupport.stream(split, false); }
From source file:com.wrmsr.kleist.util.Itertools.java
public static <T> Spliterator<EnumeratedElement<T>> enumerate(Spliterator<T> spliterator) { int characteristics = spliterator.characteristics() | Spliterator.NONNULL & ~Spliterator.CONCURRENT; return Spliterators.spliterator(enumerate(Spliterators.iterator(spliterator)), spliterator.estimateSize(), characteristics);//from ww w . jav a 2 s . c o m }
From source file:com.github.steveash.guavate.Guavate.java
/** * Creates a stream that combines two other streams, continuing until either stream ends. * <p>/*from w ww .j av a2 s.c o m*/ * The combiner function is called once for each pair of objects found in the input streams. * @param <A> the type of the first stream * @param <B> the type of the second stream * @param <R> the type of the resulting stream * @param stream1 the first stream * @param stream2 the first stream * @param zipper the function used to combine the pair of objects * @return a stream of pairs, one from each stream */ private static <A, B, R> Stream<R> zip(Stream<A> stream1, Stream<B> stream2, BiFunction<A, B, R> zipper) { // this is private for now, to see if it is really needed on the API // it suffers from generics problems at the call site with common zipper functions // as such, it is less useful than it might seem Spliterator<A> split1 = stream1.spliterator(); Spliterator<B> split2 = stream2.spliterator(); // merged stream lacks some characteristics int characteristics = split1.characteristics() & split2.characteristics() & ~(Spliterator.DISTINCT | Spliterator.SORTED); long size = Math.min(split1.getExactSizeIfKnown(), split2.getExactSizeIfKnown()); Iterator<A> it1 = Spliterators.iterator(split1); Iterator<B> it2 = Spliterators.iterator(split2); Iterator<R> it = new Iterator<R>() { @Override public boolean hasNext() { return it1.hasNext() && it2.hasNext(); } @Override public R next() { return zipper.apply(it1.next(), it2.next()); } }; Spliterator<R> split = Spliterators.spliterator(it, size, characteristics); return StreamSupport.stream(split, false); }
From source file:enumj.Enumerator.java
/** * Returns an enumerator enumerating over the elements of an existing * {@code Spliterator}./* ww w.j a va 2s. c o m*/ * * @param <E> the type of elements being enumerated. * @param source the {@link Spliterator} being enumerated upon. * @return the new enumerator. * @exception IllegalArgumentException {@code source} is null. */ public static <E> Enumerator<E> of(Spliterator<E> source) { Checks.ensureNotNull(source, Messages.NULL_ENUMERATOR_SOURCE); return of(Spliterators.iterator(source)); }