Package org.apache.sis.index.tree
Class NodeIterator<E>
java.lang.Object
org.apache.sis.index.tree.NodeIterator<E>
- Type Parameters:
E- the type of elements stored in thePointTree.
- All Implemented Interfaces:
Cloneable,Spliterator<E>
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classA provider for arrays of elements of child nodes contained in aPointTreeNode.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
FieldsModifier and TypeFieldDescriptionprivate final longA mask with a bit set for all quadrants.private final double[]The region on which to iterate.private Object[]The elements for a current quadrant/octant in current node.private NodeIterator.Cursor<E>The object to use for updating thecurrentfield, ornullif none.private static final Object[]Sentinel value meaning that iteration is over.private final PointTree.Locator<? super E>The function computing a position for an arbitrary element of the tree.private intIndex of the next element to return from thecurrentarray.private double[]A pre-allocated buffer where to store point coordinates, ornullif not needed.private NodeIterator.Cursor<E>A cursor that can be recycled, ornullif none.Fields inherited from interface java.util.Spliterator
CONCURRENT, DISTINCT, IMMUTABLE, NONNULL, ORDERED, SIZED, SORTED, SUBSIZED -
Constructor Summary
ConstructorsConstructorDescriptionNodeIterator(PointTree<E> tree, org.opengis.geometry.Envelope searchRegion) Creates a new iterator for the specified search region. -
Method Summary
Modifier and TypeMethodDescriptionintReturns a set of characteristics of this iterator and its elements.longReturns an estimate of the number of elements orLong.MAX_VALUEif too expensive to compute.protected booleanReturns whether the given element is included in the search region.private Object[]next()Returns an array of elements that may intersect the search region, orFINISHEDif the iteration is finished.private booleanpostClone(long quadrants) Invoked afterObject.clone()for copying the fields that cannot be shared between twoNodeIteratorinstances.final booleantryAdvance(Consumer<? super E> action) If a remaining element exists, performs the given action on it and returnstrue.final Spliterator<E>trySplit()If this iterator can be partitioned, returns an iterator covering about half of the elements.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Spliterator
forEachRemaining, getComparator, getExactSizeIfKnown, hasCharacteristics
-
Field Details
-
FINISHED
Sentinel value meaning that iteration is over. -
locator
The function computing a position for an arbitrary element of the tree. -
bitmask
private final long bitmaskA mask with a bit set for all quadrants. This is used as the initial value ofNodeIterator.Cursor.quadrantsbefore to clear to bits of quadrants to not search. -
bounds
private final double[] boundsThe 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[] pointA pre-allocated buffer where to store point coordinates, ornullif not needed. -
cursor
The object to use for updating thecurrentfield, ornullif none. ThisNodeIteratorstarts by returning elements in thecurrentarray. When iteration overcurrentarray is finished,NodeIteratoruses theNodeIterator.Cursorfor changing the array reference to the next array. The iteration then continues until all leaf nodes intersecting the search region have been traversed. -
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 nextIndexIndex of the next element to return from thecurrentarray. -
recycle
A cursor that can be recycled, ornullif none. Used for reducing the number ofNodeIterator.Cursorallocations during tree traversal.
-
-
Constructor Details
-
NodeIterator
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 afterObject.clone()for copying the fields that cannot be shared between twoNodeIteratorinstances. This is used fortrySplit()implementation.- Parameters:
quadrants- the value to assign toNodeIterator.Cursor.quadrants. That bitmask shall not intersect the bitmask ofother.cursor.- Returns:
- whether this iterator has to data to iterate.
-
next
Returns an array of elements that may intersect the search region, orFINISHEDif 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
FINISHEDif the iteration is finished.
-
tryAdvance
If a remaining element exists, performs the given action on it and returnstrue. Otherwise returnsfalse.- Specified by:
tryAdvancein interfaceSpliterator<E>- Parameters:
action- the action to execute on the next element.- Returns:
falseif no remaining elements exist.
-
filter
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
If this iterator can be partitioned, returns an iterator covering about half of the elements. Otherwise returnsnull.- Specified by:
trySplitin interfaceSpliterator<E>
-
estimateSize
public long estimateSize()Returns an estimate of the number of elements orLong.MAX_VALUEif too expensive to compute.- Specified by:
estimateSizein interfaceSpliterator<E>
-
characteristics
public int characteristics()Returns a set of characteristics of this iterator and its elements.- Specified by:
characteristicsin interfaceSpliterator<E>
-