Spliterator.OfPrimitive

public static interface Spliterator.OfPrimitive
implements Spliterator<T>

java.util.Spliterator.OfPrimitive<T, T_CONS, T_SPLITR extends java.util.Spliterator.OfPrimitive<T, T_CONS, T_SPLITR>>
Spliterator.OfDouble A Spliterator specialized for double values. 
Spliterator.OfInt A Spliterator specialized for int values. 
Spliterator.OfLong A Spliterator specialized for long values. 
Spliterators.AbstractDoubleSpliterator An abstract Spliterator.OfDouble that implements trySplit to permit limited parallelism. 
Spliterators.AbstractIntSpliterator An abstract Spliterator.OfInt that implements trySplit to permit limited parallelism. 
Spliterators.AbstractLongSpliterator An abstract Spliterator.OfLong that implements trySplit to permit limited parallelism. 


A Spliterator specialized for primitive values.

Summary

Inherited constants

int CONCURRENT

Characteristic value signifying that the element source may be safely concurrently modified (allowing additions, replacements, and/or removals) by multiple threads without external synchronization.

int DISTINCT

Characteristic value signifying that, for each pair of encountered elements x, y, !x.equals(y).

int IMMUTABLE

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.

int NONNULL

Characteristic value signifying that the source guarantees that encountered elements will not be null.

int ORDERED

Characteristic value signifying that an encounter order is defined for elements.

int SIZED

Characteristic value signifying that the value returned from 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.

int SORTED

Characteristic value signifying that encounter order follows a defined sort order.

int SUBSIZED

Characteristic value signifying that all Spliterators resulting from trySplit() will be both SIZED and SUBSIZED.

Public methods

default void forEachRemaining(T_CONS 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.

abstract boolean tryAdvance(T_CONS action)

If a remaining element exists, performs the given action on it, returning true; else returns false.

abstract T_SPLITR 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.

Inherited methods

abstract int characteristics()

Returns a set of characteristics of this Spliterator and its elements.

abstract long estimateSize()

Returns an estimate of the number of elements that would be encountered by a forEachRemaining(Consumer) traversal, or returns Long.MAX_VALUE if infinite, unknown, or too expensive to compute.

default void forEachRemaining(Consumer<? super T> 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.

default Comparator<? super T> getComparator()

If this Spliterator's source is SORTED by a Comparator, returns that Comparator.

default long getExactSizeIfKnown()

Convenience method that returns estimateSize() if this Spliterator is SIZED, else -1.

default boolean hasCharacteristics(int characteristics)

Returns true if this Spliterator's characteristics() contain all of the given characteristics.

abstract boolean tryAdvance(Consumer<? super T> action)

If a remaining element exists: performs the given action on it, returning true; else returns false.

abstract Spliterator<T> 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.

Public methods

forEachRemaining

Added in API level 24
public void forEachRemaining (T_CONS 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. If this Spliterator is Spliterator.ORDERED, actions are performed in encounter order. Exceptions thrown by the action are relayed to the caller.

Subsequent behavior of a spliterator is unspecified if the action throws an exception.

Implementation Requirements:
  • The default implementation repeatedly invokes tryAdvance(T_CONS) until it returns false. It should be overridden whenever possible.
Parameters
action T_CONS: The action

Throws
NullPointerException if the specified action is null

tryAdvance

Added in API level 24
public abstract boolean tryAdvance (T_CONS action)

If a remaining element exists, performs the given action on it, returning true; else returns false. If this Spliterator is Spliterator.ORDERED the action is performed on the next element in encounter order. Exceptions thrown by the action are relayed to the caller.

Subsequent behavior of a spliterator is unspecified if the action throws an exception.

Parameters
action T_CONS: The action

Returns
boolean false if no remaining elements existed upon entry to this method, else true.

Throws
NullPointerException if the specified action is null

trySplit

Added in API level 24
public abstract T_SPLITR 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 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 return null. Upon non-null return:

  • 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.

This method may return null for any reason, including emptiness, inability to split after traversal has commenced, data structure constraints, and efficiency considerations.

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