public class Subspace
extends java.lang.Object
Subspace
provide a convenient way to use Tuple
s to define namespaces for
different categories of data. The namespace is specified by a prefix Tuple
which is prepended to all Tuple
s 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(java.lang.Object rhs)
Returns true if this
Subspace is equal to rhs . |
Subspace |
get(java.lang.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 . |
int |
hashCode()
Returns a hash-table compatible hash of this subspace.
|
byte[] |
pack()
Gets the key encoding the prefix used for this
Subspace . |
byte[] |
pack(java.lang.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 . |
byte[] |
packWithVersionstamp(Tuple tuple)
Gets the key encoding the specified tuple in this
Subspace for use with
MutationType.SET_VERSIONSTAMPED_KEY . |
Range |
range()
Gets a
Range respresenting all keys strictly in the Subspace . |
Range |
range(Tuple tuple)
|
Subspace |
subspace(Tuple tuple)
|
java.lang.String |
toString()
Create a human-readable string representation of this subspace.
|
Tuple |
unpack(byte[] key)
|
public Subspace()
Tuple
.public Subspace(Tuple prefix)
Tuple
.
Note that the Tuple
prefix
should not contain any incomplete
Versionstamp
s as any of its entries.prefix
- a Tuple
used to form the subspacejava.lang.IllegalArgumentException
- if prefix
contains any incomplete Versionstamp
spublic 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. Note that the Tuple
prefix
should not contain any incomplete Versionstamp
s as any of its entries.prefix
- a Tuple
used to form the subspacerawPrefix
- a byte array used as the prefix for all packed keysjava.lang.IllegalArgumentException
- if prefix
contains any incomplete Versionstamp
spublic boolean equals(java.lang.Object rhs)
Subspace
is equal to rhs
.
Two Subspace
s are equal if they have the same prefix.equals
in class java.lang.Object
rhs
- the object to check for equalitytrue
if this Subspace
and rhs
have equal prefixespublic java.lang.String toString()
toString
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public Subspace get(java.lang.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 Tuple
sSubspace
's prefix to obj
public Subspace get(Tuple tuple)
Tuple
extended by
the specified Tuple
.tuple
- the Tuple
used to form the new Subspace
Subspace
's prefix to tuple
public byte[] getKey()
Subspace
. This is equivalent to
pack()
ing the empty Tuple
.Subspace
public byte[] pack()
Subspace
.Subspace
public byte[] pack(java.lang.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 Tuple
sobj
public 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 packedSubspace
public byte[] packWithVersionstamp(Tuple tuple)
Subspace
for use with
MutationType.SET_VERSIONSTAMPED_KEY
.
There must be exactly one incomplete Versionstamp
included in the given Tuple
. It will
create a key that is within this Subspace
that can be provided as the key
argument to
Transaction.mutate()
with the SET_VERSIONSTAMPED_KEY
mutation. This will throw an IllegalArgumentException
if the Tuple
does not
contain an incomplete Versionstamp
or if it contains multiple.tuple
- the Tuple
to be packedSubspace
java.lang.IllegalArgumentException
- if tuple
does not contain exactly one incomplete Versionstamp
public 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 Subspace
public Range range(Tuple tuple)
tuple
- the Tuple
whose sub-keys we are searching forRange
of keyspace corresponding to tuple
public 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()