public class TraceNode extends Object implements Comparable<TraceNode>
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).Constructor and Description |
---|
TraceNode()
Create an empty trace tree.
|
Modifier and Type | Method and Description |
---|---|
TraceNode |
addChild(String note)
Convenience method to add a child node containing a note to this.
|
TraceNode |
addChild(TraceNode child)
Adds a child node to this.
|
TraceNode |
addChildren(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(String str)
Build a trace tree from the given string representation (possibly encoded using
encode() ). |
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.
|
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.
|
String |
toString() |
String |
toString(int limit)
Generates a non-parseable, human-readable string representation
of this trace node.
|
public TraceNode swap(TraceNode other)
other
- The tree to swap internals with.public TraceNode clear()
public TraceNode sort()
public int compareTo(TraceNode rhs)
compareTo
in interface Comparable<TraceNode>
public TraceNode compact()
public TraceNode normalize()
public boolean isRoot()
public boolean isLeaf()
public boolean isEmpty()
public boolean isStrict()
public TraceNode setStrict(boolean strict)
strict
- True to order children strictly.public boolean hasNote()
public String getNote()
public int getNumChildren()
public TraceNode getChild(int i)
i
- The index of the child to return.public TraceNode addChild(String note)
note
- The note to assign to the child.public TraceNode addChild(TraceNode child)
child
- The child to add.public TraceNode addChildren(List<TraceNode> children)
children
- The children to add.public String toString(int limit)
limit
- soft limit for maximum string sizepublic String encode()
decode(String)
) string representation of this trace node.Copyright © 2018. All rights reserved.