org.jplate.foundation.node
Interface BranchNodeIfc<BC,LC>

Type Parameters:
BC - The branch context representing data type stored in branches.
LC - The leaf context representing data type stored in leaves.
All Superinterfaces:
FormattableIfc, NodeIfc<BC,LC>, java.io.Serializable, VisitableIfc<NodeVisitorIfc<BC,LC>>
All Known Implementing Classes:
DefaultBranchNode

public interface BranchNodeIfc<BC,LC>
extends java.io.Serializable, NodeIfc<BC,LC>

Defines the API for a branch node. Branch nodes have optional child nodes (LeafNodeIfc or BranchNodeIfc) and a context (an arbitrary object that belongs at the branch level). Implementations must manage the child nodes and act as a factory when adding child nodes. Refer to the various append, prepend, and insert methods: children are not created and then added to the branch externally, the branch performs the correct insertion creating the child node and returning it.

Providing the branch and leaf contexts define the data stored in parents, siblings and children.

Mentioned above is the notion of a context. A context is nothing more than an object that makes sense for a branch and is specific for a branch. Consider XML, the tag and its attributes are comparable for context. Assuming this, the context may be defined as such:

public final class XmlTag
{
    public String _tagName;
    public final Map <String, String> attributes =
        new HashMap <String, String> ();
}

final BranchIfc branch <XmlTag, String> = ...
    

Consider the following examples:

final BranchIfc <Bar, Foo> branch = ...; // Assume instantiated correcly.
    

Please note: For appends, inserts and prepends the implementation of BranchIfc is responsible for creating the node (either an implemntation of LeafIfc or BranchIfc). This restriction is by design: doing so forces the new child to have exactly one parent - as well as ensuring the parent can not be changed thus allowing a child to have two parents instead of one.

Modifications:
    $Date: 2008-12-02 12:32:45 -0500 (Tue, 02 Dec 2008) $
    $Revision: 479 $
    $Author: sfloess $
    $HeadURL: https://jplate.svn.sourceforge.net/svnroot/jplate/trunk/src/dev/java/org/jplate/foundation/node/BranchNodeIfc.java $
    


Method Summary
 BranchNodeIfc<BC,LC> appendNewBranch(BC branchContext)
          Append a new child branch node.
 LeafNodeIfc<BC,LC> appendNewLeaf(LC leafContext)
          Append a new child leaf node.
 java.util.Collection<NodeIfc<BC,LC>> getChildren()
          Return the children of self.
 BC getContext()
          Returns the context.
 BranchNodeIfc<BC,LC> insertNewBranch(BC branchContext, int index)
          Insert a new child branch node at index.
 LeafNodeIfc<BC,LC> insertNewLeaf(LC leafContext, int index)
          Insert a new child leaf node at index.
 BranchNodeIfc<BC,LC> prependNewBranch(BC branchContext)
          Prepend a new child branch node.
 LeafNodeIfc<BC,LC> prependNewLeaf(LC leafContext)
          Prepend a new child leaf node.
 NodeIfc<BC,LC> removeNode(int index)
          Remove the child node at index.
 boolean removeNode(NodeIfc<BC,LC> node)
          Remove a child node.
 void setContext(BC context)
          Sets the context.
 
Methods inherited from interface org.jplate.foundation.node.NodeIfc
getParent, getSource, setSource
 
Methods inherited from interface org.jplate.foundation.FormattableIfc
toString
 
Methods inherited from interface org.jplate.foundation.gof.visitor.VisitableIfc
accept
 

Method Detail

setContext

void setContext(BC context)
Sets the context.

Parameters:
context - The new context.

getContext

BC getContext()
Returns the context.

Returns:
The context.

appendNewLeaf

LeafNodeIfc<BC,LC> appendNewLeaf(LC leafContext)
Append a new child leaf node.

Parameters:
leafContext - The data stored in the return value.
Returns:
The newly appended child leaf node.

appendNewBranch

BranchNodeIfc<BC,LC> appendNewBranch(BC branchContext)
Append a new child branch node.

Parameters:
branchContext - The data stored in the return value.
Returns:
The newly appended branch node.

prependNewLeaf

LeafNodeIfc<BC,LC> prependNewLeaf(LC leafContext)
Prepend a new child leaf node.

Parameters:
leafContext - The data stored in the return value.
Returns:
The newly prepended child leaf node.

prependNewBranch

BranchNodeIfc<BC,LC> prependNewBranch(BC branchContext)
Prepend a new child branch node.

Parameters:
branchContext - The data stored in the return value.
Returns:
the newly prepended child branch node.

insertNewLeaf

LeafNodeIfc<BC,LC> insertNewLeaf(LC leafContext,
                                 int index)
Insert a new child leaf node at index.

Parameters:
leafContext - The data stored in the return value.
index - The index for which the return value will be inserted.
Returns:
the newly inserted child leaf node.

insertNewBranch

BranchNodeIfc<BC,LC> insertNewBranch(BC branchContext,
                                     int index)
Insert a new child branch node at index.

Parameters:
branchContext - The data stored in the return value.
index - The index for which the return value will be inserted.
Returns:
the newly prepended child branch node.

removeNode

NodeIfc<BC,LC> removeNode(int index)
Remove the child node at index.

Parameters:
index - The index of the child node to remove.
Returns:
The removed node.

removeNode

boolean removeNode(NodeIfc<BC,LC> node)
Remove a child node.

Parameters:
node - The child node to remove.
Returns:
true if node was found and removed false if not.

getChildren

java.util.Collection<NodeIfc<BC,LC>> getChildren()
Return the children of self. Implementations are encouraged to return an Collections.unmodifiableCollection(java.util.Collection).

Returns:
The children nodes as a Collection.