Class TraceNode

  • All Implemented Interfaces:
    java.lang.Comparable<TraceNode>

    public class TraceNode
    extends java.lang.Object
    implements java.lang.Comparable<TraceNode>
    This class contains the actual trace information of a Trace object. A trace node can be encoded to, and decoded from a string representation to allow transport across the network. Each node contains a list of children, a strictness flag and an optional note. The child list is what forms the trace tree, the strictness flag dictates whether or not the ordering of the children is important, and the note is the actual traced data. The most important feature to notice is the normalize() method that will compact, sort and 'rootify' the trace tree so that trees become well-formed (and can be compared for equality).
    Author:
    Simon Thoresen Hult
    • Constructor Summary

      Constructors 
      Constructor Description
      TraceNode()
      Create an empty trace tree.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      TraceNode addChild​(TraceNode child)
      Adds a child node to this.
      TraceNode addChild​(java.lang.String note)
      Convenience method to add a child node containing a note to this.
      TraceNode addChildren​(java.util.List<TraceNode> children)
      Adds a list of child nodes to this.
      TraceNode clear()
      Remove all trace information from this tree.
      TraceNode compact()
      Compact this tree.
      int compareTo​(TraceNode rhs)  
      static TraceNode decode​(java.lang.String str)
      Build a trace tree from the given string representation (possibly encoded using encode()).
      java.lang.String encode()
      Returns a parseable (using decode(String)) string representation of this trace node.
      TraceNode getChild​(int i)
      Returns the child trace node at the given index.
      java.lang.String getNote()
      Returns the note assigned to this node.
      int getNumChildren()
      Returns the number of child nodes of this.
      boolean hasNote()
      Returns whether or not a note is assigned to this node.
      boolean isEmpty()
      Check whether or not this node is empty, i.e.
      boolean isLeaf()
      Check whether or not this is a leaf node.
      boolean isRoot()
      Check whether or not this is a root node.
      boolean isStrict()
      Check whether or not the children of this node are strictly ordered.
      TraceNode normalize()
      Normalize this tree.
      TraceNode setStrict​(boolean strict)
      Sets whether or not the children of this node are strictly ordered.
      TraceNode sort()
      Sort non-strict children recursively down the tree.
      TraceNode swap​(TraceNode other)
      Swap the internals of this tree with another.
      java.lang.String toString()  
      java.lang.String toString​(int limit)
      Generates a non-parseable, human-readable string representation of this trace node.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • TraceNode

        public TraceNode()
        Create an empty trace tree.
    • Method Detail

      • swap

        public TraceNode swap​(TraceNode other)
        Swap the internals of this tree with another.
        Parameters:
        other - The tree to swap internals with.
        Returns:
        This, to allow chaining.
      • clear

        public TraceNode clear()
        Remove all trace information from this tree.
        Returns:
        This, to allow chaining.
      • sort

        public TraceNode sort()
        Sort non-strict children recursively down the tree.
        Returns:
        This, to allow chaining.
      • compareTo

        public int compareTo​(TraceNode rhs)
        Specified by:
        compareTo in interface java.lang.Comparable<TraceNode>
      • compact

        public TraceNode compact()
        Compact this tree. This will reduce the height of this tree as much as possible without removing information stored in it.
        Returns:
        This, to allow chaining.
      • normalize

        public TraceNode normalize()
        Normalize this tree. This will transform all equivalent trees into the same form. Note that this will also perform an implicit compaction of the tree.
        Returns:
        This, to allow chaining.
      • isRoot

        public boolean isRoot()
        Check whether or not this is a root node.
        Returns:
        True if this has no parent.
      • isLeaf

        public boolean isLeaf()
        Check whether or not this is a leaf node.
        Returns:
        True if this has no children.
      • isEmpty

        public boolean isEmpty()
        Check whether or not this node is empty, i.e. it has no note and no children.
        Returns:
        True if this node is empty.
      • isStrict

        public boolean isStrict()
        Check whether or not the children of this node are strictly ordered.
        Returns:
        True if this node is strict.
      • setStrict

        public TraceNode setStrict​(boolean strict)
        Sets whether or not the children of this node are strictly ordered.
        Parameters:
        strict - True to order children strictly.
        Returns:
        This, to allow chaining.
      • hasNote

        public boolean hasNote()
        Returns whether or not a note is assigned to this node.
        Returns:
        True if a note is assigned.
      • getNote

        public java.lang.String getNote()
        Returns the note assigned to this node.
        Returns:
        The note.
      • getNumChildren

        public int getNumChildren()
        Returns the number of child nodes of this.
        Returns:
        The number of children.
      • getChild

        public TraceNode getChild​(int i)
        Returns the child trace node at the given index.
        Parameters:
        i - The index of the child to return.
        Returns:
        The child at the given index.
      • addChild

        public TraceNode addChild​(java.lang.String note)
        Convenience method to add a child node containing a note to this.
        Parameters:
        note - The note to assign to the child.
        Returns:
        This, to allow chaining.
      • addChild

        public TraceNode addChild​(TraceNode child)
        Adds a child node to this.
        Parameters:
        child - The child to add.
        Returns:
        This, to allow chaining.
      • addChildren

        public TraceNode addChildren​(java.util.List<TraceNode> children)
        Adds a list of child nodes to this.
        Parameters:
        children - The children to add.
        Returns:
        This, to allow chaining.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toString

        public java.lang.String toString​(int limit)
        Generates a non-parseable, human-readable string representation of this trace node.
        Parameters:
        limit - soft limit for maximum string size
        Returns:
        generated string
      • encode

        public java.lang.String encode()
        Returns a parseable (using decode(String)) string representation of this trace node.
        Returns:
        A string representation of this tree.
      • decode

        public static TraceNode decode​(java.lang.String str)
        Build a trace tree from the given string representation (possibly encoded using encode()).
        Parameters:
        str - The string to parse.
        Returns:
        The corresponding trace tree, or an empty node if parsing failed.