Package com.apple.foundationdb
Class KeySelector
java.lang.Object
com.apple.foundationdb.KeySelector
A
For more about how key selectors work in practice, see the KeySelector documentation. Note that the way the key selectors are resolved is somewhat non-intuitive, so users who wish to use a key selector other than the default ones described below should probably consult that documentation before proceeding.
Generally one of the following static methods should be used to construct a
This is an immutable class. The
KeySelector
identifies a particular key in the database. FoundationDB's
lexicographically ordered data model permits finding keys based on their order (for
example, finding the first key in the database greater than a given key). Key selectors
represent a description of a key in the database that could be resolved to an actual
key by Transaction
's getKey()
or used directly as the beginning or end of a range in Transaction
's
getRange()
.For more about how key selectors work in practice, see the KeySelector documentation. Note that the way the key selectors are resolved is somewhat non-intuitive, so users who wish to use a key selector other than the default ones described below should probably consult that documentation before proceeding.
Generally one of the following static methods should be used to construct a
KeySelector
:
This is an immutable class. The
add(int)
call does not
modify internal state, but returns a new instance.
-
Constructor Summary
ConstructorsConstructorDescriptionKeySelector
(byte[] key, boolean orEqual, int offset) Constructs a newKeySelector
from the given parameters. -
Method Summary
Modifier and TypeMethodDescriptionadd
(int offset) Returns a newKeySelector
offset by a given number of keys from this one.static KeySelector
firstGreaterOrEqual
(byte[] key) Creates aKeySelector
that picks the first key greater than or equal to the parameterstatic KeySelector
firstGreaterThan
(byte[] key) Creates aKeySelector
that picks the first key greater than the parameterbyte[]
getKey()
Returns a copy of the key that serves as the anchor for thisKeySelector
.int
Returns the key offset parameter for thisKeySelector
.static KeySelector
lastLessOrEqual
(byte[] key) Creates aKeySelector
that picks the last key less than or equal to the parameterstatic KeySelector
lastLessThan
(byte[] key) Creates aKeySelector
that picks the last key less than the parameterboolean
orEqual()
Returns the orEqual parameter for thisKeySelector
.toString()
-
Constructor Details
-
KeySelector
public KeySelector(byte[] key, boolean orEqual, int offset) Constructs a newKeySelector
from the given parameters. Client code will not generally call this constructor. A key selector can be used to specify a key that will be resolved at runtime based on a starting key and an offset. When this is passed as an argument to aTransaction
'sgetKey()
orgetRange()
methods, the key selector will be resolved to a key within the database. This is done in a manner equivalent to finding the last key that is less than (or less than or equal to, iforEqual
istrue
) the basekey
specified here and then returning the key that isoffset
keys greater than that key.- Parameters:
key
- the base key to referenceorEqual
-true
if the key selector should resolve tokey
(ifkey
is present) before accounting for the offsetoffset
- the offset (in number of keys) that the selector will advance after resolving to a key based on thekey
andorEqual
parameters
-
-
Method Details
-
lastLessThan
Creates aKeySelector
that picks the last key less than the parameter- Parameters:
key
- the key to use as the edge of the edge of selection criteria- Returns:
- a newly created
KeySelector
-
lastLessOrEqual
Creates aKeySelector
that picks the last key less than or equal to the parameter- Parameters:
key
- the key to use as the edge of the edge of selection criteria- Returns:
- a newly created
KeySelector
-
firstGreaterThan
Creates aKeySelector
that picks the first key greater than the parameter- Parameters:
key
- the key to use as the edge of the edge of selection criteria- Returns:
- a newly created
KeySelector
-
firstGreaterOrEqual
Creates aKeySelector
that picks the first key greater than or equal to the parameter- Parameters:
key
- the key to use as the edge of the edge of selection criteria- Returns:
- a newly created
KeySelector
-
add
Returns a newKeySelector
offset by a given number of keys from this one. For example, an offset of1
means that the newKeySelector
specifies the key in the database after the key selected by thisKeySelector
. The offset can be negative; these will move the selector to previous keys in the database.
Note that large offsets take time O(offset) to resolve, making them a poor choice for iterating through a large range. (Instead, use the keys returned from a range query operation themselves to create a new beginningKeySelector
.) For more information see the KeySelector documentation.- Parameters:
offset
- the number of keys to offset theKeySelector
. This number can be negative.- Returns:
- a newly created
KeySelector
that is offset by a number of keys.
-
getKey
public byte[] getKey()Returns a copy of the key that serves as the anchor for thisKeySelector
. This is not the key to which thisKeySelector
would resolve to. For this function seeReadTransaction.getKey(KeySelector)
.- Returns:
- a copy of the "anchor" key for this
KeySelector
.
-
toString
-
orEqual
public boolean orEqual()Returns the orEqual parameter for thisKeySelector
. See theKeySelector(byte[], boolean, int)
KeySelector constructor} for more details.- Returns:
- the
or-equal
parameter of thisKeySelector
.
-
getOffset
public int getOffset()Returns the key offset parameter for thisKeySelector
. See theKeySelector constructor
for more details.- Returns:
- the key offset for this
KeySelector
-