public class Tree
extends java.lang.Object
Constructor and Description |
---|
Tree()
Constructor that creates an empty Tree
|
Tree(java.lang.Character root)
Constructor using the parameter to create a Node that will be the root
|
Tree(java.io.File file)
Constructor building a Tree with a XML document (File)
uses JDOM to parse and build the tree |
Tree(java.io.File file,
VocabTranslator vt)
Constructor building a Tree with an XML document (File)
uses JDOM to parse and build the tree |
Tree(Tree tree)
Constructor that copies the given Tree
|
Modifier and Type | Method and Description |
---|---|
void |
addNode(Address address,
java.lang.Character header)
Creates a Node using the string parameter as Header
Add the new Node at the Address given If the Address is already used, it push every other Node to the right |
void |
addNode(java.lang.String adress,
java.lang.Character header)
Creates an Adresse using the parameter adress and then uses addNode
|
void |
addTree(Address address,
Tree tree)
Adds the Tree at the Address given
|
void |
addTree(java.lang.String address,
Tree tree)
Creates an Address with the String given and adds the Tree at this
Address
|
Tree |
clone() |
boolean |
equals(java.lang.Object o) |
int |
getCreationCost()
Returns the cost of the creation of the tree using the cost
AddNodeOperation.cost for every leaf
|
OperationSequence |
getCreationOperationsSequence()
Returns an OperationSequence that can be used to create the current tree
from an empty tree
|
Node |
getNode(Address address)
Returns a copy of the Node at the given address
|
Tree |
getNodeAsTree(Address address)
Returns Tree create from the Node at the address given
|
int |
getRemovalCost()
Returns the cost of the removal of the tree using the cost
RemoveNodeOperation.cost for every leaf
|
OperationSequence |
getRemoveOperationsSequence()
Returns an OperationSequence that can be used to remove completely the
current tree
|
Node |
getRoot()
Returns a copy of the root
|
int |
hashCode() |
boolean |
isEmpty()
Returns true if the root is empty
|
void |
relabelNode(Address address,
java.lang.Character header)
Changes the Label (Header) of the Node at the given Address with the
given Header
|
void |
relabelNode(java.lang.String address,
java.lang.Character header)
Creates an Address using the String address given and Changes the Label
(Header) of the Node at the Address with the given Header
|
void |
removeNode(Address address)
Removes the Node at the Address given if it is a Leaf
|
void |
removeNode(java.lang.String adress)
Creates an Address with the String given and Removes the Node at the
Address if it is a Leaf
|
void |
removeTree(Address address)
Removes the Node at the Address given even if it isn't a Leaf
|
void |
removeTree(java.lang.String address)
Creates an Address with the String given and removes the Node at this
Address even if it isn't a Leaf
|
void |
replaceTree(Address address,
Tree tree)
Replace the Node and its children at the given Address with the tree
given
|
void |
replaceTree(java.lang.String address,
Tree tree)
Creates an Address with the String given and replace the Node and its
children at this Address with the tree given
|
java.lang.String |
toFlatString()
Let the user print the Tree this way:
<root><node /></root> |
java.lang.String |
toFlatString(VocabTranslator vt)
Let the user print the Tree this way:
<root><node /></root> |
java.lang.String |
toString()
Let the user print the Tree this way:
<root> <node /> </root> |
java.lang.String |
toString(VocabTranslator vt)
Let the user print the Tree this way:
<root> <node /> </root> |
public Tree()
public Tree(java.lang.Character root) throws headerNodeException
root
- String that will be the Label of the root NodeheaderNodeException
- Throws this exception is the header of the new node is ""public Tree(Tree tree)
tree
- Tree that should be copiedpublic Tree(java.io.File file) throws java.lang.Exception
file
- File to parsejava.lang.Exception
- Throws exception if the document isn't valid or if the SAX
Parser can't parse itpublic Tree(java.io.File file, VocabTranslator vt) throws java.lang.Exception
file
- File to parsevt
- Vocabulary translator establishing the correspondence between
XML elements and charactersjava.lang.Exception
- Throws exception if the document isn't valid or if the SAX
Parser can't parse it or the vocabulary translator is
overloadedpublic Node getRoot()
public void addNode(Address address, java.lang.Character header) throws addNodeException, badAddressException, headerNodeException
address
- Address where the new Node should be addedheader
- Header to use to create the NodeaddNodeException
- throws an addNodeException if the father of the Adresse given
do not existbadAddressException
- Throws this Exception if there is an error while creating new
AddressesheaderNodeException
- Throws this exception is the header of the new node is ""public void addNode(java.lang.String adress, java.lang.Character header) throws addNodeException, badAddressException, headerNodeException
adress
- String to use to create the Addressheader
- Header to use to create the NodeaddNodeException
- throws an addNodeException if the father of the Adresse given
do not existbadAddressException
- Throws this Exception if there is an error while creating new
AddressesheaderNodeException
- Throws this exception is the header of the new node is ""public void removeNode(Address address) throws noNodeException, removeNodeException, badAddressException
address
- Address of the Node to removenoNodeException
- throws this Exception if no Node exists at the Address givenremoveNodeException
- throw this Exception if the Node isn't a LeafbadAddressException
- Throws this Exception if there is an error while creating new
Addressespublic void removeNode(java.lang.String adress) throws noNodeException, removeNodeException, badAddressException
adress
- Address of the Node to removenoNodeException
- throws this Exception if no Node exists at the Address givenremoveNodeException
- throw this Exception if the Node isn't a LeafbadAddressException
- Throws this Exception if there is an error while creating new
Addressespublic void removeTree(Address address) throws noNodeException, badAddressException
address
- Address of the Node to removenoNodeException
- throws this Exception if no Node exists at the Address givenbadAddressException
- Throws this Exception if there is an error while creating new
Addressespublic void removeTree(java.lang.String address) throws noNodeException, badAddressException
address
- Address of the Node to removenoNodeException
- throws this Exception if no Node exists at the Address givenbadAddressException
- Throws this Exception if there is an error while creating new
Addressespublic void addTree(Address address, Tree tree) throws addNodeException, badAddressException
address
- Address where the tree should be addedtree
- Tree to addaddNodeException
- Throws this exception if the insertion can't be made (father
doesn't exists...)badAddressException
- Throws this Exception if there is an error while creating new
Addressespublic void addTree(java.lang.String address, Tree tree) throws addNodeException, badAddressException
address
- Address where the tree should be addedtree
- Tree to addaddNodeException
- Throws this exception if the insertion can't be made (father
doesn't exists...)badAddressException
- Throws this Exception if there is an error while creating new
Addressespublic void relabelNode(Address address, java.lang.Character header) throws noNodeException, headerNodeException
address
- Address of the Node to relabelheader
- Header to use to relabel the nodenoNodeException
- Throws this Exception if there isn't any Node at the given
AddressheaderNodeException
- If the Header given is emptypublic void relabelNode(java.lang.String address, java.lang.Character header) throws noNodeException, badAddressException, headerNodeException
address
- String of the Address of the Node to relabelheader
- Header to use to relabel the nodenoNodeException
- Throws this Exception if there isn't any Node at the given
AddressbadAddressException
- Throws this Exception if there is an error while creating new
AddressesheaderNodeException
- If the Header given is emptypublic void replaceTree(Address address, Tree tree) throws noNodeException, addNodeException, removeNodeException, badAddressException
address
- Address of the Node that should be replacedtree
- Tree that has to replace the NodenoNodeException
- Throws this Exception if there is no Node at the adress GivenaddNodeException
- Throws this Exception if the Tree cannot be addedremoveNodeException
- Throws this Exception if the Node at the adress given cannot
be removedbadAddressException
- Throws this Exception if there is an error while creating new
Addressespublic void replaceTree(java.lang.String address, Tree tree) throws noNodeException, addNodeException, removeNodeException, badAddressException
address
- Address of the Node that should be replacedtree
- Tree that has to replace the NodenoNodeException
- Throws this Exception if there is no Node at the address
GivenaddNodeException
- Throws this Exception if the Tree cannot be addedremoveNodeException
- Throws this Exception if the Node at the address given cannot
be removedbadAddressException
- Throws this Exception if there is an error while creating new
Addressespublic int getCreationCost()
public int getRemovalCost()
public Node getNode(Address address)
address
- Address of the Nodepublic Tree getNodeAsTree(Address address) throws noNodeException
address
- Address of the NodenoNodeException
- Throws this exception if there isn't any Node at the address
givenpublic boolean isEmpty()
public java.lang.String toFlatString()
public java.lang.String toFlatString(VocabTranslator vt)
vt
- Vocabulary translator establishing the correspondence between
XML elements and characterspublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(VocabTranslator vt)
vt
- Vocabulary translator establishing the correspondence between
XML elements and characterspublic OperationSequence getCreationOperationsSequence() throws badOperationException, badAddressException, headerNodeException
badOperationException
- Throws this Exception if there is an error while creating the
operationsbadAddressException
- Throws this Exception if there is an error with the addressesheaderNodeException
- Throws this exception is the header of the new node is ""public OperationSequence getRemoveOperationsSequence() throws badOperationException, badAddressException
badOperationException
- Throws this Exception if there is an error while creating the
operationsbadAddressException
- Throws this Exception if there is an error with the addressespublic int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public Tree clone()
clone
in class java.lang.Object