com.bigdata.btree.data
Class DefaultNodeCoder

java.lang.Object
  extended by com.bigdata.btree.data.DefaultNodeCoder
All Implemented Interfaces:
IAbstractNodeDataCoder<INodeData>, Externalizable, Serializable

public class DefaultNodeCoder
extends Object
implements IAbstractNodeDataCoder<INodeData>, Externalizable

Default implementation for immutable INodeData records.

Version:
$Id: DefaultNodeCoder.java 4585 2011-06-01 13:42:56Z thompsonbry $
Author:
Bryan Thompson
See Also:
Serialized Form
TODO:
partly mutable coded records for INodeData are feasible. The only reason to expand an INodeData into a fully MutableNodeData is if we need to modify the keys. The rest of the fields could be easily patched in place if they were not coded (they are fixed length fields). Of course, we have a more compact representation when those fields ARE coded.

Constructor Summary
DefaultNodeCoder()
          De-serialization ctor.
DefaultNodeCoder(IRabaCoder keysCoder)
           
 
Method Summary
 INodeData decode(AbstractFixedByteArrayBuffer data)
          Return an IAbstractNodeData instance which can access the coded data.
 AbstractFixedByteArrayBuffer encode(INodeData node, DataOutputBuffer buf)
          Encode the data, returning a slice containing the coded data.
 INodeData encodeLive(INodeData node, DataOutputBuffer buf)
          Encode the data, returning a reference to a coded instance of the data.
 boolean isLeafDataCoder()
          No.
 boolean isNodeDataCoder()
          Yes.
 void readExternal(ObjectInput in)
           
 String toString()
           
static StringBuilder toString(INodeData node, StringBuilder sb)
          Utility method formats the INodeData.
 void writeExternal(ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultNodeCoder

public DefaultNodeCoder()
De-serialization ctor.


DefaultNodeCoder

public DefaultNodeCoder(IRabaCoder keysCoder)
Parameters:
keysCoder - The IRabaCoder for the node's keys.
Method Detail

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Specified by:
readExternal in interface Externalizable
Throws:
IOException
ClassNotFoundException

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Specified by:
writeExternal in interface Externalizable
Throws:
IOException

isLeafDataCoder

public final boolean isLeafDataCoder()
No.

Specified by:
isLeafDataCoder in interface IAbstractNodeDataCoder<INodeData>
See Also:
ILeafData

isNodeDataCoder

public boolean isNodeDataCoder()
Yes.

Specified by:
isNodeDataCoder in interface IAbstractNodeDataCoder<INodeData>
See Also:
INodeData

toString

public String toString()
Overrides:
toString in class Object

decode

public INodeData decode(AbstractFixedByteArrayBuffer data)
Description copied from interface: IAbstractNodeDataCoder
Return an IAbstractNodeData instance which can access the coded data.

Specified by:
decode in interface IAbstractNodeDataCoder<INodeData>
Parameters:
data - The record containing the coded data.
Returns:
A view of the coded data.

encodeLive

public INodeData encodeLive(INodeData node,
                            DataOutputBuffer buf)
Description copied from interface: IAbstractNodeDataCoder
Encode the data, returning a reference to a coded instance of the data.

Note: Implementations of this method are typically heavy. While it is always valid to IAbstractNodeDataCoder.encode(IAbstractNodeData, DataOutputBuffer) an IAbstractNodeData, DO NOT invoke this arbitrarily on data which may already be coded. The IAbstractNodeCodedData interface will always be implemented for coded data.

Specified by:
encodeLive in interface IAbstractNodeDataCoder<INodeData>
Parameters:
node - The node or leaf data.
buf - A buffer on which the coded data will be written.
Returns:
A reference to a coded instance of the data. IAbstractNodeData.data() is a slice onto the post-condition state of the caller's buffer whose view corresponds to the coded record. This may be written directly onto an output stream or the slice may be converted to an exact fit byte[].

encode

public AbstractFixedByteArrayBuffer encode(INodeData node,
                                           DataOutputBuffer buf)
Description copied from interface: IAbstractNodeDataCoder
Encode the data, returning a slice containing the coded data.

Note: Implementations of this method are typically heavy. While it is always valid to IAbstractNodeDataCoder.encode(IAbstractNodeData, DataOutputBuffer) an IAbstractNodeData, DO NOT invoke this arbitrarily on data which may already be coded. The IAbstractNodeCodedData interface will always be implemented for coded data.

Specified by:
encode in interface IAbstractNodeDataCoder<INodeData>
Parameters:
node - The node or leaf data.
buf - A buffer on which the coded data will be written.
Returns:
A slice onto the post-condition state of the caller's buffer whose view corresponds to the coded record. This may be written directly onto an output stream or the slice may be converted to an exact fit byte[].

toString

public static StringBuilder toString(INodeData node,
                                     StringBuilder sb)
Utility method formats the INodeData.

Parameters:
node - A node data record.
sb - The representation will be written onto this object.
Returns:
The sb parameter.


Copyright © 2006-2011 SYSTAP, LLC. All Rights Reserved.