- Type Parameters:
E
- the type of the array elements
- 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
ConstructorDescriptionSparseArraySpliterator
(E[] entries, int estimatedElementsCount, Runnable checkForConcurrentModification) Create a spliterator for the given array, with the given size. -
Method Summary
Modifier and TypeMethodDescriptionint
Returns a set of characteristics of this Spliterator and its elements.long
Returns an estimate of the number of elements that would be encountered by aforEachRemaining(java.util.function.Consumer<? super E>)
traversal, or returnsLong.MAX_VALUE
if infinite, unknown, or too expensive to compute.void
forEachRemaining
(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.boolean
tryAdvance
(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, wait
Methods inherited from interface java.util.Spliterator
getComparator, getExactSizeIfKnown, hasCharacteristics
-
Constructor Details
-
Method Details
-
tryAdvance
If a remaining element exists, performs the given action on it, returningtrue
; else returnsfalse
. If this Spliterator isSpliterator.ORDERED
the action is performed on the next element in encounter order. Exceptions thrown by the action are relayed to the caller.- Specified by:
tryAdvance
in interfaceSpliterator<E>
- Parameters:
action
- The action- Returns:
false
if 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:
forEachRemaining
in 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
null
for any reason, including emptiness, inability to split after traversal has commenced, data structure constraints, and efficiency considerations.- Specified by:
trySplit
in interfaceSpliterator<E>
- Returns:
- a
Spliterator
covering some portion of the elements, ornull
if this spliterator cannot be split - API Note:
- An ideal
trySplit
method 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 inefficienttrySplit
mechanics 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_VALUE
if infinite, unknown, or too expensive to compute.If this Spliterator is
Spliterator.SIZED
and has not yet been partially traversed or split, or this Spliterator isSpliterator.SUBSIZED
and 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:
estimateSize
in interfaceSpliterator<E>
- Returns:
- the estimated size, or
Long.MAX_VALUE
if 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:
characteristics
in 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.SUBSIZED
andSpliterator.CONCURRENT
.
-