Package com.google.common.geometry
Class S2CellIndex.ContentsIterator
- java.lang.Object
-
- com.google.common.geometry.S2CellIndex.ContentsIterator
-
- Enclosing class:
- S2CellIndex
public class S2CellIndex.ContentsIterator extends java.lang.ObjectAn iterator that visits the (cellId, label) pairs that cover a set of leaf cell ranges (see RangeIterator). To use it, construct an instance orclear()an existing instance, andstartUnion(com.google.common.geometry.S2CellIndex.RangeIterator)to visit the contents of each desired leaf cell range.Note that when multiple leaf cell ranges are visited, this class only guarantees that each result will be reported at least once, i.e. duplicate values may be suppressed. If you want duplicate values to be reported again, be sure to call
clear()first.In particular, the implementation guarantees that when multiple leaf cell ranges are visited in monotonically increasing order, then each (cellId, label) pair is reported exactly once.
-
-
Field Summary
Fields Modifier and Type Field Description private static intDONEA special label indicating thatdone()is true.private intnextNodeCutoffThe maximum index withinS2CellIndex.cellNodesvisited during the current call to startUnion().private S2CellIndex.CellNodenodeA copy of the current node in the cell tree.private intnodeCutoffThe maximum index withinS2CellIndex.cellNodesvisited during the previous call to startUnion().private S2CellIdprevStartIdThe value of it.startId() from the previous call to startUnion().
-
Constructor Summary
Constructors Modifier Constructor Description privateContentsIterator()Creates a new iterator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description S2CellIdcellId()Returns the S2CellId of the current (cellId, label) pair.voidclear()Clears all state with respect to which range(s) have been visited.booleandone()Returns true if all (cellId, label) pairs have been visited.intlabel()Returns the label of the current (cellId, label) pair.voidnext()Advances the iterator to the next (cellId, label) pair covered by the current leaf cell range.private voidsetDone()Sets the current node label to DONE to indicate that iteration has finished.voidstartUnion(S2CellIndex.RangeIterator range)Positions the ContentsIterator at the first (cellId, label) pair that covers the given leaf cell range.
-
-
-
Field Detail
-
DONE
private static final int DONE
A special label indicating thatdone()is true.- See Also:
- Constant Field Values
-
prevStartId
private S2CellId prevStartId
The value of it.startId() from the previous call to startUnion(). This is used to check whether these values are monotonically increasing.
-
nodeCutoff
private int nodeCutoff
The maximum index withinS2CellIndex.cellNodesvisited during the previous call to startUnion(). This is used to eliminate duplicate values when startUnion() is called multiple times.
-
nextNodeCutoff
private int nextNodeCutoff
The maximum index withinS2CellIndex.cellNodesvisited during the current call to startUnion(). This is used to update nodeCutoff.
-
node
private final S2CellIndex.CellNode node
A copy of the current node in the cell tree.
-
-
Constructor Detail
-
ContentsIterator
private ContentsIterator()
Creates a new iterator. CallstartUnion(com.google.common.geometry.S2CellIndex.RangeIterator)next.
-
-
Method Detail
-
clear
public void clear()
Clears all state with respect to which range(s) have been visited.
-
startUnion
public void startUnion(S2CellIndex.RangeIterator range)
Positions the ContentsIterator at the first (cellId, label) pair that covers the given leaf cell range. Note that when multiple leaf cell ranges are visited using the same ContentsIterator, duplicate values may be suppressed. If you don't want this behavior, call clear() first.
-
cellId
public S2CellId cellId()
Returns the S2CellId of the current (cellId, label) pair.
-
label
public int label()
Returns the label of the current (cellId, label) pair.
-
done
public boolean done()
Returns true if all (cellId, label) pairs have been visited.
-
next
public void next()
Advances the iterator to the next (cellId, label) pair covered by the current leaf cell range.
-
setDone
private void setDone()
Sets the current node label to DONE to indicate that iteration has finished.
-
-