Package introspector.model.traverse
Class TxtTreeSerializer
java.lang.Object
introspector.model.traverse.TxtTreeSerializer
- All Implemented Interfaces:
TreeSerializer
- Direct Known Subclasses:
ConsoleTreeSerializer
Stores a tree as a txt file
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanIndicates if all the info in the nodes must be displayed (i.e., toString() method of objects wrapped by nodes)Used when two trees have been compared.private final WriterThe text stream where the information is to be written -
Constructor Summary
ConstructorsConstructorDescriptionTxtTreeSerializer(Writer writer) This constructor creates an object to write the tree in a file with all the information in the nodesTxtTreeSerializer(Writer writer, boolean allInfo) This constructor creates an object to write the tree in a file with all the information in the nodesTxtTreeSerializer(String fileName) This constructor creates an object to write the tree in a file with all the information in the nodesTxtTreeSerializer(String fileName, boolean allInfo) This constructor creates an object to write the tree in a fileTxtTreeSerializer(String fileName, boolean allInfo, Set<Node> modifiedNodes) This constructor creates an object to write the tree in a file -
Method Summary
Modifier and TypeMethodDescriptionvoidafterTraversing(Node node, int depth, boolean hasBeenVisited) This method is called after one node is traversedvoidbeforeTraversing(Node node, int depth, boolean hasBeenVisited) This method is called after the whole tree has been traversedvoidThis method is called at the beginning of the tree traversalvoidThis method is called after the whole tree has been traversedprivate Stringprefix(int depth) Writes the prefix of every nodevoidtraversing(Node node, int depth, boolean hasBeenVisited) This method is called when a node is being traversedprotected voidWrites one string in the output file and flushes it
-
Field Details
-
outputTxtFile
The text stream where the information is to be written -
allInfo
private final boolean allInfoIndicates if all the info in the nodes must be displayed (i.e., toString() method of objects wrapped by nodes) -
modifiedNodes
Used when two trees have been compared. The nodes in this set indicates that nodes that have been modified. These nodes must be written between ** and ** to indicate that they have are different from the other tree.
-
-
Constructor Details
-
TxtTreeSerializer
This constructor creates an object to write the tree in a file- Parameters:
fileName- the name of the output txt fileallInfo- if all the info in the nodes must be displayed (i.e., toString() method of objects wrapped by nodes)- Throws:
IOException- a textual file is opened
-
TxtTreeSerializer
public TxtTreeSerializer(String fileName, boolean allInfo, Set<Node> modifiedNodes) throws IOException This constructor creates an object to write the tree in a file- Parameters:
fileName- the name of the output txt fileallInfo- if all the info in the nodes must be displayed (i.e., toString() method of objects wrapped by nodes)modifiedNodes- the nodes that have been modified in the comparison of two trees- Throws:
IOException- a textual file is opened
-
TxtTreeSerializer
TxtTreeSerializer(String fileName) throws IOException This constructor creates an object to write the tree in a file with all the information in the nodes- Parameters:
fileName- the name of the file- Throws:
IOException- textual file is opened
-
TxtTreeSerializer
TxtTreeSerializer(Writer writer, boolean allInfo) This constructor creates an object to write the tree in a file with all the information in the nodes- Parameters:
writer- the textual output streamallInfo- if all the info in the nodes must be displayed (i.e., toString() method of objects wrapped by nodes)
-
TxtTreeSerializer
TxtTreeSerializer(Writer writer) This constructor creates an object to write the tree in a file with all the information in the nodes- Parameters:
writer- the textual output stream
-
-
Method Details
-
prefix
Writes the prefix of every node- Parameters:
depth- the depth of the node- Returns:
- its textual representation
-
write
Writes one string in the output file and flushes it- Parameters:
str- the string to be written- Throws:
IOException- a textual file is written
-
beginTraverse
public void beginTraverse()Description copied from interface:TreeSerializerThis method is called at the beginning of the tree traversal- Specified by:
beginTraversein interfaceTreeSerializer- See Also:
-
endTraverse
Description copied from interface:TreeSerializerThis method is called after the whole tree has been traversed- Specified by:
endTraversein interfaceTreeSerializer- Throws:
IOException- if there is an error writing the tree- See Also:
-
afterTraversing
Description copied from interface:TreeSerializerThis method is called after one node is traversed- Specified by:
afterTraversingin interfaceTreeSerializer- Parameters:
node- the node that has just been traverseddepth- the depth of the nodehasBeenVisited- if the node has already been visited in the current traversal (to detect cycles)- See Also:
-
beforeTraversing
Description copied from interface:TreeSerializerThis method is called after the whole tree has been traversed- Specified by:
beforeTraversingin interfaceTreeSerializer- Parameters:
node- the node that is up to be traverseddepth- the depth of the nodehasBeenVisited- if the node has already been visited in the current traversal (to detect cycles)- Throws:
IOException- if there is an error writing the tree- See Also:
-
traversing
Description copied from interface:TreeSerializerThis method is called when a node is being traversed- Specified by:
traversingin interfaceTreeSerializer- Parameters:
node- the node that is up being traverseddepth- the depth of the nodehasBeenVisited- if the node has already been visited in the current traversal (to detect cycles)- Throws:
IOException- if there is an error writing the tree- See Also:
-