groovy.util

## Class Node

- java.lang.Object
- - groovy.util.Node

- All Implemented Interfaces:
    Serializable

      public class Node
      extends Object
      implements Serializable

  Represents an arbitrary tree node which can be used for structured metadata or any arbitrary XML-like tree. A node can have a name, a value and an optional Map of attributes. Typically the name is a String and a value is either a String or a List of other Nodes, though the types are extensible to provide a flexible structure, e.g. you could use a QName as the name which includes a namespace URI and a local name. Or a JMX ObjectName etc. So this class can represent metadata like `{foo a=1 b="abc"}` or nested metadata like `{foo a=1 b="123" { bar x=12 text="hello" }}`
  Version:
    $Revision: 19451 $
  Author:
    James Strachan, Paul King
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Node(Node parent, Object name)` Creates a new Node named `name` and if a parent is supplied, adds the newly created node as a child of the parent.
    `Node(Node parent, Object name, Map attributes)` Creates a new Node named `name` with attributes specified in the `attributes` Map.
    `Node(Node parent, Object name, Map attributes, Object value)` Creates a new Node named `name` with value `value` and with attributes specified in the `attributes` Map.
    `Node(Node parent, Object name, Object value)` Creates a new Node named `name` with value `value` and if a parent is supplied, adds the newly created node as a child of the parent.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `append(Node child)`
    `Node` | `appendNode(Object name)`
    `Node` | `appendNode(Object name, Map attributes)`
    `Node` | `appendNode(Object name, Map attributes, Object value)`
    `Node` | `appendNode(Object name, Object value)`
    `Object` | `attribute(Object key)`
    `Map` | `attributes()`
    `List` | `breadthFirst()` Provide a collection of all the nodes in the tree using a breadth-first traversal.
    `List` | `children()`
    `List` | `depthFirst()` Provide a collection of all the nodes in the tree using a depth first traversal.
    `Object` | `get(String key)` Provides lookup of elements by non-namespaced name
    `NodeList` | `getAt(QName name)` Provides lookup of elements by QName.
    `Iterator` | `iterator()`
    `Object` | `name()`
    `Node` | `parent()`
    `void` | `plus(Closure c)`
    `void` | `print(PrintWriter out)`
    `boolean` | `remove(Node child)`
    `Node` | `replaceNode(Closure c)`
    `protected static void` | `setMetaClass(MetaClass metaClass, Class nodeClass)`
    `void` | `setValue(Object value)`
    `String` | `text()`
    `String` | `toString()`
    `Object` | `value()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### Node

          public Node(Node parent,
              Object name)

      Creates a new Node named `name` and if a parent is supplied, adds the newly created node as a child of the parent.
      Parameters:
        `parent` - the parent node or null if no parent
        `name` - the name of the node

    - #### Node

          public Node(Node parent,
              Object name,
              Object value)

      Creates a new Node named `name` with value `value` and if a parent is supplied, adds the newly created node as a child of the parent.
      Parameters:
        `parent` - the parent node or null if no parent
        `name` - the name of the node
        `value` - the Node value, e.g. some text but in general any Object

    - #### Node

          public Node(Node parent,
              Object name,
              Map attributes)

      Creates a new Node named `name` with attributes specified in the `attributes` Map. If a parent is supplied, the newly created node is added as a child of the parent.
      Parameters:
        `parent` - the parent node or null if no parent
        `name` - the name of the node
        `attributes` - a Map of name-value pairs

    - #### Node

          public Node(Node parent,
              Object name,
              Map attributes,
              Object value)

      Creates a new Node named `name` with value `value` and with attributes specified in the `attributes` Map. If a parent is supplied, the newly created node is added as a child of the parent.
      Parameters:
        `parent` - the parent node or null if no parent
        `name` - the name of the node
        `attributes` - a Map of name-value pairs
        `value` - the Node value, e.g. some text but in general any Object

  - ### Method Detail

    - #### append

          public boolean append(Node child)

    - #### remove

          public boolean remove(Node child)

    - #### appendNode

          public Node appendNode(Object name,
                        Map attributes)

    - #### appendNode

          public Node appendNode(Object name)

    - #### appendNode

          public Node appendNode(Object name,
                        Object value)

    - #### appendNode

          public Node appendNode(Object name,
                        Map attributes,
                        Object value)

    - #### replaceNode

          public Node replaceNode(Closure c)

    - #### plus

          public void plus(Closure c)

    - #### setMetaClass

          protected static void setMetaClass(MetaClass metaClass,
                          Class nodeClass)

    - #### text

          public String text()

    - #### iterator

          public Iterator iterator()

    - #### children

          public List children()

    - #### attributes

          public Map attributes()

    - #### attribute

          public Object attribute(Object key)

    - #### name

          public Object name()

    - #### value

          public Object value()

    - #### setValue

          public void setValue(Object value)

    - #### parent

          public Node parent()

    - #### get

          public Object get(String key)

      Provides lookup of elements by non-namespaced name
      Parameters:
        `key` - the name (or shortcut key) of the node(s) of interest
      Returns:
        the nodes which match key

    - #### getAt

          public NodeList getAt(QName name)

      Provides lookup of elements by QName.
      Parameters:
        `name` - the QName of interest
      Returns:
        the nodes matching name

    - #### depthFirst

          public List depthFirst()

      Provide a collection of all the nodes in the tree using a depth first traversal.
      Returns:
        the list of (depth-first) ordered nodes

    - #### breadthFirst

          public List breadthFirst()

      Provide a collection of all the nodes in the tree using a breadth-first traversal.
      Returns:
        the list of (breadth-first) ordered nodes

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### print

          public void print(PrintWriter out)