Commit 1e8c38cd authored by Simon Barner's avatar Simon Barner
Browse files

Move "asStream()", a method that converts an {@link Iterator} to a...

Move "asStream()", a method that converts an {@link Iterator} to a (sequential) {@link Stream}, to LambdaUtils
refs 2950
parent 5b84057e
......@@ -17,7 +17,10 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.common.util;
import static java.util.stream.StreamSupport.stream;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.Set;
......@@ -33,7 +36,7 @@ import java.util.stream.Stream;
* @author diewald
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 398AEE2F6FA7CB30D9B23BC49734AC46
* @ConQAT.Rating YELLOW Hash: A2B03C6E9EAA4377F36137398B6D9DDE
*/
public class LambdaUtils {
......@@ -215,4 +218,17 @@ public class LambdaUtils {
Collection<T> inColl, Function<T, R> mapper, Supplier<U> sup) {
return inColl.parallelStream().flatMap(mapper).collect(Collectors.toCollection(sup));
}
/** Converts an {@link Iterator} to a (sequential) {@link Stream}. */
public static <T> Stream<T> asStream(Iterator<T> iterator) {
Iterable<T> iterable = new Iterable<T>() {
/** {@inheritDoc} */
@Override
public Iterator<T> iterator() {
return iterator;
}
};
return stream(iterable.spliterator(), false);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment