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 and 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. |
Modifier and Type | Method and 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.
|
public Builder()
Builder
which does not contain any
property definitions yet.public Builder(int childCount)
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.childCount
- the number of child nodespublic ImmutableNode.Builder name(String n)
n
- the node namepublic ImmutableNode.Builder value(Object v)
v
- the valuepublic ImmutableNode.Builder addChild(ImmutableNode c)
c
- the child node (must not be null)public ImmutableNode.Builder addChildren(Collection<? extends ImmutableNode> children)
addChild(ImmutableNode)
, but it allows setting a number of
child nodes at once.children
- a collection with the child nodes to be addedpublic ImmutableNode.Builder addAttribute(String name, Object value)
name
- the attribute namevalue
- the attribute valuepublic ImmutableNode.Builder addAttributes(Map<String,?> attrs)
addAttribute(String, Object)
, but it allows
setting multiple attributes at once.attrs
- the map with attributes to be added (may be nullpublic ImmutableNode create()
ImmutableNode
instance based on the properties
set for this builder.ImmutableNode
Copyright © 2001–2020 The Apache Software Foundation. All rights reserved.