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 Details

  • Method Details

    • hasMore

      boolean hasMore()
      Poll whether there are more keys available from this OrderedKeys.Iterator.
      Returns:
      True if there are more keys available, else false
    • peekNextKey

      long peekNextKey()
      Peek at the next key that would be returned by getNextOrderedKeysThrough(long) or getNextOrderedKeysWithLength(long). Does not advance the position.
      Returns:
      The next key that would be returned, or ReadOnlyIndex.NULL_KEY if this iterator is exhausted
    • getNextOrderedKeysThrough

      OrderedKeys getNextOrderedKeysThrough​(long maxKeyInclusive)
      Get an OrderedKeys 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 by peekNextKey()), the empty OrderedKeys is returned. The returned OrderedKeys object is only borrowed by the caller from the OrderedKeys.Iterator, who owns it. It is guaranteed to be valid and not change only until a later call to another getNext* method. As the returned reference is owned by the OrderedKeys.Iterator, the caller should not call close() 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

      OrderedKeys getNextOrderedKeysWithLength​(long numberOfKeys)
      Get an OrderedKeys 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 the OrderedKeys.Iterator, who owns it. It is guaranteed to be valid and not change only until the next call to another getNext* method. As the returned reference is owned by the OrderedKeys.Iterator, the caller should not call close() 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 than nextKey if nextKey is not found. If nextKey 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), or getNextOrderedKeysWithLength(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 in advance(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 that close() is called when they are done with resulting OrderedKeys.Iterator.

      Using any OrderedKeys.Iterator methods after close() is an error and may produce exceptions or undefined results.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface SafeCloseable
    • 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.