Java Lambda Stream Factory
import java.util.*;
import java.util.stream.*;
public class LambdaStream {
public static <T> Stream<T> of(Spliterator<T> spliterator) {
return StreamSupport.stream(spliterator, false);
}
public static <T> Stream<T> of(Iterable<T> iterable) {
return of(iterable.spliterator());
}
public static <E> Stream<E> of(Iterator<E> iterator) {
return of(Spliterators.spliteratorUnknownSize(iterator, 0));
}
public static <E> Stream<E> of(Enumeration<E> enumeration) {
return of(new Iterator<E>() {
@Override
public boolean hasNext() {
return enumeration.hasMoreElements();
}
@Override
public E next() {
return enumeration.nextElement();
}
});
}
public static <E> Stream<E> of(Collection<E> collect) {
return collect.stream();
}
public static <K, V> Stream<Map.Entry<K, V>> of(Map<K, V> map) {
return map.entrySet().stream();
}
public static <T> Stream<T> of(T t) {
return Stream.of(t);
}
public static <T> Stream<T> ofNullable(T t) {
return t == null ? Stream.empty() : Stream.of(t);
}
public static <T> Stream<T> empty() {
return Stream.empty();
}
@SafeVarargs
public static <T> Stream<T> of(T... values) {
return Arrays.stream(values);
}
public static <T> Stream<T> of(T[] array, int startInclusive, int endExclusive) {
return Arrays.stream(array, startInclusive, endExclusive);
}
public static IntStream of(int[] array) {
return Arrays.stream(array);
}
public static IntStream of(int[] array, int startInclusive, int endExclusive) {
return Arrays.stream(array, startInclusive, endExclusive);
}
public static LongStream of(long[] array) {
return Arrays.stream(array);
}
public static LongStream of(long[] array, int startInclusive, int endExclusive) {
return Arrays.stream(array, startInclusive, endExclusive);
}
public static DoubleStream of(double[] array) {
return Arrays.stream(array);
}
public static DoubleStream of(double[] array, int startInclusive, int endExclusive) {
return Arrays.stream(array, startInclusive, endExclusive);
}
}
标签:return,stream,Stream,LambdaStream,static,Java,array,public
From: https://www.cnblogs.com/zhuzhongxing/p/16624497.html