Package com.apple.foundationdb.tuple
Class TupleHelpers
java.lang.Object
com.apple.foundationdb.tuple.TupleHelpers
Helper methods for working with
Tuple
s.-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic int
Compare two tuples lexicographically, that is, the same way they would sort when used as keys.static boolean
Determine if twoTuple
s have the same contents.static boolean
Get whether one tuple is a prefix of another.static Number
Negate a number used as an element of aTuple
.static int
packedSizeAsTupleItem
(Object item) Get the number of bytes that an object would occupy as an element of an encodedTuple
.static int
prefixLengthOfSize
(byte[] bytes, int size) Get the index of a prefix of an encoded tuple that decodes as a sub-tuple of the given size.static Tuple
static Tuple
-
Field Details
-
EMPTY
-
-
Method Details
-
set
-
subTuple
-
compare
Compare two tuples lexicographically, that is, the same way they would sort when used as keys. Note that this is currently WAY more efficient than callingTuple.equals(java.lang.Object)
, and slightly more efficient than callingTuple.compareTo(com.apple.foundationdb.tuple.Tuple)
. -
equals
Determine if twoTuple
s have the same contents. Unfortunately, the implementation ofTuple.equals()
serializes bothTuple
s to byte arrays, so it is fairly expensive. This method avoids serializing eitherTuple
, and it also adds a short-circuit to return early if the twoTuple
s are pointer-equal. -
negate
Negate a number used as an element of aTuple
.- Parameters:
number
- the number to be negated- Returns:
- a negated number suitable for use in a new
Tuple
-
packedSizeAsTupleItem
Get the number of bytes that an object would occupy as an element of an encodedTuple
. UnlikeTuple.getPackedSize()
, this does not include the extra space an incompleteVersionstamp
would add to the end to record its position.- Parameters:
item
- an item of a tuple- Returns:
- the number of bytes in the encoded form of the item
-
isPrefix
Get whether one tuple is a prefix of another.- Parameters:
t1
- the potential prefixt2
- the whole tuple- Returns:
true
ift1
is a prefix oft2
-
prefixLengthOfSize
public static int prefixLengthOfSize(@Nonnull byte[] bytes, int size) Get the index of a prefix of an encoded tuple that decodes as a sub-tuple of the given size.- Parameters:
bytes
- encoded tuplesize
- size of desired subtuple- Returns:
- the index into
bytes
that ends the sub-tuple or-1
ifbytes
is too short or decoding fails
-