hasCharacteristics(int characteristics) 查看是否包含给定的特性值
/** * Returns {@code true} if this Spliterator's {@link * #characteristics} contain all of the given characteristics. * * @implSpec * The default implementation returns true if the corresponding bits * of the given characteristics are set. * * @param characteristics the characteristics to check for * @return {@code true} if all the specified characteristics are present, * else {@code false} */ default boolean hasCharacteristics(int characteristics) { return (characteristics() & characteristics) == characteristics; }getComparator() :抛出一个不可实现的状态异常。
/** * If this Spliterator's source is {@link #SORTED} by a {@link Comparator}, * returns that {@code Comparator}. If the source is {@code SORTED} in * {@linkplain Comparable natural order}, returns {@code null}. Otherwise, * if the source is not {@code SORTED}, throws {@link IllegalStateException}. 如果源是有序的,返回用于排序的 Comparator 如果是按照自然排序的,就返回空 (就不需要比较器) 否则就抛出异常, * * @implSpec * The default implementation always throws {@link IllegalStateException}. * * @return a Comparator, or {@code null} if the elements are sorted in the * natural order. * @throws IllegalStateException if the spliterator does not report * a characteristic of {@code SORTED}. */ default Comparator<? super T> getComparator() { throw new IllegalStateException(); }8个特性值
ORDERED DISTINCT SORTED SIZED NONNULL IMMUTABLE CONCURRENT SUBSIZED //更多的是用在并发的时候,指定执行哪些内容。 我们再来看看Spliterator中的8种Characteristic /** * Characteristic value signifying that an encounter order is defined for * elements. If so, this Spliterator guarantees that method * {@link #trySplit} splits a strict prefix of elements, that method * {@link #tryAdvance} steps by one element in prefix order, and that * {@link #forEachRemaining} performs actions in encounter order. * * <p>A {@link Collection} has an encounter order if the corresponding * {@link Collection#iterator} documents an order. If so, the encounter * order is the same as the documented order. Otherwise, a collection does * not have an encounter order. * * @apiNote Encounter order is guaranteed to be ascending index order for * any {@link List}. But no order is guaranteed for hash-based collections * such as {@link HashSet}. Clients of a Spliterator that reports * {@code ORDERED} are expected to preserve ordering constraints in * non-commutative parallel computations. */ public static final int ORDERED = 0x00000010; /** * Characteristic value signifying that, for each pair of * encountered elements {@code x, y}, {@code !x.equals(y)}. This * applies for example, to a Spliterator based on a {@link Set}. */ public static final int DISTINCT = 0x00000001; /** * Characteristic value signifying that encounter order follows a defined * sort order. If so, method {@link #getComparator()} returns the associated * Comparator, or {@code null} if all elements are {@link Comparable} and * are sorted by their natural ordering. * * <p>A Spliterator that reports {@code SORTED} must also report * {@code ORDERED}. * * @apiNote The spliterators for {@code Collection} classes in the JDK that * implement {@link NavigableSet} or {@link SortedSet} report {@code SORTED}. */ public static final int SORTED = 0x00000004; /** * Characteristic value signifying that the value returned from * {@code estimateSize()} prior to traversal or splitting represents a * finite size that, in the absence of structural source modification, * represents an exact count of the number of elements that would be * encountered by a complete traversal. 在执行遍历或者分割之前,由estimateSize返回的值,表示一个有序的大小。 表示元素的数量的精确的值。 * * @apiNote Most Spliterators for Collections, that cover all elements of a * {@code Collection} report this characteristic. Sub-spliterators, such as * those for {@link HashSet}, that cover a sub-set of elements and * approximate their reported size do not. 大部分对于Collections的分割迭代器,一般都会有这个特性值。 */ public static final int SIZED = 0x00000040; /** * Characteristic value signifying that the source guarantees that * encountered elements will not be {@code null}. (This applies, * for example, to most concurrent collections, queues, and maps.) */ public static final int NONNULL = 0x00000100; /** * Characteristic value signifying that the element source cannot be * structurally modified; that is, elements cannot be added, replaced, or * removed, so such changes cannot occur during traversal. A Spliterator * that does not report {@code IMMUTABLE} or {@code CONCURRENT} is expected * to have a documented policy (for example throwing * {@link ConcurrentModificationException}) concerning structural * interference detected during traversal. 指定元素的源是不能被修改的,不能被(be added, replaced, or removed)。 在执行的时候,如果发现被修改,没有返回,则会抛出ConcurrentModificationException并发修改异常。 */ public static final int IMMUTABLE = 0x00000400; /** * Characteristic value signifying that the element source may be safely * concurrently modified (allowing additions, replacements, and/or removals) * by multiple threads without external synchronization. If so, the * Spliterator is expected to have a documented policy concerning the impact * of modifications during traversal. 表示元素的源能够安全的被并发修改。允许 modified (allowing additions, replacements, and/or removals)。 不需要外部的同步化的操作。Spliterator的提供了允许被修改的策略。 * * <p>A top-level Spliterator should not report both {@code CONCURRENT} and * {@code SIZED}, since the finite size, if known, may change if the source * is concurrently modified during traversal. Such a Spliterator is * inconsistent and no guarantees can be made about any computation using * that Spliterator. Sub-spliterators may report {@code SIZED} if the * sub-split size is known and additions or removals to the source are not * reflected when traversing. 顶层的Spliterator 不应该同时返回:{@code CONCURRENT} and {@code SIZED}。 因为两者之间存在一定的矛盾性。 这个的Spliterator 是不一直到, 得到的Sub-spliterators 可能会返回SIZED。 * * @apiNote Most concurrent collections maintain a consistency policy * guaranteeing accuracy with respect to elements present at the point of * Spliterator construction, but possibly not reflecting subsequent * additions or removals. 大多是的这种并发性的集合,都会被维护一定的策略。 :原有的Spliterator ,不会去影响子的Spliterator */ public static final int CONCURRENT = 0x00001000; /** * Characteristic value signifying that all Spliterators resulting from * {@code trySplit()} will be both {@link #SIZED} and {@link #SUBSIZED}. * (This means that all child Spliterators, whether direct or indirect, will * be {@code SIZED}.) * * <p>A Spliterator that does not report {@code SIZED} as required by * {@code SUBSIZED} is inconsistent and no guarantees can be made about any * computation using that Spliterator. A Spliterator如果没有返回要求的SIZED。 是没有明确的保证的。 * * @apiNote Some spliterators, such as the top-level spliterator for an * approximately balanced binary tree, will report {@code SIZED} but not * {@code SUBSIZED}, since it is common to know the size of the entire tree * but not the exact sizes of subtrees. 有一些Spliterator。如二叉树的整个树的大小,我们得知总的数,但是不知道子的数。 */ public static final int SUBSIZED = 0x00004000;以上就是关于spliterator的interface所有内容。
Spliterator都支持哪些事情?上面的8个方法。就是具体功能的实现。
OfPrimitive