org.apache.asn1.ber
Class DefaultMutableTupleNode

java.lang.Object
  extended by org.apache.asn1.ber.DefaultMutableTupleNode
All Implemented Interfaces:
MutableTupleNode, TupleNode

public class DefaultMutableTupleNode
extends java.lang.Object
implements MutableTupleNode

The default mutable tuple node.

Version:
$Rev: 157644 $
Author:
Apache Directory Project

Field Summary
private  java.util.ArrayList children
          a list of this node's children
private  DefaultMutableTupleNode parent
          this node's parent node
private  Tuple tuple
          this node's tuple user object
private  java.util.List valueChunks
          this node's accumulated ByteBuffer value chunks
 
Constructor Summary
DefaultMutableTupleNode()
          Creates a node without a parent and without a tuple.
DefaultMutableTupleNode(Tuple tuple)
          Creates a node without a parent using a tuple.
DefaultMutableTupleNode(Tuple tuple, java.util.List valueChunks)
          Creates a node without a parent.
 
Method Summary
 void accept(TupleNodeVisitor visitor)
          Recursively descends the tree at this node based on the order of the visitor.
 void addFront(DefaultMutableTupleNode child)
          Adds a child node to the front of the child list.
 void addLast(DefaultMutableTupleNode child)
          Adds a child node to the end of the child list.
 void addValueChunk(java.nio.ByteBuffer valueChunk)
          Adds a buffer containing the entire buffer or a chunked peice of it.
 void encode(java.nio.ByteBuffer dest)
          Depth first generation of this tlv tuple node's encoded image.
static boolean equals(DefaultMutableTupleNode n1, DefaultMutableTupleNode n2)
          Checks to see if two nodes equal one another.
 boolean equals(java.lang.Object obj)
          Checks to see if this node and its children equal another exactly.
 int getChildCount()
          Gets the number of child nodes contained.
 java.util.Iterator getChildren()
          Gets an iterator over this node's children.
 TupleNode getChildTupleNodeAt(int index)
          Gets a tuple node at an index.
private  java.lang.String getHex(int val)
          Gets the hex encoding of an integer with the most significant bites first.
 int getIndex(TupleNode node)
          Gets the index of a child if the child node if it exists.
 TupleNode getParentTupleNode()
          Gets the parent tuple node to this node or null if a parent does not exist.
 Tuple getTuple()
          Gets the Tuple this node represents.
 java.util.List getValueChunks()
          Gets the chunked value buffer fragments collected within this node.
 void insert(MutableTupleNode child, int index)
          Adds child to the receiver at index.
 void printDepthFirst(java.lang.StringBuffer buf, int level)
          Generates a depth first traversal of this node.
 void remove(int index)
          Removes the child at index from the receiver.
 void remove(MutableTupleNode node)
          Removes node from the receiver.
 void removeFromParent()
          Removes the receiver from its parent.
 void setParent(MutableTupleNode newParent)
          Sets the parent of the receiver to newParent.
 void setTuple(Tuple t)
          Resets the Tuple of the receiver object.
 void setTuple(Tuple t, java.util.List valueChunks)
          Resets the Tuple of the receiver object.
 int size()
          Gets the number of child nodes contained.
 java.lang.String toDepthFirstString()
          Generates a depth first traversal of this node.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

tuple

private Tuple tuple
this node's tuple user object


children

private java.util.ArrayList children
a list of this node's children


parent

private DefaultMutableTupleNode parent
this node's parent node


valueChunks

private java.util.List valueChunks
this node's accumulated ByteBuffer value chunks

Constructor Detail

DefaultMutableTupleNode

public DefaultMutableTupleNode()
Creates a node without a parent and without a tuple.


DefaultMutableTupleNode

public DefaultMutableTupleNode(Tuple tuple)
Creates a node without a parent using a tuple. If the tuple is primitive and has a non-null last value chunk, that value chunk is added to the list of value chunks.

Parameters:
tuple - the tuple to set for this node

DefaultMutableTupleNode

public DefaultMutableTupleNode(Tuple tuple,
                               java.util.List valueChunks)
Creates a node without a parent.

Parameters:
tuple - the tuple to set for this node
Method Detail

insert

public void insert(MutableTupleNode child,
                   int index)
Description copied from interface: MutableTupleNode
Adds child to the receiver at index.

Specified by:
insert in interface MutableTupleNode
Parameters:
child - the child to add
index - the index at which to insert the child

addFront

public void addFront(DefaultMutableTupleNode child)
Adds a child node to the front of the child list.

Parameters:
child - the child to add to the front

addLast

public void addLast(DefaultMutableTupleNode child)
Adds a child node to the end of the child list.

Parameters:
child - the child to add to the end

remove

public void remove(int index)
Description copied from interface: MutableTupleNode
Removes the child at index from the receiver.

Specified by:
remove in interface MutableTupleNode
Parameters:
index - the index at which to remove the child

remove

public void remove(MutableTupleNode node)
Description copied from interface: MutableTupleNode
Removes node from the receiver.

Specified by:
remove in interface MutableTupleNode
Parameters:
node - the node to remove

removeFromParent

public void removeFromParent()
Description copied from interface: MutableTupleNode
Removes the receiver from its parent.

Specified by:
removeFromParent in interface MutableTupleNode

setParent

