|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectStatic
Trees
public final class Trees
Convenience static methods for trees operations. This class provides methods for performing a copy of a tree and for converting from XML. It can also print a tree in a format like the following example:
Node #1 ├───Node #2 │ └───Node #4 └───Node #3
TreeFormat
| utility/geotk-utility (download) | View source code for this class |
| Method Summary | |
|---|---|
static MutableTreeNode |
copy(TreeNode node)
Returns a copy of the tree starting at the given node. |
static MutableTreeNode |
copy(TreeNode node,
TreeNodeFilter filter)
Returns a copy of a subset of the tree starting at the given node. |
static TreePath[] |
getPathsToUserObject(TreeModel model,
Object value)
Returns the path to the specified user object. |
static Object |
getUserObject(TreeNode node)
Returns the user object from the given tree node. |
static MutableTreeNode |
objectToSwing(Object object)
Returns a tree representation of the given object. |
static void |
print(TreeModel tree)
Prints the specified tree model to the standard output stream. |
static void |
print(TreeNode node)
Prints the specified tree to the standard output stream. |
static void |
show(TreeModel tree,
String title)
Display the given tree in a Swing frame. |
static void |
show(TreeNode node,
String title)
Display the given tree in a Swing frame. |
static String |
toString(String root,
Iterable<?> nodes)
Returns a graphical representation of the specified nodes. |
static String |
toString(TreeModel tree)
Returns a graphical representation of the specified tree model. |
static String |
toString(TreeNode node)
Returns a graphical representation of the specified tree. |
static MutableTreeNode |
xmlToSwing(Node node)
Creates a Swing root tree node from a XML root tree node. |
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static Object getUserObject(TreeNode node)
TreeNode, then its
getUserObject()
method is invoked. Otherwise if the given node is an instance of Java
DefaultMutableTreeNode, then its getUserObject()
method is invoked. Otherwise this method returns null.
node - The node for which to get the user object, or null.
null if none.
public static TreePath[] getPathsToUserObject(TreeModel model,
Object value)
TreeNode,
this method compares the specified value against the user object returned by the
TreeNode.getUserObject() method.
model - The tree model to inspect.value - User object to compare to TreeNode.getUserObject().
public static MutableTreeNode objectToSwing(Object object)
Node, then this method delegates
to xmlToSwing(Node).Iterable, Map or an array,
then a node is created with the name of the implemented interface (for example
"List" or "Set") and each iterated elements is added as a child
of the above-cited node.Map.Entry, then this
method returns a NamedTreeNode which contain the entry key as the
name and the entry value as
user object.DefaultMutableTreeNode which contain
the given object as user object.
Together with toString(TreeNode), this method provides a convenient way to print
the content of a XML document for debugging purpose.
object - The array, collection or single object to format.
public static MutableTreeNode xmlToSwing(Node node)
toString(TreeNode), this method provides a convenient way to print
the content of a XML document for debugging purpose.
node - The XML root node.
public static MutableTreeNode copy(TreeNode node)
node - The tree to copy (may be null).
null if the given tree was null.
public static MutableTreeNode copy(TreeNode node,
TreeNodeFilter filter)
node - The tree to copy (may be null).filter - An object filtering the node to copy, or null if none.
null if the given tree was null or if
the given node is not accepted by the filter.public static String toString(TreeModel tree)
This convenience method delegates to TreeFormat.format(TreeModel, Appendable).
Users are encouraged to use TreeFormat directly if they want more control on
the formatting process.
tree - The tree to format.
public static String toString(TreeNode node)
This convenience method delegates to TreeFormat.format(TreeNode, Appendable).
Users are encouraged to use TreeFormat directly if they want more control on
the formatting process.
node - The root node of the tree to format.
public static String toString(String root,
Iterable<?> nodes)
This convenience method delegates to TreeFormat.format(Iterable, Appendable).
Users are encouraged to use TreeFormat directly if they want more control on
the formatting process.
Recursivity
This method does not perform any check on the element types. In particular, elements of type
TreeModel, TreeNode or inner Iterable are not processed recursively.
It is up to the toString() implementation of each element to invoke this
toString method recursively if they wish (this method is safe for this purpose).
root - The root name of the tree to format.nodes - The nodes to format.
@Debug public static void print(TreeModel tree)
tree - The tree to print.@Debug public static void print(TreeNode node)
node - The root node of the tree to print.
@Debug
public static void show(TreeNode node,
String title)
node - The root of the tree to display in a Swing frame.title - The frame title, or null if none.
@Debug
public static void show(TreeModel tree,
String title)
tree - The tree to display in a Swing frame.title - The frame title, or null if none.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||