Package com.apple.foundationdb.subspace
Class Subspace
java.lang.Object
com.apple.foundationdb.subspace.Subspace
- Direct Known Subclasses:
 DirectorySubspace
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 Summary
ConstructorsConstructorDescriptionSubspace()Constructor for a subspace formed with an empty prefixTuple.Subspace(byte[] rawPrefix) Constructor for a subspace formed with the specified byte string, which will be prepended to all packed keys.Constructor for a subspace formed with the specified prefixTuple.Constructor for a subspace formed with both a prefixTupleand a prefix byte string. - 
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(byte[] key) Tests whether the specified key starts with thisSubspace's prefix, indicating that theSubspacelogically contains key.booleanReturns true if thisSubspaceis equal torhs.Gets a new subspace which is equivalent to this subspace with its prefixTupleextended by the specifiedObject.byte[]getKey()Gets the key encoding the prefix used for thisSubspace.inthashCode()Returns a hash-table compatible hash of this subspace.byte[]pack()Gets the key encoding the prefix used for thisSubspace.byte[]Gets the key encoding the specified tuple in thisSubspace.byte[]Gets the key encoding the specifiedObjectin thisSubspace.byte[]packWithVersionstamp(Tuple tuple) Gets the key encoding the specified tuple in thisSubspacefor use withMutationType.SET_VERSIONSTAMPED_KEY.range()Gets aRangerepresenting all keys strictly in theSubspace.toString()Create a human-readable string representation of this subspace.unpack(byte[] key)  
- 
Constructor Details
- 
Subspace
public Subspace()Constructor for a subspace formed with an empty prefixTuple. - 
Subspace
Constructor for a subspace formed with the specified prefixTuple. Note that theTupleprefixshould not contain any incompleteVersionstamps as any of its entries.- Parameters:
 prefix- aTupleused to form the subspace- Throws:
 IllegalArgumentException- ifprefixcontains any incompleteVersionstamps
 - 
Subspace
public Subspace(byte[] rawPrefix) Constructor for a subspace formed with the specified byte string, which will be prepended to all packed keys.- Parameters:
 rawPrefix- a byte array used as the prefix for all packed keys
 - 
Subspace
Constructor for a subspace formed with both a prefixTupleand a prefix byte string. The prefixTuplewill be prepended to allTuplespacked by theSubspace, and the byte string prefix will be prepended to the packed result. Note that theTupleprefixshould not contain any incompleteVersionstamps as any of its entries.- Parameters:
 prefix- aTupleused to form the subspacerawPrefix- a byte array used as the prefix for all packed keys- Throws:
 IllegalArgumentException- ifprefixcontains any incompleteVersionstamps
 
 - 
 - 
Method Details
- 
equals
Returns true if thisSubspaceis equal torhs. TwoSubspaces are equal if they have the same prefix. - 
toString
Create a human-readable string representation of this subspace. This is really only useful for debugging purposes, but it includes information on what raw prefix the subspace is using. - 
hashCode
public int hashCode()Returns a hash-table compatible hash of this subspace. This is based off of the hash of the underlying byte-array prefix. - 
get
Gets a new subspace which is equivalent to this subspace with its prefixTupleextended by the specifiedObject. The object will be inserted into aTupleand passed toget(Tuple).- Parameters:
 obj- anObjectcompatible withTuples- Returns:
 - a new subspace formed by joining this 
Subspace's prefix toobj 
 - 
get
Gets a new subspace which is equivalent to this subspace with its prefixTupleextended by the specifiedTuple.- Parameters:
 tuple- theTupleused to form the newSubspace- Returns:
 - a new subspace formed by joining this 
Subspace's prefix totuple 
 - 
getKey
public byte[] getKey()Gets the key encoding the prefix used for thisSubspace. This is equivalent topack()ing the emptyTuple.- Returns:
 - the key encoding the prefix used for this 
Subspace 
 - 
pack
public byte[] pack()Gets the key encoding the prefix used for thisSubspace.- Returns:
 - the key encoding the prefix used for this 
Subspace 
 - 
pack
Gets the key encoding the specifiedObjectin thisSubspace.objis inserted into aTupleand packed withpack(Tuple).- Parameters:
 obj- anObjectto be packed that is compatible withTuples- Returns:
 - the key encoding the tuple derived from 
obj 
 - 
pack
Gets the key encoding the specified tuple in thisSubspace. For example, if you have aSubspacewith prefixTuple("users")and you use it to pack theTuple("Smith"), the result is the same as if you packed theTuple("users", "Smith").- Parameters:
 tuple- theTupleto be packed- Returns:
 - the key encoding the specified tuple in this 
Subspace 
 - 
packWithVersionstamp
Gets the key encoding the specified tuple in thisSubspacefor use withMutationType.SET_VERSIONSTAMPED_KEY. There must be exactly one incompleteVersionstampincluded in the givenTuple. It will create a key that is within thisSubspacethat can be provided as thekeyargument toTransaction.mutate()with theSET_VERSIONSTAMPED_KEYmutation. This will throw anIllegalArgumentExceptionif theTupledoes not contain an incompleteVersionstampor if it contains multiple.- Parameters:
 tuple- theTupleto be packed- Returns:
 - the key encoding the specified tuple in this 
Subspace - Throws:
 IllegalArgumentException- iftupledoes not contain exactly one incompleteVersionstamp
 - 
unpack
- Parameters:
 key- The key being decoded- Returns:
 - the 
Tupleencoded bykeywith the prefix removed 
 - 
range
Gets aRangerepresenting all keys strictly in theSubspace.- Returns:
 - the 
Rangeof keyspace corresponding to thisSubspace 
 - 
range
- Parameters:
 tuple- theTuplewhose sub-keys we are searching for- Returns:
 - the 
Rangeof keyspace corresponding totuple 
 - 
contains
public boolean contains(byte[] key) Tests whether the specified key starts with thisSubspace's prefix, indicating that theSubspacelogically contains key.- Parameters:
 key- the key to be tested- Returns:
 trueifkeystarts withSubspace.key()
 - 
subspace
Gets a new subspace which is equivalent to this subspace with its prefixTupleextended by the specifiedTuple.- Parameters:
 tuple- theTupleused to form the newSubspace- Returns:
 - a new subspace formed by joining this 
Subspace's prefix totuple 
 
 -