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 class
A 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,
T_CONS, T_SPLITR extends Spliterator.OfPrimitive<T, T_CONS, T_SPLITR>> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final long
A 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 thecurrent
field, ornull
if 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 int
Index of the next element to return from thecurrent
array.private double[]
A pre-allocated buffer where to store point coordinates, ornull
if not needed.private NodeIterator.Cursor
<E> A cursor that can be recycled, ornull
if 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 TypeMethodDescriptionint
Returns a set of characteristics of this iterator and its elements.long
Returns an estimate of the number of elements orLong.MAX_VALUE
if too expensive to compute.protected boolean
Returns whether the given element is included in the search region.private Object[]
next()
Returns an array of elements that may intersect the search region, orFINISHED
if the iteration is finished.private boolean
postClone
(long quadrants) Invoked afterObject.clone()
for copying the fields that cannot be shared between twoNodeIterator
instances.final boolean
tryAdvance
(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, wait
Methods 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.quadrants
before 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, ornull
if not needed. -
cursor
The object to use for updating thecurrent
field, ornull
if none. ThisNodeIterator
starts by returning elements in thecurrent
array. When iteration overcurrent
array is finished,NodeIterator
uses theNodeIterator.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
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 thecurrent
array. -
recycle
A cursor that can be recycled, ornull
if none. Used for reducing the number ofNodeIterator.Cursor
allocations 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 twoNodeIterator
instances. 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, orFINISHED
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
If a remaining element exists, performs the given action on it and returnstrue
. Otherwise returnsfalse
.- Specified by:
tryAdvance
in interfaceSpliterator<E>
- Parameters:
action
- the action to execute on the next element.- Returns:
false
if 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:
trySplit
in interfaceSpliterator<E>
-
estimateSize
public long estimateSize()Returns an estimate of the number of elements orLong.MAX_VALUE
if too expensive to compute.- Specified by:
estimateSize
in interfaceSpliterator<E>
-
characteristics
public int characteristics()Returns a set of characteristics of this iterator and its elements.- Specified by:
characteristics
in interfaceSpliterator<E>
-