Class EmptyCursor<K,​V>

  • Type Parameters:
    K - Type of the simulated record's key
    V - Type of the simulated record's value
    All Implemented Interfaces:
    Closeable, AutoCloseable, Cursor<K,​V>, SequentialCursor<K,​V>

    public final class EmptyCursor<K,​V>
    extends Object
    implements Cursor<K,​V>
    Implementation of an empty Cursor, for simulating no records to cursor on.

    Cursor behaves as follows:

    • Positioning to a key or index will fail, returning false.
    • Reading the key or value will return null.
    • Deleting the current element is not supported, UnsupportedOperationException will be thrown.
    • Constructor Detail

      • EmptyCursor

        public EmptyCursor()
    • Method Detail

      • positionToKey

        public boolean positionToKey​(K key)
        Description copied from interface: Cursor
        Positions the cursor to the provided key if it exists in the tree.

        Positioning the cursor is required before calling SequentialCursor.isValid().

        Specified by:
        positionToKey in interface Cursor<K,​V>
        Parameters:
        key - the key where to position the cursor
        Returns:
        true if the cursor could be positioned to the key, false otherwise
      • positionToKeyOrNext

        public boolean positionToKeyOrNext​(K key)
        Description copied from interface: Cursor
        Positions the cursor to the provided key if it exists in the tree, or else the lesser key greater than the provided key in the tree.

        Positioning the cursor is required before calling SequentialCursor.isValid().

        Specified by:
        positionToKeyOrNext in interface Cursor<K,​V>
        Parameters:
        key - the key where to position the cursor
        Returns:
        true if the cursor could be positioned to the key or the next one, false otherwise
      • positionToLastKey

        public boolean positionToLastKey()
        Description copied from interface: Cursor
        Positions the cursor to the last key in the tree.

        Positioning the cursor is required before calling SequentialCursor.isValid().

        Specified by:
        positionToLastKey in interface Cursor<K,​V>
        Returns:
        true if the cursor could be positioned to the last key, false otherwise
      • positionToIndex

        public boolean positionToIndex​(int index)
        Description copied from interface: Cursor
        Positions the cursor to the specified index within the tree. Implementations may take advantage of optimizations provided by the underlying storage, such as counted B-Trees.

        Positioning the cursor is required before calling SequentialCursor.isValid().

        Specified by:
        positionToIndex in interface Cursor<K,​V>
        Parameters:
        index - the index where the cursor should be positioned, (0 is the first record).
        Returns:
        true if the cursor could be positioned to the index, false otherwise
      • previous

        public boolean previous()
        Description copied from interface: Cursor
        Moves this cursor to the previous record in the tree.
        Specified by:
        previous in interface Cursor<K,​V>
        Returns:
        true if the cursor has moved to the previous record, false if no next record exists leaving cursor in undefined state.
      • next

        public boolean next()
        Description copied from interface: SequentialCursor
        Moves this cursor to the next record in the tree.

        No data is available before calling next() on a new cursor.

        Specified by:
        next in interface SequentialCursor<K,​V>
        Returns:
        true if the cursor has moved to the next record, false if no next record exists leaving cursor in undefined state.
      • isValid

        public boolean isValid()
        Description copied from interface: SequentialCursor
        Check whether this cursor is currently pointing to a valid record.

        Before calling isValid() the cursor must be positioned by calling SequentialCursor.next().

        Specified by:
        isValid in interface SequentialCursor<K,​V>
        Returns:
        true if the cursor is pointing to a valid entry, false if cursor is not pointing to a valid entry