下面列出了java.util.Spliterators#emptySpliterator ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Fetch data immediately before traversing or sub-page splitting.
*/
private Spliterator<T> ensurePage() {
if (danglingFirstPage != null) {
final Spliterator<T> fp = danglingFirstPage;
danglingFirstPage = null;
currentPage = fp;
start = fp.getExactSizeIfKnown();
return fp;
} else if (currentPage != null) {
return currentPage;
} else if (start >= end) {
return Spliterators.emptySpliterator();
}
var spliterator = spliterator(supplier.fetch(start, min(end - start, pageSize), l -> end = min(l, end)));
start += spliterator.getExactSizeIfKnown();
currentPage = spliterator;
return spliterator;
}
private boolean init() {
if (context == null)
return false;
if (target == null) {
Box<T> first = new Box<>();
source = TailSpliterator.tryAdvanceWithTail(source, first);
Stream<U> stream = source == null ? emptyMapper.get() : mapper.apply(first.a, StreamEx.of(source));
source = null;
mapper = null;
emptyMapper = null;
if (stream == null) {
target = Spliterators.emptySpliterator();
} else {
StreamContext ctx = StreamContext.of(stream);
if (ctx.closeHandler != null)
context.onClose(ctx.closeHandler);
target = stream.spliterator();
}
}
return true;
}
public static <T> Spliterator<T> dropRight(Spliterator<T> source, int skip){
if(skip==0){
return source;
}
if(skip==source.getExactSizeIfKnown()){ //right sized already
return Spliterators.emptySpliterator();
}
return new SkipLastSpliterator<T>(source,skip);
}
@Override
public Spliterator<T> trySplit() {
Spliterator<T> source = this.source;
switch (ThreadLocalRandom.current().nextInt(3)) {
case 0:
return Spliterators.emptySpliterator();
case 1:
this.source = Spliterators.emptySpliterator();
return source;
default:
Spliterator<T> split = source.trySplit();
return split == null ? null : new EmptyingSpliterator<>(split);
}
}
@Override
public Spliterator<T> spliterator() {
return Spliterators.emptySpliterator();
}
@Override
public Spliterator<T> spliterator() {
return Spliterators.emptySpliterator();
}
@Override
public Spliterator<T> spliterator() {
return Spliterators.emptySpliterator();
}
@Override
public Spliterator<Object> spliterator() {
return Spliterators.emptySpliterator();
}
@Override
public Spliterator<T> spliterator() {
return Spliterators.emptySpliterator();
}
@Override
public Spliterator<E> spliterator() {
return Spliterators.emptySpliterator();
}
@Override
public Spliterator<T> spliterator() {
return Spliterators.emptySpliterator();
}
@Override
public Spliterator<Object> spliterator() {
return Spliterators.emptySpliterator();
}
@Override
public Spliterator<T> spliterator() {
return Spliterators.emptySpliterator();
}
/**
* Returns a {@code StreamEx} consisting of the distinct elements (according
* to {@link Object#equals(Object)}) which appear at least specified number
* of times in this stream.
*
* <p>
* This operation is not guaranteed to be stable: any of equal elements can
* be selected for the output. However if this stream is ordered then order
* is preserved.
*
* <p>
* This is a stateful <a
* href="package-summary.html#StreamOps">quasi-intermediate</a> operation.
*
* @param atLeast minimal number of occurrences required to select the
* element. If atLeast is 1 or less, then this method is equivalent
* to {@link #distinct()}.
* @return the new stream
* @see #distinct()
* @since 0.3.1
*/
public S distinct(long atLeast) {
if (atLeast <= 1)
return distinct();
Spliterator<T> spliterator = spliterator();
Spliterator<T> result;
if (spliterator.hasCharacteristics(Spliterator.DISTINCT))
// already distinct: cannot have any repeating elements
result = Spliterators.emptySpliterator();
else
result = new DistinctSpliterator<>(spliterator, atLeast);
return supply(result);
}
/**
* Returns an empty spliterator in which calls to
* {@link java.util.Spliterator#trySplit()} always return {@code null}.
*
* @return an empty spliterator
* @since 1.8
*/
public Spliterator<E> spliterator() {
return Spliterators.emptySpliterator();
}
/**
* Returns an empty spliterator in which calls to
* {@link java.util.Spliterator#trySplit()} always return {@code null}.
*
* @return an empty spliterator
* @since 1.8
*/
public Spliterator<E> spliterator() {
return Spliterators.emptySpliterator();
}
/**
* Returns an empty spliterator in which calls to
* {@link java.util.Spliterator#trySplit()} always return {@code null}.
*
* @return an empty spliterator
* @since 1.8
*/
public Spliterator<E> spliterator() {
return Spliterators.emptySpliterator();
}
/**
* Returns an empty spliterator in which calls to
* {@link java.util.Spliterator#trySplit()} always return {@code null}.
*
* @return an empty spliterator
* @since 1.8
*/
public Spliterator<E> spliterator() {
return Spliterators.emptySpliterator();
}
/**
* Returns an empty spliterator in which calls to
* {@link java.util.Spliterator#trySplit()} always return {@code null}.
*
* @return an empty spliterator
* @since 1.8
*/
public Spliterator<E> spliterator() {
return Spliterators.emptySpliterator();
}
/**
* Performs a cross product of current stream with specified
* {@link Collection} of elements. As a result the {@link EntryStream} is
* created whose keys are elements of current stream and values are elements
* of the specified collection.
*
* <p>
* The resulting stream contains all the possible combinations of keys and
* values.
*
* <p>
* This is an <a href="package-summary.html#StreamOps">intermediate</a>
* operation.
*
* @param <V> the type of collection elements
* @param other the collection to perform a cross product with
* @return the new {@code EntryStream}
* @throws NullPointerException if other is null
* @since 0.2.3
*/
public <V> EntryStream<T, V> cross(Collection<? extends V> other) {
if (other.isEmpty())
return new EntryStream<>(Spliterators.emptySpliterator(), context);
return cross(t -> of(other));
}