public class TreeGraph
extends java.lang.Object
implements java.io.Serializable
TreeGraph
is a tree with additional directed,
labeled arcs between arbitrary pairs of nodes. (So, it's a graph
with a tree skeleton.) This class is a container for the complete
TreeGraph structure, and does not inherit from Tree
. Individual nodes in the TreeGraph are
represented by TreeGraphNode
s
,
which do inherit from Tree
, and the additional
labeled arcs are represented in the TreeGraphNode
s.TreeGraphNode
,
Serialized FormModifier and Type | Field and Description |
---|---|
protected TreeGraphNode |
root
The root node of this treegraph.
|
Constructor and Description |
---|
TreeGraph(Tree t)
Construct a new
TreeGraph having the same tree
structure and label values as an existing tree (but no shared
storage). |
TreeGraph(TreeGraphNode root) |
Modifier and Type | Method and Description |
---|---|
void |
addNodeToIndexMap(int index,
TreeGraphNode node)
Store a mapping from an arbitrary integer index to a node in
this treegraph.
|
TreeGraphNode |
getNodeByIndex(int index)
Return the node in the this treegraph corresponding to the
specified integer index.
|
java.util.Collection<TreeGraphNode> |
getNodes() |
static void |
main(java.lang.String[] args)
Just for testing.
|
TreeGraphNode |
root()
Return the root node of this treegraph.
|
java.lang.String |
toString()
Return a
String representing this treegraph. |
protected TreeGraphNode root
public TreeGraph(Tree t)
TreeGraph
having the same tree
structure and label values as an existing tree (but no shared
storage). This constructor also assigns integer indices to
all the nodes, beginning with 0 and using a preorder tree
traversal.t
- the tree to copypublic TreeGraph(TreeGraphNode root)
public TreeGraphNode root()
public void addNodeToIndexMap(int index, TreeGraphNode node)
TreeGraph
constructor.index
- the arbitrary integer indexnode
- the TreeGraphNode
to be indexedpublic TreeGraphNode getNodeByIndex(int index)
index
- the integer index of the node you wantTreeGraphNode
having the specified
index (or null
if such does not exist)public java.util.Collection<TreeGraphNode> getNodes()
public java.lang.String toString()
String
representing this treegraph. By
default, the nodes of the treegraph are printed in Lispy
(parenthesized) format, with one node per line, indented
according to depth.toString
in class java.lang.Object
String
representation of this treegraphpublic static void main(java.lang.String[] args)