public class Subspace extends Object
Subspace provide a convenient way to use Tuples to define namespaces for
different categories of data. The namespace is specified by a prefix Tuple
which is prepended to all Tuples packed by the Subspace. When unpacking a key
with the Subspace, the prefix Tuple will be removed from the result.
For general guidance on subspace usage, see the discussion in Developer Guide.
As a best practice, API clients should use at least one subspace for application data.
| Constructor and Description |
|---|
Subspace()
Constructor for a subspace formed with an empty prefix
Tuple. |
Subspace(byte[] rawPrefix)
Constructor for a subspace formed with the specified byte string, which will
be prepended to all packed keys.
|
Subspace(Tuple prefix)
Constructor for a subspace formed with the specified prefix
Tuple. |
Subspace(Tuple prefix,
byte[] rawPrefix)
Constructor for a subspace formed with both a prefix
Tuple and a
prefix byte string. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(byte[] key)
Tests whether the specified key starts with this
Subspace's prefix, indicating that
the Subspace logically contains key. |
boolean |
equals(Object rhs)
Returns true if this
Subspace is equal to rhs. |
Subspace |
get(Object obj)
Gets a new subspace which is equivalent to this subspace with its prefix
Tuple extended by
the specified Object. |
Subspace |
get(Tuple tuple)
|
byte[] |
getKey()
Gets the key encoding the prefix used for this
Subspace. |
byte[] |
pack()
Gets the key encoding the prefix used for this
Subspace. |
byte[] |
pack(Object obj)
Gets the key encoding the specified
Object in this Subspace. |
byte[] |
pack(Tuple tuple)
Gets the key encoding the specified tuple in this
Subspace. |
Range |
range()
Gets a
Range respresenting all keys strictly in the Subspace. |
Range |
range(Tuple tuple)
|
Subspace |
subspace(Tuple tuple)
|
String |
toString() |
Tuple |
unpack(byte[] key)
|
public Subspace()
Tuple.public Subspace(Tuple prefix)
Tuple.prefix - a Tuple used to form the subspacepublic Subspace(byte[] rawPrefix)
rawPrefix - a byte array used as the prefix for all packed keyspublic Subspace(Tuple prefix, byte[] rawPrefix)
Tuple and a
prefix byte string. The prefix Tuple will be prepended to all
Tuples packed by the Subspace, and the byte string prefix
will be prepended to the packed result.prefix - a Tuple used to form the subspacerawPrefix - a byte array used as the prefix for all packed keyspublic boolean equals(Object rhs)
Subspace is equal to rhs.
Two Subspaces are equal if they have the same prefix.public String toString()
public Subspace get(Object obj)
Tuple extended by
the specified Object. The object will be inserted into a Tuple and passed to get(Tuple).obj - an Object compatible with TuplesSubspace's prefix to objpublic Subspace get(Tuple tuple)
Tuple extended by
the specified Tuple.tuple - the Tuple used to form the new SubspaceSubspace's prefix to tuplepublic byte[] getKey()
Subspace. This is equivalent to
pack()ing the empty Tuple.Subspacepublic byte[] pack()
Subspace.Subspacepublic byte[] pack(Object obj)
Object in this Subspace. obj is
inserted into a Tuple and packed with pack(Tuple).obj - an Object to be packed that is compatible with Tuplesobjpublic byte[] pack(Tuple tuple)
Subspace. For example, if you have a Subspace
with prefix Tuple ("users") and you use it to pack the Tuple ("Smith"),
the result is the same as if you packed the Tuple ("users", "Smith").tuple - the Tuple to be packedSubspacepublic Tuple unpack(byte[] key)
key - The key being decodedTuple encoded by key with the prefix removedpublic Range range()
Range respresenting all keys strictly in the Subspace.Range of keyspace corresponding to this Subspacepublic Range range(Tuple tuple)
tuple - the Tuple whose sub-keys we are searching forRange of keyspace corresponding to tuplepublic boolean contains(byte[] key)
Subspace's prefix, indicating that
the Subspace logically contains key.key - the key to be testedtrue if key starts with Subspace.key()