Package com.google.common.geometry
Class S2Iterator<T extends S2Iterator.Entry>
java.lang.Object
com.google.common.geometry.S2Iterator<T>
A random access iterator that provides low-level access to entries sorted by cell ID. The
behavior of this iterator is more like a database cursor, where accessing properties at the
current position does not alter the position of the cursor. The cursor has a
compareTo(com.google.common.geometry.S2CellId)
method to compare the value at the current position of the iterator with a given S2CellId.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAn interface to provide the cell ID for an element in a sorted list. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedS2Iterator(List<T> entries) Create a new iterator based on the given list of entries.protectedS2Iterator(List<T> entries, com.google.common.base.Function<S2CellId, Integer> seekFunction) Same asS2Iterator(List), but acceptsseekFunction, which is used as the implementation ofseek(S2CellId). -
Method Summary
Modifier and TypeMethodDescriptionbooleanatBegin()Returns true if the iterator is positioned at the first index cell.center()Returns the center of the cell (used as a reference point for shape interiors.)intReturns the comparison from the current iterator cell to the given cell ID.copy()Returns a copy of this iterator, positioned as this iterator is.(package private) static <T extends S2Iterator.Entry>
S2Iterator<T> copy(S2Iterator<T> it) Creates a new iterator with the same entries and position asit.(package private) static <T extends S2Iterator.Entry>
S2Iterator<T> Creates an iterator given a list of entries.(package private) static <T extends S2Iterator.Entry>
S2Iterator<T> Same ascreate(List), but acceptsseekFunction, which is used as the implementation ofseek(S2CellId).booleandone()Returns true if the iterator is positioned past the last index cell.entry()Returns the current entry.<T extends S2Iterator.Entry>
booleanequalIterators(S2Iterator<T> it) Returns true if these iterators have the same entries and position.booleanReturns true ifois anS2Iteratorwith equal entries and position.voidfinish()Positions the iterator so thatdone()is true.inthashCode()id()Returns the cell id for the current cell.Positions the iterator at the index cell containing the given cell, if possible, and returns theS2ShapeIndex.CellRelationthat describes the relationship between the index and the given target cell: ReturnsS2ShapeIndex.CellRelation.INDEXEDif the iterator was positioned at an index cell that is equal to or contains the given cell.booleanPositions the iterator at the index cell containing "target" and returns true, or if no such cell exists in the index, the iterator is positioned arbitrarily and this method returns false.voidnext()Advances the iterator to the next cell in the index.voidposition(S2Iterator<T> it) Set this iterator to the position given by the other iterator.voidprev()Positions the iterator at the previous cell in the index.voidrestart()Positions the iterator so thatatBegin()is true.voidPositions the iterator at the first cell with id() >= target, or at the end of the index if no such cell exists.voidseekForward(S2CellId target) Advances the iterator to the next cell with id() >= target.
-
Field Details
-
entries
-
seekFunction
-
pos
protected int pos
-
-
Constructor Details
-
S2Iterator
Create a new iterator based on the given list of entries. Results are undefined if the entries are not in ascending sorted order.- Parameters:
entries- the list of entries which back this iterator.
-
S2Iterator
protected S2Iterator(List<T> entries, com.google.common.base.Function<S2CellId, Integer> seekFunction) Same asS2Iterator(List), but acceptsseekFunction, which is used as the implementation ofseek(S2CellId).- Parameters:
entries- the list of entries which back this iterator.seekFunction- a function which takes a targetS2CellIdand returns an index to which this iterator will be repositioned.
-
-
Method Details
-
create
Creates an iterator given a list of entries. Package private and not public, since only S2 classes guarantee the necessary preconditions onentries-- that the cell IDs of each entry are sorted in ascending order. -
create
static <T extends S2Iterator.Entry> S2Iterator<T> create(List<T> entries, com.google.common.base.Function<S2CellId, Integer> seekFunction) Same ascreate(List), but acceptsseekFunction, which is used as the implementation ofseek(S2CellId).- Parameters:
entries- the list of entries which back this iterator.seekFunction- a function which takes a targetS2CellIdand returns an index to which this iterator will be repositioned.
-
copy
Creates a new iterator with the same entries and position asit. -
copy
Returns a copy of this iterator, positioned as this iterator is. -
restart
public void restart()Positions the iterator so thatatBegin()is true. -
compareTo
Returns the comparison from the current iterator cell to the given cell ID. -
equals
Returns true ifois anS2Iteratorwith equal entries and position. -
hashCode
public int hashCode() -
equalIterators
Returns true if these iterators have the same entries and position. -
id
Returns the cell id for the current cell. -
entry
Returns the current entry. -
center
Returns the center of the cell (used as a reference point for shape interiors.) -
next
public void next()Advances the iterator to the next cell in the index. Does not advance the iterator ifposis equal to the number of cells in the index. -
prev
public void prev()Positions the iterator at the previous cell in the index. Does not move the iterator ifposis equal to 0. -
done
public boolean done()Returns true if the iterator is positioned past the last index cell. -
atBegin
public boolean atBegin()Returns true if the iterator is positioned at the first index cell. -
seek
Positions the iterator at the first cell with id() >= target, or at the end of the index if no such cell exists. -
seekForward
Advances the iterator to the next cell with id() >= target. If the iterator isdone()or already satisfies id() >= target, there is no effect. -
finish
public void finish()Positions the iterator so thatdone()is true. -
locate
Positions the iterator at the index cell containing "target" and returns true, or if no such cell exists in the index, the iterator is positioned arbitrarily and this method returns false.The resulting index position is guaranteed to contain all edges that might intersect the line segment between
targetPointandcenter(). -
locate
Positions the iterator at the index cell containing the given cell, if possible, and returns theS2ShapeIndex.CellRelationthat describes the relationship between the index and the given target cell:- Returns
S2ShapeIndex.CellRelation.INDEXEDif the iterator was positioned at an index cell that is equal to or contains the given cell. I.e. the given target exists in the index as a leaf cell. - Returns
S2ShapeIndex.CellRelation.SUBDIVIDEDif the iterator was positioned at the first of one or more cells contained by the given target cell. I.e. the target does not exist in the index, but the first of its descendants was selected. - Returns
S2ShapeIndex.CellRelation.DISJOINTif the iterator had to be positioned arbitrarily because the given target cell does not intersect any of the index's cells.
- Returns
-
position
Set this iterator to the position given by the other iterator.
-