Class SparseArraySpliterator<E>

java.lang.Object
org.apache.jena.mem.SparseArraySpliterator<E>
Type Parameters:
E - the type of the array elements
All Implemented Interfaces:
Spliterator<E>

public class SparseArraySpliterator<E> extends Object implements Spliterator<E>
A spliterator for sparse arrays. This spliterator will iterate over the array skipping null entries. This spliterator supports splitting into sub-spliterators. The spliterator will check for concurrent modifications by invoking a Runnable before each action.
  • Constructor Details

    • SparseArraySpliterator

      public SparseArraySpliterator(E[] entries, int estimatedElementsCount, Runnable checkForConcurrentModification)
      Create a spliterator for the given array, with the given size.
      Parameters:
      entries - the array
      estimatedElementsCount - the estimated size
  • Method Details

    • tryAdvance

      public boolean tryAdvance(Consumer<? super E> 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.
      Specified by:
      tryAdvance in interface Spliterator<E>
      Parameters:
      action - The action
      Returns:
      false if no remaining elements existed upon entry to this method, else true.
      Throws:
      NullPointerException - if the specified action is null
    • forEachRemaining

      public 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. If this Spliterator is Spliterator.ORDERED, actions are performed in encounter order. Exceptions thrown by the action are relayed to the caller.
      Specified by:
      forEachRemaining in interface Spliterator<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 returns false. It should be overridden whenever possible.
    • trySplit

      public Spliterator<E> 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 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.

      Specified by:
      trySplit in interface Spliterator<E>
      Returns:
      a Spliterator covering some portion of the elements, or null 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 inefficient trySplit mechanics typically result in poor parallel performance.
    • estimateSize

      public long estimateSize()
      Returns an estimate of the number of elements that would be encountered by a forEachRemaining(java.util.function.Consumer<? super E>) traversal, or returns Long.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 is Spliterator.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 of trySplit().

      Specified by:
      estimateSize in interface Spliterator<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 from Spliterator.ORDERED, Spliterator.DISTINCT, Spliterator.SORTED, Spliterator.SIZED, Spliterator.NONNULL, Spliterator.IMMUTABLE, Spliterator.CONCURRENT, Spliterator.SUBSIZED. Repeated calls to characteristics() on a given spliterator, prior to or in-between calls to trySplit, 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 interface Spliterator<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 and Spliterator.CONCURRENT.