|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
BC
- The branch context representing data type stored in branches.LC
- The leaf context representing data type stored in leaves.public interface BranchNodeIfc<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.
branch.setContext ( new Bar () );
final Bar context = branch.getContext ();
final LeafNodeIfc <Foo> leaf = branch.appendNewLeaf ( new Foo () ); final BranchNodeIfc <Foo> branch = branch.appendNewBranch ( new Bar () );
final LeafNodeIfc <Foo> leaf = branch.prependNewLeaf ( new Foo () ); final BranchNodeIfc <Foo> branch = branch.prependNewBranch ( new Bar () );
final LeafNodeIfc <Foo> leaf = branch.insertNewLeaf ( new Foo (), 10 ); final BranchNodeIfc <Foo> branch = branch.insertNewBranch ( new Bar (), 20 );
final NodeIfc <Foo> leaf = branch.removeNode ( 10 );
final NodeIfc <Foo> leaf = branch.removeNode ( node );
final Collection <NodeIfc <Foo, Bar>> collection = branch.getChildren ();
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 |
---|
void setContext(BC context)
context
- The new context.BC getContext()
LeafNodeIfc<BC,LC> appendNewLeaf(LC leafContext)
leafContext
- The data stored in the return value.
BranchNodeIfc<BC,LC> appendNewBranch(BC branchContext)
branchContext
- The data stored in the return value.
LeafNodeIfc<BC,LC> prependNewLeaf(LC leafContext)
leafContext
- The data stored in the return value.
BranchNodeIfc<BC,LC> prependNewBranch(BC branchContext)
branchContext
- The data stored in the return value.
LeafNodeIfc<BC,LC> insertNewLeaf(LC leafContext, int index)
index
.
leafContext
- The data stored in the return value.index
- The index for which the return value will be inserted.
BranchNodeIfc<BC,LC> insertNewBranch(BC branchContext, int index)
index
.
branchContext
- The data stored in the return value.index
- The index for which the return value will be inserted.
NodeIfc<BC,LC> removeNode(int index)
index
.
index
- The index of the child node to remove.
boolean removeNode(NodeIfc<BC,LC> node)
node
- The child node to remove.
node
was found and removed false if not.java.util.Collection<NodeIfc<BC,LC>> getChildren()
Collections.unmodifiableCollection(java.util.Collection extends T>)
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |