Class EmptyCursor<K,V>
- java.lang.Object
-
- org.opends.server.backends.pluggable.spi.EmptyCursor<K,V>
-
- Type Parameters:
K
- Type of the simulated record's keyV
- 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 emptyCursor
, 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 Summary
Constructors Constructor Description EmptyCursor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
delete()
Deletes the record on which this cursor is currently positioned.K
getKey()
Returns the key of the record on which this cursor is currently positioned.V
getValue()
Returns the value of the record on which this cursor is currently positioned.boolean
isDefined()
Check whether this cursor is currently pointing to valid record.boolean
next()
Moves this cursor to the next record in the tree.boolean
positionToIndex(int index)
Positions the cursor to the specified index within the tree.boolean
positionToKey(ByteSequence key)
Positions the cursor to the provided key if it exists in the tree.boolean
positionToKeyOrNext(ByteSequence key)
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.boolean
positionToLastKey()
Positions the cursor to the last key in the tree.
-
-
-
Method Detail
-
positionToKey
public boolean positionToKey(ByteSequence key)
Description copied from interface:Cursor
Positions the cursor to the provided key if it exists in the tree.- Specified by:
positionToKey
in interfaceCursor<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(ByteSequence 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.- Specified by:
positionToKeyOrNext
in interfaceCursor<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.- Specified by:
positionToLastKey
in interfaceCursor<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.- Specified by:
positionToIndex
in interfaceCursor<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
-
next
public boolean next()
Description copied from interface:SequentialCursor
Moves this cursor to the next record in the tree.- Specified by:
next
in interfaceSequentialCursor<K,V>
- Returns:
true
if the cursor has moved to the next record,false
if no next record exists leaving cursor in undefined state.
-
isDefined
public boolean isDefined()
Description copied from interface:SequentialCursor
Check whether this cursor is currently pointing to valid record.- Specified by:
isDefined
in interfaceSequentialCursor<K,V>
- Returns:
true
if the cursor is pointing to a valid entry,false
if cursor is not pointing to a valid entry
-
getKey
public K getKey() throws NoSuchElementException
Description copied from interface:SequentialCursor
Returns the key of the record on which this cursor is currently positioned.- Specified by:
getKey
in interfaceSequentialCursor<K,V>
- Returns:
- the current record's key.
- Throws:
NoSuchElementException
- if the cursor is not defined.
-
getValue
public V getValue() throws NoSuchElementException
Description copied from interface:SequentialCursor
Returns the value of the record on which this cursor is currently positioned.- Specified by:
getValue
in interfaceSequentialCursor<K,V>
- Returns:
- the current record's value.
- Throws:
NoSuchElementException
- if the cursor is not defined.
-
delete
public void delete() throws NoSuchElementException, UnsupportedOperationException
Description copied from interface:SequentialCursor
Deletes the record on which this cursor is currently positioned. This method does not alter the position of the cursor. In particular,SequentialCursor.next()
must be called in order to point to the next record. The behavior of methodsSequentialCursor.getKey()
andSequentialCursor.getValue()
after this method returns is undefined.- Specified by:
delete
in interfaceSequentialCursor<K,V>
- Throws:
NoSuchElementException
- if the cursor is not defined.UnsupportedOperationException
- if the cursor implementation does not support updates.
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceSequentialCursor<K,V>
-
-