Class NodeIterator<E>

java.lang.Object
org.apache.sis.index.tree.NodeIterator<E>
Type Parameters:
E - the type of elements stored in the PointTree.
All Implemented Interfaces:
Cloneable, Spliterator<E>

class NodeIterator<E> extends Object implements Spliterator<E>, Cloneable
An iterator over the elements contained in a PointTreeNode. The iterator applies a first filtering of elements by traversing only the nodes that may intersect the Area Of Interest (AOI). But after a node has been retained, an additional check for inclusion may be necessary. That additional check is performed by filter(Object) and can be overridden by subclasses.
Since:
1.1
Version:
1.1
  • Field Details

    • FINISHED

      private static final Object[] FINISHED
      Sentinel value meaning that iteration is over.
    • locator

      private final PointTree.Locator<? super E> locator
      The function computing a position for an arbitrary element of the tree.
    • bitmask

      private final long bitmask
      A mask with a bit set for all quadrants. This is used as the initial value of NodeIterator.Cursor.quadrants before to clear to bits of quadrants to not search.
    • bounds

      private final double[] bounds
      The region on which to iterate. The first half are minimal coordinates and the second half are maximal coordinates. The content of this array should not be modified.
    • point

      private double[] point
      A pre-allocated buffer where to store point coordinates, or null if not needed.
    • cursor

      private NodeIterator.Cursor<E> cursor
      The object to use for updating the current field, or null if none. This NodeIterator starts by returning elements in the current array. When iteration over current array is finished, NodeIterator uses the NodeIterator.Cursor for changing the array reference to the next array. The iteration then continues until all leaf nodes intersecting the search region have been traversed.
    • current

      private Object[] current
      The elements for a current quadrant/octant in current node. After iteration over this array is finished, this field is updated with elements for next quadrant/octant until all nodes have been traversed.
    • nextIndex

      private int nextIndex
      Index of the next element to return from the current array.
    • recycle

      private NodeIterator.Cursor<E> recycle
      A cursor that can be recycled, or null if none. Used for reducing the number of NodeIterator.Cursor allocations during tree traversal.
  • Constructor Details

    • NodeIterator

      NodeIterator(PointTree<E> tree, org.opengis.geometry.Envelope searchRegion)
      Creates a new iterator for the specified search region. If the given region is null, then infinite bounds are assumed.
  • Method Details

    • postClone

      private boolean postClone(long quadrants)
      Invoked after Object.clone() for copying the fields that cannot be shared between two NodeIterator instances. This is used for trySplit() implementation.
      Parameters:
      quadrants - the value to assign to NodeIterator.Cursor.quadrants. That bitmask shall not intersect the bitmask of other.cursor.
      Returns:
      whether this iterator has to data to iterate.
    • next

      private Object[] next()
      Returns an array of elements that may intersect the search region, or FINISHED if the iteration is finished. This method does not verify if the points are really in the search region; callers may need to filter the returned array.
      Returns:
      array of elements that may be in the search region, or FINISHED if the iteration is finished.
    • tryAdvance

      public final boolean tryAdvance(Consumer<? super E> action)
      If a remaining element exists, performs the given action on it and returns true. Otherwise returns false.
      Specified by:
      tryAdvance in interface Spliterator<E>
      Parameters:
      action - the action to execute on the next element.
      Returns:
      false if no remaining elements exist.
    • filter

      protected boolean filter(E element)
      Returns whether the given element is included in the search region. The default implementation verifies if the point is included in the bounding box. Subclasses may override, for example for restricting the points to a radius around a central location.
      Parameters:
      element - the element to check for inclusion.
      Returns:
      whether the element is in the search region.
    • trySplit

      public final Spliterator<E> trySplit()
      If this iterator can be partitioned, returns an iterator covering about half of the elements. Otherwise returns null.
      Specified by:
      trySplit in interface Spliterator<E>
    • estimateSize

      public long estimateSize()
      Returns an estimate of the number of elements or Long.MAX_VALUE if too expensive to compute.
      Specified by:
      estimateSize in interface Spliterator<E>
    • characteristics

      public int characteristics()
      Returns a set of characteristics of this iterator and its elements.
      Specified by:
      characteristics in interface Spliterator<E>