Class HtmlTreeSerializer

java.lang.Object
introspector.model.traverse.HtmlTreeSerializer
All Implemented Interfaces:
TreeSerializer

public class HtmlTreeSerializer extends Object implements TreeSerializer
Stores a tree as a html file
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final boolean
    Indicates if all the info in the nodes must be displayed (i.e., toString() method of objects wrapped by nodes)
    private final Set<Node>
    Used when two trees have been compared.
    private final Writer
    The text stream where the information is to be written
  • Constructor Summary

    Constructors
    Constructor
    Description
    This constructor creates an object to write the tree in a file with all the information in the nodes
    HtmlTreeSerializer(Writer writer, boolean allInfo)
    This constructor creates an object to write the tree in a file with all the information in the nodes
    This constructor creates an object to write the tree in a file with all the information in the nodes
    HtmlTreeSerializer(String fileName, boolean allInfo)
    This constructor creates an object to write the tree in a file
    HtmlTreeSerializer(String fileName, boolean allInfo, Set<Node> modifiedNodes)
    This constructor creates an object to write the tree in a file
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    afterTraversing(Node node, int depth, boolean hasBeenVisited)
    This method is called after one node is traversed
    void
    beforeTraversing(Node node, int depth, boolean hasBeenVisited)
    This method is called after the whole tree has been traversed
    void
    This method is called at the beginning of the tree traversal
    void
    This method is called after the whole tree has been traversed
    private String
    nodeDescription(Node node, boolean cycle)
    Returns the textual representation of a node, considering the allInfo field
    private String
    prefix(int depth)
    Writes the prefix of every node
    private String
    readResourceFile(String resourceName)
    Reads the contents of a file in a resource folder
    void
    traversing(Node node, int depth, boolean hasBeenVisited)
    This method is called when a node is being traversed
    protected void
    Writes one string in the output file and flushes it

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • outputTxtFile

      private final Writer outputTxtFile
      The text stream where the information is to be written
    • allInfo

      private final boolean allInfo
      Indicates if all the info in the nodes must be displayed (i.e., toString() method of objects wrapped by nodes)
    • modifiedNodes

      private final Set<Node> 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 in red to indicate that they have are different from the other tree.
  • Constructor Details

    • HtmlTreeSerializer

      public HtmlTreeSerializer(String fileName, boolean allInfo) throws IOException
      This constructor creates an object to write the tree in a file
      Parameters:
      fileName - the name of the output txt file
      allInfo - 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
    • HtmlTreeSerializer

      public HtmlTreeSerializer(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 file
      allInfo - 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
    • HtmlTreeSerializer

      HtmlTreeSerializer(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
    • HtmlTreeSerializer

      HtmlTreeSerializer(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 stream
      allInfo - if all the info in the nodes must be displayed (i.e., toString() method of objects wrapped by nodes)
    • HtmlTreeSerializer

      HtmlTreeSerializer(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

      private String prefix(int depth)
      Writes the prefix of every node
      Parameters:
      depth - the depth of the node
      Returns:
      its textual representation
    • write

      protected void write(String str) throws IOException
      Writes one string in the output file and flushes it
      Parameters:
      str - the string to be written
      Throws:
      IOException - a textual file is written
    • readResourceFile

      private String readResourceFile(String resourceName)
      Reads the contents of a file in a resource folder
      Parameters:
      resourceName - the name of the resource
      Returns:
      the contents of the file
    • beginTraverse

      public void beginTraverse() throws IOException
      Description copied from interface: TreeSerializer
      This method is called at the beginning of the tree traversal
      Specified by:
      beginTraverse in interface TreeSerializer
      Throws:
      IOException - if there is an error writing the tree
      See Also:
    • endTraverse

      public void endTraverse() throws IOException
      Description copied from interface: TreeSerializer
      This method is called after the whole tree has been traversed
      Specified by:
      endTraverse in interface TreeSerializer
      Throws:
      IOException - if there is an error writing the tree
      See Also:
    • beforeTraversing

      public void beforeTraversing(Node node, int depth, boolean hasBeenVisited)
      Description copied from interface: TreeSerializer
      This method is called after the whole tree has been traversed
      Specified by:
      beforeTraversing in interface TreeSerializer
      Parameters:
      node - the node that is up to be traversed
      depth - the depth of the node
      hasBeenVisited - if the node has already been visited in the current traversal (to detect cycles)
      See Also:
    • traversing

      public void traversing(Node node, int depth, boolean hasBeenVisited) throws IOException
      Description copied from interface: TreeSerializer
      This method is called when a node is being traversed
      Specified by:
      traversing in interface TreeSerializer
      Parameters:
      node - the node that is up being traversed
      depth - the depth of the node
      hasBeenVisited - 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:
    • afterTraversing

      public void afterTraversing(Node node, int depth, boolean hasBeenVisited) throws IOException
      Description copied from interface: TreeSerializer
      This method is called after one node is traversed
      Specified by:
      afterTraversing in interface TreeSerializer
      Parameters:
      node - the node that has just been traversed
      depth - the depth of the node
      hasBeenVisited - 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:
    • nodeDescription

      private String nodeDescription(Node node, boolean cycle)
      Returns the textual representation of a node, considering the allInfo field
      Parameters:
      node - the node to be converted into string
      cycle - if this node is a cycle (has already been visited)
      Returns:
      the textual representation of a node