Package org.apache.commons.configuration2.tree

## Class ImmutableNode.Builder

- java.lang.Object
- - org.apache.commons.configuration2.tree.ImmutableNode.Builder

- Enclosing class:
    ImmutableNode

      public static final class ImmutableNode.Builder
      extends Object

  A builder class for creating instances of `ImmutableNode`.

  This class can be used to set all properties of an immutable node instance. Eventually call the `create()` method to obtain the resulting instance.

  Implementation note: This class is not thread-safe. It is intended to be used to define a single node instance only.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Builder()` | Creates a new instance of `Builder` which does not contain any property definitions yet.
    `Builder​(int childCount)` | Creates a new instance of `Builder` and sets the number of expected child nodes.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `ImmutableNode.Builder` | `addAttribute​(String name, Object value)` | Adds an attribute to this builder.
    `ImmutableNode.Builder` | `addAttributes​(Map<String,​?> attrs)` | Adds all attributes of the given map to this builder.
    `ImmutableNode.Builder` | `addChild​(ImmutableNode c)` | Adds a child node to this builder.
    `ImmutableNode.Builder` | `addChildren​(Collection<? extends ImmutableNode> children)` | Adds multiple child nodes to this builder.
    `ImmutableNode` | `create()` | Creates a new `ImmutableNode` instance based on the properties set for this builder.
    `ImmutableNode.Builder` | `name​(String n)` | Sets the name of the node to be created.
    `ImmutableNode.Builder` | `value​(Object v)` | Sets the value of the node to be created.

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

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

- - ### Constructor Detail

    - #### Builder

          public Builder()

      Creates a new instance of `Builder` which does not contain any property definitions yet.

    - #### Builder

          public Builder​(int childCount)

      Creates a new instance of `Builder` and sets the number of expected child nodes. Using this constructor helps the class to create a properly sized list for the child nodes to be added.
      Parameters:
        `childCount` - the number of child nodes

  - ### Method Detail

    - #### name

          public ImmutableNode.Builder name​(String n)

      Sets the name of the node to be created.
      Parameters:
        `n` - the node name
      Returns:
        a reference to this object for method chaining

    - #### value

          public ImmutableNode.Builder value​(Object v)

      Sets the value of the node to be created.
      Parameters:
        `v` - the value
      Returns:
        a reference to this object for method chaining

    - #### addChild

          public ImmutableNode.Builder addChild​(ImmutableNode c)

      Adds a child node to this builder. The passed in node becomes a child of the newly created node. If it is null, it is ignored.
      Parameters:
        `c` - the child node (must not be null)
      Returns:
        a reference to this object for method chaining

    - #### addChildren

          public ImmutableNode.Builder addChildren​(Collection<? extends ImmutableNode> children)

      Adds multiple child nodes to this builder. This method works like `addChild(ImmutableNode)`, but it allows setting a number of child nodes at once.
      Parameters:
        `children` - a collection with the child nodes to be added
      Returns:
        a reference to this object for method chaining

    - #### addAttribute

          public ImmutableNode.Builder addAttribute​(String name,
                                                    Object value)

      Adds an attribute to this builder. The passed in attribute key and value are stored in an internal map. If there is already an attribute with this name, it is overridden.
      Parameters:
        `name` - the attribute name
        `value` - the attribute value
      Returns:
        a reference to this object for method chaining

    - #### addAttributes

          public ImmutableNode.Builder addAttributes​(Map<String,​?> attrs)

      Adds all attributes of the given map to this builder. This method works like `addAttribute(String, Object)`, but it allows setting multiple attributes at once.
      Parameters:
        `attrs` - the map with attributes to be added (may be null
      Returns:
        a reference to this object for method chaining

    - #### create

          public ImmutableNode create()

      Creates a new `ImmutableNode` instance based on the properties set for this builder.
      Returns:
        the newly created `ImmutableNode`