- Type Parameters:
E-
- All Implemented Interfaces:
Spliterator<E>
Runnable
before each action.-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.Spliterator
Spliterator.OfDouble, Spliterator.OfInt, Spliterator.OfLong, Spliterator.OfPrimitive<T extends Object,T_CONS extends Object, T_SPLITR extends Spliterator.OfPrimitive<T, T_CONS, T_SPLITR>> -
Field Summary
Fields inherited from interface java.util.Spliterator
CONCURRENT, DISTINCT, IMMUTABLE, NONNULL, ORDERED, SIZED, SORTED, SUBSIZED -
Constructor Summary
ConstructorsConstructorDescriptionSparseArraySubSpliterator(E[] entries, int fromIndex, int toIndex, float fillRatio, Runnable checkForConcurrentModification) Create a spliterator for the given array, with the given size.SparseArraySubSpliterator(E[] entries, int estimatedElementsCount, Runnable checkForConcurrentModification) Create a spliterator for the given array, with the given size. -
Method Summary
Modifier and TypeMethodDescriptionintReturns a set of characteristics of this Spliterator and its elements.longReturns an estimate of the number of elements that would be encountered by aforEachRemaining(java.util.function.Consumer<? super E>)traversal, or returnsLong.MAX_VALUEif infinite, unknown, or too expensive to compute.voidforEachRemaining(Consumer<? super E> action) Performs the given action for each remaining element, sequentially in the current thread, until all elements have been processed or the action throws an exception.booleantryAdvance(Consumer<? super E> action) If a remaining element exists, performs the given action on it, returningtrue; else returnsfalse.trySplit()If this spliterator can be partitioned, returns a Spliterator covering elements, that will, upon return from this method, not be covered by this Spliterator.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Spliterator
getComparator, getExactSizeIfKnown, hasCharacteristics
-
Constructor Details
-
SparseArraySubSpliterator
public SparseArraySubSpliterator(E[] entries, int fromIndex, int toIndex, float fillRatio, Runnable checkForConcurrentModification) Create a spliterator for the given array, with the given size.- Parameters:
entries- the arrayfromIndex- the index of the first element, inclusivetoIndex- the index of the last element, exclusivefillRatio- the ratio of elements containing nullcheckForConcurrentModification-
-
SparseArraySubSpliterator
public SparseArraySubSpliterator(E[] entries, int estimatedElementsCount, Runnable checkForConcurrentModification) Create a spliterator for the given array, with the given size.- Parameters:
entries- the arrayestimatedElementsCount- the estimated size
-
-
Method Details
-
tryAdvance
If a remaining element exists, performs the given action on it, returningtrue; else returnsfalse. If this Spliterator isSpliterator.ORDEREDthe action is performed on the next element in encounter order. Exceptions thrown by the action are relayed to the caller.- Specified by:
tryAdvancein interfaceSpliterator<E>- Parameters:
action- The action- Returns:
falseif no remaining elements existed upon entry to this method, elsetrue.- Throws:
NullPointerException- if the specified action is null
-
forEachRemaining
Performs the given action for each remaining element, sequentially in the current thread, until all elements have been processed or the action throws an exception. If this Spliterator isSpliterator.ORDERED, actions are performed in encounter order. Exceptions thrown by the action are relayed to the caller.- Specified by:
forEachRemainingin interfaceSpliterator<E>- Parameters:
action- The action- Throws:
NullPointerException- if the specified action is null- Implementation Requirements:
- The default implementation repeatedly invokes
tryAdvance(java.util.function.Consumer<? super E>)until it returnsfalse. It should be overridden whenever possible.
-
trySplit
If this spliterator can be partitioned, returns a Spliterator covering elements, that will, upon return from this method, not be covered by this Spliterator.If this Spliterator is
Spliterator.ORDERED, the returned Spliterator must cover a strict prefix of the elements.Unless this Spliterator covers an infinite number of elements, repeated calls to
trySplit()must eventually returnnull. Upon non-null return:- the value reported for
estimateSize()before splitting, must, after splitting, be greater than or equal toestimateSize()for this and the returned Spliterator; and - if this Spliterator is
SUBSIZED, thenestimateSize()for this spliterator before splitting must be equal to the sum ofestimateSize()for this and the returned Spliterator after splitting.
This method may return
nullfor any reason, including emptiness, inability to split after traversal has commenced, data structure constraints, and efficiency considerations.- Specified by:
trySplitin interfaceSpliterator<E>- Returns:
- a
Spliteratorcovering some portion of the elements, ornullif this spliterator cannot be split - API Note:
- An ideal
trySplitmethod efficiently (without traversal) divides its elements exactly in half, allowing balanced parallel computation. Many departures from this ideal remain highly effective; for example, only approximately splitting an approximately balanced tree, or for a tree in which leaf nodes may contain either one or two elements, failing to further split these nodes. However, large deviations in balance and/or overly inefficienttrySplitmechanics typically result in poor parallel performance.
- the value reported for
-
estimateSize
public long estimateSize()Returns an estimate of the number of elements that would be encountered by aforEachRemaining(java.util.function.Consumer<? super E>)traversal, or returnsLong.MAX_VALUEif infinite, unknown, or too expensive to compute.If this Spliterator is
Spliterator.SIZEDand has not yet been partially traversed or split, or this Spliterator isSpliterator.SUBSIZEDand has not yet been partially traversed, this estimate must be an accurate count of elements that would be encountered by a complete traversal. Otherwise, this estimate may be arbitrarily inaccurate, but must decrease as specified across invocations oftrySplit().- Specified by:
estimateSizein interfaceSpliterator<E>- Returns:
- the estimated size, or
Long.MAX_VALUEif infinite, unknown, or too expensive to compute. - API Note:
- Even an inexact estimate is often useful and inexpensive to compute. For example, a sub-spliterator of an approximately balanced binary tree may return a value that estimates the number of elements to be half of that of its parent; if the root Spliterator does not maintain an accurate count, it could estimate size to be the power of two corresponding to its maximum depth.
-
characteristics
public int characteristics()Returns a set of characteristics of this Spliterator and its elements. The result is represented as ORed values fromSpliterator.ORDERED,Spliterator.DISTINCT,Spliterator.SORTED,Spliterator.SIZED,Spliterator.NONNULL,Spliterator.IMMUTABLE,Spliterator.CONCURRENT,Spliterator.SUBSIZED. Repeated calls tocharacteristics()on a given spliterator, prior to or in-between calls totrySplit, should always return the same result.If a Spliterator reports an inconsistent set of characteristics (either those returned from a single invocation or across multiple invocations), no guarantees can be made about any computation using this Spliterator.
- Specified by:
characteristicsin interfaceSpliterator<E>- Returns:
- a representation of characteristics
- API Note:
- The characteristics of a given spliterator before splitting may
differ from the characteristics after splitting. For specific examples see
the characteristic values
Spliterator.SIZED,Spliterator.SUBSIZEDandSpliterator.CONCURRENT.
-