Package com.illumon.iris.db.v2.utils
Interface OrderedKeys.Iterator
- All Superinterfaces:
AutoCloseable
,SafeCloseable
- Enclosing interface:
- OrderedKeys
public static interface OrderedKeys.Iterator extends SafeCloseable
Iterator for consuming an
OrderedKeys
by ordered subsets.-
Field Summary
Fields Modifier and Type Field Description static OrderedKeys.Iterator
EMPTY
Immutable, re-usableOrderedKeys.Iterator
for an emptyOrderedKeys
. -
Method Summary
Modifier and Type Method Description boolean
advance(long nextKey)
Advance this iterator's position tonextKey
, or to the first present key greater thannextKey
ifnextKey
is not found.default long
advanceAndGetPositionDistance(long nextKey)
Advance this iterator's position as inadvance(long)
, returning the number of keys thus consumed.default void
close()
Free any resources associated with this iterator.OrderedKeys
getNextOrderedKeysThrough(long maxKeyInclusive)
Get anOrderedKeys
from the key at the position of this iterator up to the maximum key (inclusive).OrderedKeys
getNextOrderedKeysWithLength(long numberOfKeys)
Get anOrderedKeys
from the key at the position of this iterator up to the desired number of keys.long
getRelativePosition()
Taking the difference between values returned by this method at different positions in the iterator gives you the cardinality of the set of keys between them, exclusive.boolean
hasMore()
Poll whether there are more keys available from thisOrderedKeys.Iterator
.long
peekNextKey()
Peek at the next key that would be returned bygetNextOrderedKeysThrough(long)
orgetNextOrderedKeysWithLength(long)
.
-
Field Details
-
EMPTY
Immutable, re-usableOrderedKeys.Iterator
for an emptyOrderedKeys
.
-
-
Method Details
-
hasMore
boolean hasMore()Poll whether there are more keys available from thisOrderedKeys.Iterator
.- Returns:
- True if there are more keys available, else false
-
peekNextKey
long peekNextKey()Peek at the next key that would be returned bygetNextOrderedKeysThrough(long)
orgetNextOrderedKeysWithLength(long)
. Does not advance the position.- Returns:
- The next key that would be returned, or
ReadOnlyIndex.NULL_KEY
if this iterator is exhausted
-
getNextOrderedKeysThrough
Get anOrderedKeys
from the key at the position of this iterator up to the maximum key (inclusive). Advances the position of this iterator by the size of the result. If the maximum key provided is smaller than the next key (as would be returned bypeekNextKey()
), the empty OrderedKeys is returned. The returned OrderedKeys object is only borrowed by the caller from theOrderedKeys.Iterator
, who owns it. It is guaranteed to be valid and not change only until a later call to anothergetNext*
method. As the returned reference is owned by theOrderedKeys.Iterator
, the caller should not callclose()
on it.- Parameters:
maxKeyInclusive
- The maximum key to include.- Returns:
- An
OrderedKeys
from the key at the initial position up to the maximum key (inclusive).
-
getNextOrderedKeysWithLength
Get anOrderedKeys
from the key at the position of this iterator up to the desired number of keys. Advances the position of this iterator by the size of the result. The returned OrderedKeys object is only borrowed by the caller from theOrderedKeys.Iterator
, who owns it. It is guaranteed to be valid and not change only until the next call to anothergetNext*
method. As the returned reference is owned by theOrderedKeys.Iterator
, the caller should not callclose()
on it.- Parameters:
numberOfKeys
- The desired number of keys- Returns:
- An
OrderedKeys
from the key at the initial position up to the desired number of keys
-
advance
boolean advance(long nextKey)Advance this iterator's position to
nextKey
, or to the first present key greater thannextKey
ifnextKey
is not found. IfnextKey
is less than or equal to the key at this iterator's current position, this method is a no-op.Subsequent calls to
peekNextKey()
,getNextOrderedKeysThrough(long)
, orgetNextOrderedKeysWithLength(long)
will begin with the key advanced to.- Parameters:
nextKey
- The key to advance to- Returns:
- true If there are any keys remaining to be iterated after the advance, false if this
OrderedKeys.Iterator
is exhausted
-
advanceAndGetPositionDistance
default long advanceAndGetPositionDistance(long nextKey)Advance this iterator's position as inadvance(long)
, returning the number of keys thus consumed.- Parameters:
nextKey
- The key to advance to- Returns:
- The number of keys consumed from the iterator
-
close
default void close()Free any resources associated with this iterator.
Callers of
OrderedKeys.getOrderedKeysIterator()
are responsible for ensuring thatclose()
is called when they are done with resultingOrderedKeys.Iterator
.Using any
OrderedKeys.Iterator
methods afterclose()
is an error and may produce exceptions or undefined results.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceSafeCloseable
-
getRelativePosition
long getRelativePosition()Taking the difference between values returned by this method at different positions in the iterator gives you the cardinality of the set of keys between them, exclusive. Note a single value itself is not meaningful; like measuring elapsed time, it only makes sense to take the difference from absolute points.- Returns:
- A relative position offset from some arbitrary initial point in the underlying ordered keys.
-