mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
StreamUtil.of(Iterable)方法优化
This commit is contained in:
parent
46daf6c1c0
commit
05e14f0fb6
@ -1,6 +1,5 @@
|
|||||||
package cn.hutool.core.stream;
|
package cn.hutool.core.stream;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
|
||||||
import cn.hutool.core.io.IORuntimeException;
|
import cn.hutool.core.io.IORuntimeException;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.util.CharsetUtil;
|
import cn.hutool.core.util.CharsetUtil;
|
||||||
@ -10,6 +9,7 @@ import java.io.IOException;
|
|||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Spliterators;
|
import java.util.Spliterators;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@ -52,9 +52,10 @@ public class StreamUtil {
|
|||||||
*/
|
*/
|
||||||
public static <T> Stream<T> of(Iterable<T> iterable, boolean parallel) {
|
public static <T> Stream<T> of(Iterable<T> iterable, boolean parallel) {
|
||||||
Assert.notNull(iterable, "Iterable must be not null!");
|
Assert.notNull(iterable, "Iterable must be not null!");
|
||||||
return StreamSupport.stream(
|
|
||||||
Spliterators.spliterator(CollUtil.toCollection(iterable), 0),
|
return iterable instanceof Collection ?
|
||||||
parallel);
|
((Collection<T>) iterable).stream() :
|
||||||
|
StreamSupport.stream(iterable.spliterator(), parallel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user