org.modeshape.sequencer.ddl.node

## Class AstNode

- java.lang.Object
- - org.modeshape.sequencer.ddl.node.AstNode

- All Implemented Interfaces:
    Cloneable, Iterable<AstNode>

      @NotThreadSafe
      public final class AstNode
      extends Object
      implements Iterable<AstNode>, Cloneable

  Utility object class designed to facilitate constructing an AST or Abstract Syntax Tree representing nodes and properties that are compatible with ModeShape graph component structure.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `AstNode(AstNode parent, String name)` Construct a node with the supplied name and parent.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addChildren(AstNode first, AstNode second)` Add the supplied nodes at the end of the list of children.
    `void` | `addChildren(AstNode first, AstNode second, AstNode third)` Add the supplied nodes at the end of the list of children.
    `void` | `addChildren(Iterable<AstNode> otherChildren)` Add the supplied nodes at the end of the list of children.
    `void` | `addFirstChild(AstNode child)` Add the supplied node to the front of the list of children.
    `void` | `addLastChild(AstNode child)` Add the supplied node to the end of the list of children.
    `boolean` | `addMixin(String mixin)`
    `List<AstNode>` | `childrenWithName(String name)`
    `AstNode` | `clone()` This class returns a new clone of the plan tree rooted at this node.
    `protected AstNode` | `cloneWithoutNewParent()`
    `void` | `extractChild(AstNode child)` Remove the child node from this node, and replace that child with its first child (if there is one).
    `void` | `extractFromParent()` Extract this node from its parent, but replace this node with its child (if there is one).
    `String` | `getAbsolutePath()` Get the current path of this node
    `AstNode` | `getChild(int index)` Get the child at the supplied index.
    `int` | `getChildCount()` Get the number of child nodes.
    `List<AstNode>` | `getChildren()` Get the unmodifiable list of child nodes.
    `List<AstNode>` | `getChildren(String mixin)`
    `AstNode` | `getFirstChild()` Get the first child.
    `AstNode` | `getLastChild()` Get the last child.
    `List<String>` | `getMixins()`
    `String` | `getName()` Get the name of the node.
    `AstNode` | `getParent()` Get the parent of this node.
    `String` | `getPrimaryType()`
    `Object` | `getProperty(String name)` Get the property with the supplied name.
    `List<String>` | `getPropertyNames()` Return the list of property names for this node.
    `int` | `getSameNameSiblingIndex()` Get the current same-name-sibling index.
    `boolean` | `hasMixin(String mixin)`
    `void` | `insertAsParent(AstNode newParent)` Insert the supplied node into the plan node tree immediately above this node.
    `boolean` | `isSameAs(AstNode other)` Determine whether the supplied plan is equivalent to this plan.
    `Iterator<AstNode>` | `iterator()` This iterator is immutable.
    `List<AstNode>` | `removeAllChildren()` Remove all children from this node.
    `boolean` | `removeChild(AstNode child)` Remove the node from this node.
    `AstNode` | `removeFromParent()` Remove this node from its parent, and return the node that used to be the parent of this node.
    `Object` | `removeProperty(String name)` Remove and return the property with the supplied name.
    `boolean` | `replaceChild(AstNode child, AstNode replacement)` Replace the supplied child with another node.
    `void` | `setParent(AstNode parent)` Set the parent for this node.
    `AstNode` | `setProperty(String name, Object... values)` Set the property with the given name to the supplied values.
    `AstNode` | `setProperty(String name, Object value)` Set the property with the given name to the supplied value.
    `String` | `toString()`

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

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

- - ### Constructor Detail

    - #### AstNode

          public AstNode(AstNode parent,
                 String name)

      Construct a node with the supplied name and parent.
      Parameters:
        `parent` - the parent node; may be null if the new node is to be a root
        `name` - the name of the node; may not be null

  - ### Method Detail

    - #### addMixin

          public boolean addMixin(String mixin)

      Parameters:
        `mixin` - the mixin being added (cannot be `null` or empty)
      Returns:
        `true` if mixin was added

    - #### hasMixin

          public boolean hasMixin(String mixin)

      Parameters:
        `mixin` - the mixin to look for (cannot be `null` or empty)
      Returns:
        `true` if the node has the specified mixin

    - #### getName

          public String getName()

      Get the name of the node.
      Returns:
        the node's name; never null

    - #### getPrimaryType

          public String getPrimaryType()

    - #### getSameNameSiblingIndex

          public int getSameNameSiblingIndex()

      Get the current same-name-sibling index.
      Returns:
        the SNS index, or 1 if this is the first sibling with the same name

    - #### getAbsolutePath

          public String getAbsolutePath()

      Get the current path of this node
      Returns:
        the path of this node; never null

    - #### getProperty

          public Object getProperty(String name)

      Get the property with the supplied name.
      Parameters:
        `name` - the property name; never null
      Returns:
        the property, or null if no such property exists on the node

    - #### setProperty

          public AstNode setProperty(String name,
                            Object value)

      Set the property with the given name to the supplied value. Any existing property with the same name will be replaced.
      Parameters:
        `name` - the name of the property; may not be null
        `value` - the value of the property; may not be null
      Returns:
        this node, for method chaining purposes

    - #### setProperty

          public AstNode setProperty(String name,
                            Object... values)

      Set the property with the given name to the supplied values. If there is at least one value, the new property will replace any existing property with the same name. This method does nothing if zero values are supplied.
      Parameters:
        `name` - the name of the property; may not be null
        `values` - the values of the property
      Returns:
        this node, for method chaining purposes

    - #### removeProperty

          public Object removeProperty(String name)

      Remove and return the property with the supplied name.
      Parameters:
        `name` - the property name; may not be null
      Returns:
        the list of values of the property that was removed, or null if there was no such property

    - #### getPropertyNames

          public List<String> getPropertyNames()

      Return the list of property names for this node.
      Returns:
        the list of strings.

    - #### getMixins

          public List<String> getMixins()

    - #### getParent

          public AstNode getParent()

      Get the parent of this node.
      Returns:
        the parent node, or null if this node has no parent

    - #### setParent

          public void setParent(AstNode parent)

      Set the parent for this node. If this node already has a parent, this method will remove this node from the current parent. If the supplied parent is not null, then this node will be added to the supplied parent's children.
      Parameters:
        `parent` - the new parent, or null if this node is to have no parent

    - #### insertAsParent

          public void insertAsParent(AstNode newParent)

      Insert the supplied node into the plan node tree immediately above this node. If this node has a parent when this method is called, the new parent essentially takes the place of this node within the list of children of the old parent. This method does nothing if the supplied new parent is null.

      For example, consider a plan node tree before this method is called:

                  A
                / | \
               /  |  \
              B   C   D

      Then after this method is called with `c.insertAsParent(e)`, the resulting plan node tree will be:

                  A
                / | \
               /  |  \
              B   E   D
                  |
                  |
                  C

      Also note that the node on which this method is called ('C' in the example above) will always be added as the `last child` to the new parent. This allows the new parent to already have children before this method is called.

      Parameters:
        `newParent` - the new parent; method does nothing if this is null

    - #### removeFromParent

          public AstNode removeFromParent()

      Remove this node from its parent, and return the node that used to be the parent of this node. Note that this method removes the entire subgraph under this node.
      Returns:
        the node that was the parent of this node, or null if this node had no parent
      See Also:
        `extractChild(AstNode)`, `extractFromParent()`

    - #### replaceChild

          public boolean replaceChild(AstNode child,
                             AstNode replacement)

      Replace the supplied child with another node. If the replacement is already a child of this node, this method effectively swaps the position of the child and replacement nodes.
      Parameters:
        `child` - the node that is already a child and that is to be replaced; may not be null and must be a child
        `replacement` - the node that is to replace the 'child' node; may not be null
      Returns:
        true if the child was successfully replaced

    - #### getChildCount

          public int getChildCount()

      Get the number of child nodes.
      Returns:
        the number of children; never negative

    - #### getFirstChild

          public AstNode getFirstChild()

      Get the first child.
      Returns:
        the first child, or null if there are no children

    - #### getLastChild

          public AstNode getLastChild()

      Get the last child.
      Returns:
        the last child, or null if there are no children

    - #### childrenWithName

          public List<AstNode> childrenWithName(String name)

      Parameters:
        `name` - the name of the child being requested (cannot be `null` or empty)
      Returns:
        a collection of children with the specified name (never `null` but can be empty)

    - #### getChild

          public AstNode getChild(int index)

      Get the child at the supplied index.
      Parameters:
        `index` - the index
      Returns:
        the child, or null if there are no children
      Throws:
        `IndexOutOfBoundsException` - if the index is not valid given the number of children

    - #### addFirstChild

          public void addFirstChild(AstNode child)

      Add the supplied node to the front of the list of children.
      Parameters:
        `child` - the node that should be added as the first child; may not be null

    - #### addLastChild

          public void addLastChild(AstNode child)

      Add the supplied node to the end of the list of children.
      Parameters:
        `child` - the node that should be added as the last child; may not be null

    - #### addChildren

          public void addChildren(Iterable<AstNode> otherChildren)

      Add the supplied nodes at the end of the list of children.
      Parameters:
        `otherChildren` - the children to add; may not be null

    - #### addChildren

          public void addChildren(AstNode first,
                         AstNode second)

      Add the supplied nodes at the end of the list of children.
      Parameters:
        `first` - the first child to add
        `second` - the second child to add

    - #### addChildren

          public void addChildren(AstNode first,
                         AstNode second,
                         AstNode third)

      Add the supplied nodes at the end of the list of children.
      Parameters:
        `first` - the first child to add
        `second` - the second child to add
        `third` - the third child to add

    - #### removeChild

          public boolean removeChild(AstNode child)

      Remove the node from this node.
      Parameters:
        `child` - the child node; may not be null
      Returns:
        true if the child was removed from this node, or false if the supplied node was not a child of this node

    - #### extractChild

          public void extractChild(AstNode child)

      Remove the child node from this node, and replace that child with its first child (if there is one).
      Parameters:
        `child` - the child to be extracted; may not be null and must have at most 1 child
      See Also:
        `extractFromParent()`

    - #### extractFromParent

          public void extractFromParent()

      Extract this node from its parent, but replace this node with its child (if there is one).
      See Also:
        `extractChild(AstNode)`

    - #### getChildren

          public List<AstNode> getChildren()

      Get the unmodifiable list of child nodes. This list will immediately reflect any changes made to the children (via other methods), but this list cannot be used to add or remove children.
      Returns:
        the list of children, which immediately reflects changes but which cannot be modified directly; never null

    - #### getChildren

          public List<AstNode> getChildren(String mixin)

      Parameters:
        `mixin` - the mixin to match children with (cannot be `null` or empty)
      Returns:
        the children having the specified mixin (never `null`)

    - #### iterator

          public Iterator<AstNode> iterator()

      This iterator is immutable.

      Specified by:
        `iterator` in interface `Iterable<AstNode>`
      See Also:
        `Iterable.iterator()`

    - #### removeAllChildren

          public List<AstNode> removeAllChildren()

      Remove all children from this node. All nodes immediately become orphaned. The resulting list will be mutable.
      Returns:
        a copy of all the of the children that were removed (and which have no parent); never null

    - #### isSameAs

          public boolean isSameAs(AstNode other)

      Determine whether the supplied plan is equivalent to this plan.
      Parameters:
        `other` - the other plan to compare with this instance
      Returns:
        true if the two plans are equivalent, or false otherwise

    - #### clone

          public AstNode clone()

      This class returns a new clone of the plan tree rooted at this node. However, the top node of the resulting plan tree (that is, the node returned from this method) has no parent.

      Overrides:
        `clone` in class `Object`
      See Also:
        `Object.clone()`

    - #### cloneWithoutNewParent

          protected AstNode cloneWithoutNewParent()

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.