org.apache.hadoop.hbase.types
Class TerminatedWrapper<T>

java.lang.Object
  extended by org.apache.hadoop.hbase.types.TerminatedWrapper<T>
All Implemented Interfaces:
DataType<T>
Direct Known Subclasses:
RawBytesTerminated, RawStringTerminated

@InterfaceAudience.Public
@InterfaceStability.Evolving
public class TerminatedWrapper<T>
extends Object
implements DataType<T>

Wraps an existing DataType implementation as a terminated version of itself. This has the useful side-effect of turning an existing DataType which is not skippable into a skippable variant.


Field Summary
protected  byte[] term
           
protected  DataType<T> wrapped
           
 
Constructor Summary
TerminatedWrapper(DataType<T> wrapped, byte[] term)
          Create a terminated version of the wrapped.
TerminatedWrapper(DataType<T> wrapped, String term)
          Create a terminated version of the wrapped.
 
Method Summary
 T decode(PositionedByteRange src)
          Read an instance of T from the buffer src.
 int encode(PositionedByteRange dst, T val)
          Write instance val into buffer dst.
 Class<T> encodedClass()
          Inform consumers over what type this DataType operates.
 int encodedLength(T val)
          Inform consumers how long the encoded byte[] will be.
 Order getOrder()
          Retrieve the sort Order imposed by this data type, or null when natural ordering is not preserved.
 boolean isNullable()
          Indicates whether this instance supports encoding null values.
 boolean isOrderPreserving()
          Indicates whether this instance writes encoded byte[]'s which preserve the natural sort order of the unencoded value.
 boolean isSkippable()
          Indicates whether this instance is able to skip over it's encoded value.
 int skip(PositionedByteRange src)
          Skip src's position forward over one encoded value.
protected  int terminatorPosition(PositionedByteRange src)
          Return the position at which term begins within src, or -1 if term is not found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

wrapped

protected final DataType<T> wrapped

term

protected final byte[] term
Constructor Detail

TerminatedWrapper

public TerminatedWrapper(DataType<T> wrapped,
                         byte[] term)
Create a terminated version of the wrapped.

Throws:
IllegalArgumentException - when term is null or empty.

TerminatedWrapper

public TerminatedWrapper(DataType<T> wrapped,
                         String term)
Create a terminated version of the wrapped. term is converted to a byte[] using Bytes.toBytes(String).

Throws:
IllegalArgumentException - when term is null or empty.
Method Detail

isOrderPreserving

public boolean isOrderPreserving()
Description copied from interface: DataType
Indicates whether this instance writes encoded byte[]'s which preserve the natural sort order of the unencoded value.

Specified by:
isOrderPreserving in interface DataType<T>
Returns:
true when natural order is preserved, false otherwise.

getOrder

public Order getOrder()
Description copied from interface: DataType
Retrieve the sort Order imposed by this data type, or null when natural ordering is not preserved. Value is either ascending or descending. Default is assumed to be Order.ASCENDING.

Specified by:
getOrder in interface DataType<T>

isNullable

public boolean isNullable()
Description copied from interface: DataType
Indicates whether this instance supports encoding null values. This depends on the implementation details of the encoding format. All DataTypes that support null should treat null as comparing less than any non-null value for default sort ordering purposes.

Specified by:
isNullable in interface DataType<T>
Returns:
true when null is supported, false otherwise.

isSkippable

public boolean isSkippable()
Description copied from interface: DataType
Indicates whether this instance is able to skip over it's encoded value. DataTypes that are not skippable can only be used as the right-most field of a Struct.

Specified by:
isSkippable in interface DataType<T>

encodedLength

public int encodedLength(T val)
Description copied from interface: DataType
Inform consumers how long the encoded byte[] will be.

Specified by:
encodedLength in interface DataType<T>
Parameters:
val - The value to check.
Returns:
the number of bytes required to encode val.a

encodedClass

public Class<T> encodedClass()
Description copied from interface: DataType
Inform consumers over what type this DataType operates. Useful when working with bare DataType instances.

Specified by:
encodedClass in interface DataType<T>

terminatorPosition

protected int terminatorPosition(PositionedByteRange src)
Return the position at which term begins within src, or -1 if term is not found.


skip

public int skip(PositionedByteRange src)
Skip src's position forward over one encoded value.

Specified by:
skip in interface DataType<T>
Parameters:
src - the buffer containing the encoded value.
Returns:
number of bytes skipped.
Throws:
IllegalArgumentException - when the terminator sequence is not found.

decode

public T decode(PositionedByteRange src)
Description copied from interface: DataType
Read an instance of T from the buffer src.

Specified by:
decode in interface DataType<T>
Parameters:
src - the buffer containing the encoded value.

encode

public int encode(PositionedByteRange dst,
                  T val)
Write instance val into buffer dst.

Specified by:
encode in interface DataType<T>
Parameters:
dst - the buffer containing the encoded value.
val - the value to encode onto dst.
Returns:
number of bytes written.
Throws:
IllegalArgumentException - when the encoded representation of val contains the term sequence.


Copyright © 2013 The Apache Software Foundation. All Rights Reserved.