Most visited

Recently visited

Added in API level 24

Spliterators.AbstractSpliterator

public static abstract class Spliterators.AbstractSpliterator
extends Object implements Spliterator<T>

java.lang.Object
   ↳ java.util.Spliterators.AbstractSpliterator<T>


抽象 Spliterator ,实现 trySplit以允许有限的并行性。

扩展类只需要实现tryAdvance 如果扩展类可以提供更高性能的实现,则应该覆盖forEach

也可以看看:

Summary

Inherited constants

From interface java.util.Spliterator

Protected constructors

Spliterators.AbstractSpliterator(long est, int additionalCharacteristics)

创建报告给定估计大小和附加特性的分解器。

Public methods

int characteristics()

返回此Spliterator及其元素的一组特征。

long estimateSize()

返回 forEachRemaining(Consumer )遍历将遇到的元素数量的估计值,如果计算结果无限,未知或成本太高,则返回 MAX_VALUE

Spliterator<T> trySplit()

如果这个分割器可以被分割,返回一个Spliterator覆盖元素,当从这个方法返回时,不会被这个分割器覆盖。 这种实现允许有限的并行性。

Inherited methods

From class java.lang.Object
From interface java.util.Spliterator

Protected constructors

Spliterators.AbstractSpliterator

Added in API level 24
Spliterators.AbstractSpliterator (long est, 
                int additionalCharacteristics)

创建报告给定估计大小和附加特性的分解器。

Parameters
est long: the estimated size of this spliterator if known, otherwise Long.MAX_VALUE.
additionalCharacteristics int: properties of this spliterator's source or elements. If SIZED is reported then this spliterator will additionally report SUBSIZED.

Public methods

characteristics

Added in API level 24
int characteristics ()

返回此Spliterator及其元素的一组特征。 结果从表示为或运算值ORDEREDDISTINCTSORTEDSIZEDNONNULLIMMUTABLECONCURRENTSUBSIZED 重复调用characteristics()在给定的spliterator之前或在两者之间的调用, trySplit ,应始终返回相同的结果。

如果Spliterator报告一组不一致的特征(无论是从单个调用还是跨多个调用返回的特征),都不能保证使用此Spliterator的任何计算。

实现要求:
  • This implementation returns the characteristics as reported when created.
Returns
int a representation of characteristics

estimateSize

Added in API level 24
long estimateSize ()

返回 forEachRemaining(Consumer )遍历将遇到的元素数量的估计值,或者返回 MAX_VALUE如果无限,未知或计算成本太高。

如果此Spliterator为SIZED并且尚未部分遍历或拆分,或者此Spliterator为SUBSIZED且尚未部分遍历,则此估计必须是完整遍历可能遇到的元素的准确计数。 否则,这个估计可能是任意不准确的,但必须按照调用trySplit()规定降低。

实现要求:
  • This implementation returns the estimated size as reported when created and, if the estimate size is known, decreases in size when split.
Returns
long the estimated size, or Long.MAX_VALUE if infinite, unknown, or too expensive to compute.

trySplit

Added in API level 24
Spliterator<T> trySplit ()

如果这个分割器可以被分割,返回一个Spliterator覆盖元素,当从这个方法返回时,不会被这个分割器覆盖。

如果此Spliterator为 ORDERED ,则返回的Spliterator必须覆盖元素的严格前缀。

除非此Spliterator覆盖无限数量的元素,否则重复调用trySplit()最终必须返回null 非空返回时:

  • the value reported for estimateSize() before splitting, must, after splitting, be greater than or equal to estimateSize() for this and the returned Spliterator; and
  • if this Spliterator is SUBSIZED, then estimateSize() for this spliterator before splitting must be equal to the sum of estimateSize() for this and the returned Spliterator after splitting.

出于任何原因,此方法可能会返回null ,包括空白,遍历开始后无法拆分,数据结构约束和效率考虑。 这种实现允许有限的并行性。

Returns
Spliterator<T> a Spliterator covering some portion of the elements, or null if this spliterator cannot be split

Hooray!