com.pow2.structures.tree
Class ItemTree

java.lang.Object
  extended bycom.pow2.structures.tree.BinaryTree
      extended bycom.pow2.structures.tree.ItemTree

public abstract class ItemTree
extends BinaryTree

ItemsTree class.

Author:
Luca Fossato

Field Summary
protected  HashMap map
          Node hashMap.
protected  boolean traverseAllNodes
          set to true to navigate all the nodes; to false to navigate only the open nodes;
 
Fields inherited from class com.pow2.structures.tree.BinaryTree
cat, INTRAVERSE, nodeVisitor, POSTRAVERSE, PRETRAVERSE, root, traverseMode
 
Constructor Summary
ItemTree()
          Constructor for the ItemsTree object
 
Method Summary
 boolean addLeft(Node p, Node c)
          Add a new left node to the parent node left node list.
 boolean addRight(Node p, Node c)
          Add a new right node to the parent node right node list.
 Node getNode(String id)
          Get the node referenced by the input id.
 boolean insertLeft(Node p, Node c)
          Insert a new left node into the tree.
 boolean insertRight(Node p, Node c)
          Insert a new right node into the tree.
 boolean isTraverseAllNodes()
          Gets the traverseAllNodes attribute of the ItemTree object
 void move(String pId, String id, boolean left)
          Move the c node identified by the input pId indentifier over the new parent p node.
protected  void pretrav(Node p)
          Traverse the tree, using pre-order algorithm, starting from the input node; visit only open nodes.
protected  void remove(Node n)
          Remove the input node from the tree, rearranging the parent and the child nodes references.
 void setTraverseAllNodes(boolean traverseAllNodes)
          Sets the traverseAllNodes attribute of the ItemTree object
 
Methods inherited from class com.pow2.structures.tree.BinaryTree
build, getData, getLeft, getNodeVisitor, getRight, getRoot, getTraverseMode, intrav, isEmpty, move, postrav, remove, setData, setNodeVisitor, setRoot, setTraverseMode, traverse, visit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

map

protected HashMap map
Node hashMap.
Every map entry references a tree node.


traverseAllNodes

protected boolean traverseAllNodes
set to true to navigate all the nodes; to false to navigate only the open nodes;

Constructor Detail

ItemTree

public ItemTree()
Constructor for the ItemsTree object

Method Detail

setTraverseAllNodes

public void setTraverseAllNodes(boolean traverseAllNodes)
Sets the traverseAllNodes attribute of the ItemTree object

Parameters:
traverseAllNodes - The new traverseAllNodes value

isTraverseAllNodes

public boolean isTraverseAllNodes()
Gets the traverseAllNodes attribute of the ItemTree object

Returns:
The traverseAllNodes value

move

public void move(String pId,
                 String id,
                 boolean left)
Move the c node identified by the input pId indentifier over the new parent p node.

Parameters:
pId - the identifier of the parent c node
id - the identifier of the c node to move
left - true if the c node must be inserted as left node of p; false if c must be inserted as right node of p

remove

protected void remove(Node n)
Remove the input node from the tree, rearranging the parent and the child nodes references.

Overrides:
remove in class BinaryTree
Parameters:
n - the node to remove.

getNode

public Node getNode(String id)
Get the node referenced by the input id.

Parameters:
id - the node id
Returns:
the node referenced by the input id, or null if that id doesn't match any node stored into the node map

pretrav

protected void pretrav(Node p)
                throws Exception
Traverse the tree, using pre-order algorithm, starting from the input node; visit only open nodes.
pre-order traversal: first looks at the data, then the left nodes, and then the right nodes.

Overrides:
pretrav in class BinaryTree
Parameters:
p - the node where to start the tree traversing
Throws:
Exception - if any error occurs

insertLeft

public boolean insertLeft(Node p,
                          Node c)
Insert a new left node into the tree.

Overrides:
insertLeft in class BinaryTree
Parameters:
p - the parent node where to insert the new left node
c - the new left node to add to the parent node
Returns:
true if the insertion is successfull; false otherwise

insertRight

public boolean insertRight(Node p,
                           Node c)
Insert a new right node into the tree.

Overrides:
insertRight in class BinaryTree
Parameters:
p - the parent node where to insert the new right node
c - the new right node to add to the parent node
Returns:
true if the insertion is successfull; false otherwise

addLeft

public boolean addLeft(Node p,
                       Node c)
Add a new left node to the parent node left node list.

Overrides:
addLeft in class BinaryTree
Parameters:
p - the parent node
c - the left node to add to the parent node left node list
Returns:
true if the addition is successfull; false otherwise

addRight

public boolean addRight(Node p,
                        Node c)
Add a new right node to the parent node right node list.

Overrides:
addRight in class BinaryTree
Parameters:
p - the parent node
c - the right node to add to the parent node right node list
Returns:
true if the addition is successfull; false otherwise


Copyright © 2002-2004 Power Of Two S.R.L. All Rights Reserved.