public void setParent(MutableTupleNode newParent)
Description copied from interface: MutableTupleNode
Sets the parent of the receiver to newParent.

Specified by:
setParent in interface MutableTupleNode
Parameters:
newParent - the new parent to set

getParentTupleNode

public TupleNode getParentTupleNode()
Description copied from interface: TupleNode
Gets the parent tuple node to this node or null if a parent does not exist. The analogous method on the TreeNode interface would be getParent().

Specified by:
getParentTupleNode in interface TupleNode
Returns:
the parent node or null if one does not exist

getChildren

public java.util.Iterator getChildren()
Description copied from interface: TupleNode
Gets an iterator over this node's children. The analogous interface on the TreeNode interface would be children which returns an Enumeration instead of an Iterator.

Specified by:
getChildren in interface TupleNode
Returns:
an iterator over this node's children

getChildTupleNodeAt

public TupleNode getChildTupleNodeAt(int index)
Description copied from interface: TupleNode
Gets a tuple node at an index. The analogous interface on TreeNode would be the getChildAt method.

Specified by:
getChildTupleNodeAt in interface TupleNode
Parameters:
index - the index of the child to get
Returns:
the child node at the specified index

getIndex

public int getIndex(TupleNode node)
Description copied from interface: TupleNode
Gets the index of a child if the child node if it exists. The analog within TreeNode takes a TreeNode instead of a TupleNode.

Specified by:
getIndex in interface TupleNode
Parameters:
node - the child node to get the index for
Returns:
the index of the child node or -1 if the node does not exist

getChildCount

public int getChildCount()
Description copied from interface: TupleNode
Gets the number of child nodes contained. This is the same as in TreeNode.getChildCount() as well.

Specified by:
getChildCount in interface TupleNode
Returns:
the number of child nodes contained.

size

public int size()
Description copied from interface: TupleNode
Gets the number of child nodes contained. This is the same as in TreeNode.size() as well.

Specified by:
size in interface TupleNode
Returns:
the number of children

getTuple

public Tuple getTuple()
Description copied from interface: TupleNode
Gets the Tuple this node represents. This is the analogous to TreeNode.getUserObject().

Specified by:
getTuple in interface TupleNode
Returns:
the tuple this node represents or null if one has not been assigned

setTuple

public void setTuple(Tuple t)
Description copied from interface: MutableTupleNode
Resets the Tuple of the receiver object. Also clears the value chunk buffers accumulated for the previous tuple if any.

Specified by:
setTuple in interface MutableTupleNode
Parameters:
t - the tuple to set for this node

setTuple

public void setTuple(Tuple t,
                     java.util.List valueChunks)
Description copied from interface: MutableTupleNode
Resets the Tuple of the receiver object. Also clears the value chunk buffers accumulated for the previous tuple if any.

Specified by:
setTuple in interface MutableTupleNode
Parameters:
t - the tuple to set for this node
valueChunks - the list of value chunk buffers

getValueChunks

public java.util.List getValueChunks()
Description copied from interface: TupleNode
Gets the chunked value buffer fragments collected within this node.

Specified by:
getValueChunks in interface TupleNode
Returns:
the value buffer parts for this node

addValueChunk

public void addValueChunk(java.nio.ByteBuffer valueChunk)
Description copied from interface: MutableTupleNode
Adds a buffer containing the entire buffer or a chunked peice of it.

Specified by:
addValueChunk in interface MutableTupleNode
Parameters:
valueChunk - a chunk of the value as a byte buffer

encode

public void encode(java.nio.ByteBuffer dest)
Depth first generation of this tlv tuple node's encoded image.

Specified by:
encode in interface TupleNode
Parameters:
dest - the buffer populated with the BER encoded tlv tree contents
See Also:
TupleNode.encode(ByteBuffer)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toDepthFirstString

public java.lang.String toDepthFirstString()
Generates a depth first traversal of this node.

Returns:
a depth first traversal print out for this node

getHex

private java.lang.String getHex(int val)
Gets the hex encoding of an integer with the most significant bites first.

Parameters:
val - the integer to break up into 4 bytes and hex encode
Returns:
the hex encoded 4 bytes of an integer

printDepthFirst

public void printDepthFirst(java.lang.StringBuffer buf,
                            int level)
Generates a depth first traversal of this node.

Parameters:
buf - the buffer to capture the traversal into
level - the level down into the tree

equals

public boolean equals(java.lang.Object obj)
Checks to see if this node and its children equal another exactly.

Specified by:
equals in interface TupleNode
Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to compare this node to
Returns:
true if the obj and this node are exact replicas of one another
See Also:
Object.equals(java.lang.Object)

equals

public static boolean equals(DefaultMutableTupleNode n1,
                             DefaultMutableTupleNode n2)
Checks to see if two nodes equal one another. The nodes must be exactly the same even in terms of the order of their children and the children of their descendants.

Parameters:
n1 - the first node
n2 - the second node
Returns:
true if n1.equals(n2) exactly otherwise false

accept

public void accept(TupleNodeVisitor visitor)
Recursively descends the tree at this node based on the order of the visitor.

Specified by:
accept in interface TupleNode
Parameters:
visitor - the tuple node tree structure visitor
See Also:
TupleNode.accept(TupleNodeVisitor)


Copyright © 2004-2009 . All Rights Reserved.