public class ConfigTreeBuilder extends java.lang.Object implements ConfigTree
Usage example:
ConfigNode config = new ConfigNodeBuilder()
.beginValue("version", "1.0.0")
.withFinality()
.beginConstraints() // checks the default value
.regex("\\d+\\.\\d+\\.\\d+")
.finishConstraints()
.finishValue()
.fork("child")
.beginValue("A", 10)
.beginConstraints()
.composite(CompositeType.OR)
.atLeast(3)
.atMost(0)
.finishComposite()
.finishConstraints()
.finishValue()
.finishNode()
.build();
ConfigTree.builder(),
PropertyMirror| Modifier and Type | Field and Description |
|---|---|
protected java.lang.String |
name |
protected ConfigTreeBuilder |
parent |
| Constructor and Description |
|---|
ConfigTreeBuilder() |
| Modifier and Type | Method and Description |
|---|---|
ConfigTreeBuilder |
add(ConfigNode item)
Attempts to introduce a new child to this node.
|
ConfigTreeBuilder |
add(ConfigNode item,
boolean overwrite)
Attempts to introduce a new child to this node.
|
ConfigTreeBuilder |
applyFromPojo(java.lang.Object pojo)
Configure this builder using a POJO (Plain Old Java Object).
|
<C extends java.util.Collection<E>,E> |
beginAggregateValue(java.lang.String name,
C defaultValue,
java.lang.Class<E> elementType)
Creates an aggregate
ConfigLeafBuilder. |
<E> ConfigAggregateBuilder<E[],E> |
beginAggregateValue(java.lang.String name,
E[] defaultValue)
Creates an aggregate
ConfigLeafBuilder. |
<T> ConfigLeafBuilder<T> |
beginValue(java.lang.String name,
java.lang.Class<T> type)
Creates a scalar
ConfigLeafBuilder. |
<T> ConfigLeafBuilder<T> |
beginValue(java.lang.String name,
T defaultValue)
Creates a
ConfigLeafBuilder with the given default value. |
ConfigBranch |
build()
Construct a new
ConfigNode based on this builder's specifications. |
ConfigTreeBuilder |
finishNode() |
ConfigTreeBuilder |
finishNode(java.util.function.Consumer<ConfigBranch> action) |
ConfigTreeBuilder |
fork(java.lang.String name)
Forks this builder, creating a subtree whose parent is this node.
|
java.util.Collection<ConfigNode> |
getItems()
Returns a collection of this builder's children.
|
ConfigNode |
lookup(java.lang.String name)
Tries to find a child in this builder by name.
|
ConfigNode |
remove(java.lang.String name)
Attempts to remove an item from this node by name.
|
ConfigTreeBuilder |
withComment(java.lang.String comment) |
ConfigTreeBuilder |
withName(java.lang.String name) |
ConfigTreeBuilder |
withParent(ConfigTreeBuilder parent) |
ConfigTreeBuilder |
withSeparateSerialization()
Marks the built subtree as being serialized separately.
|
ConfigTreeBuilder |
withSeparateSerialization(boolean serializeSeparately)
Sets whether a subtree should be serialized separately.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbuilder@Nullable protected ConfigTreeBuilder parent
@Nullable protected java.lang.String name
@Nonnull public java.util.Collection<ConfigNode> getItems()
The returned collection is guaranteed to have no two nodes with the same name. Elements may be removed from it, but no elements may be added directly.
getItems in interface ConfigTreeadd(ConfigNode)@Nullable public ConfigNode lookup(java.lang.String name)
lookup in interface ConfigTreename - The name of the child to look fornullpublic ConfigTreeBuilder withParent(ConfigTreeBuilder parent)
public ConfigTreeBuilder withName(java.lang.String name)
public ConfigTreeBuilder withComment(@Nullable java.lang.String comment)
public ConfigTreeBuilder withSeparateSerialization()
A subtree marked for separate serialization will not appear in the serialized representation of its ancestors. This property can be useful when partitioning a big configuration tree into several files.
This method has no effect if the built node is a tree root.
this, for chainingwithSeparateSerialization(),
ConfigBranch.isSerializedSeparately()public ConfigTreeBuilder withSeparateSerialization(boolean serializeSeparately)
If serializeSeparately is true, the subtree created
from this builder will not appear in the serialized representation of the
ancestor. This property can be especially useful when partitioning a
big configuration tree into several files.
This method has no effect if the built node is a tree root.
serializeSeparately - true if the built tree should be serialized separatelythis, for chainingpublic ConfigTreeBuilder applyFromPojo(java.lang.Object pojo) throws FiberException
The node's structure will be based on the pojo's fields,
recursively generating settings. The generated settings can be configured
in the pojo's class declaration, using annotations such as Setting.
The generated ConfigLeafs will be bound to their respective fields,
setting the latter when the former's value is updated.
pojo - an object serving as a base to reflectively generate a config treethis, for chainingFiberException@Setting,
@Settings,
AnnotatedSettings.applyToNode(ConfigTreeBuilder, Object)public <T> ConfigLeafBuilder<T> beginValue(@Nonnull java.lang.String name, @Nonnull java.lang.Class<T> type)
ConfigLeafBuilder.T - the type type representstype - the class of the type of value the ConfigLeaf produced by the builder holdsConfigLeafBuilderpublic <T> ConfigLeafBuilder<T> beginValue(@Nonnull java.lang.String name, @Nonnull T defaultValue)
ConfigLeafBuilder with the given default value.T - the type of value the ConfigLeaf produced by the builder holdsdefaultValue - the default value of the ConfigLeaf that will be produced by the created builder.ConfigLeafBuilder,
ConfigAggregateBuilderpublic <E> ConfigAggregateBuilder<E[],E> beginAggregateValue(@Nonnull java.lang.String name, @Nonnull E[] defaultValue)
ConfigLeafBuilder.E - the type of elements defaultValue holdsdefaultValue - the default array of values the ConfigLeaf will hold.Aggregatepublic <C extends java.util.Collection<E>,E> ConfigAggregateBuilder<C,E> beginAggregateValue(@Nonnull java.lang.String name, @Nonnull C defaultValue, @Nullable java.lang.Class<E> elementType)
ConfigLeafBuilder.C - the type of collection defaultValue isE - the type elementType representsdefaultValue - the default collection of values the ConfigLeaf will hold.elementType - the class of the type of elements defaultValue holdspublic ConfigTreeBuilder add(@Nonnull ConfigNode item) throws FiberException
item - The child to addFiberException - if there was already a child by the same namePropertypublic ConfigTreeBuilder add(@Nonnull ConfigNode item, boolean overwrite) throws FiberException
item - The child to addoverwrite - whether existing items should be overwrittenFiberException - if there was already a child by the same namePropertypublic ConfigNode remove(java.lang.String name)
name - the name of the child that should be removednullpublic ConfigTreeBuilder fork(java.lang.String name)
name - the name of the new Nodepublic ConfigBranch build()
ConfigNode based on this builder's specifications.
This method cannot be called more than once, as allowing multiple nodes to be built would result in duplicated references. To guard against this, usually undesirable, behaviour, this method will throw an exception on successive calls.
ConfigNodejava.lang.IllegalStateException - if this builder already built a nodepublic ConfigTreeBuilder finishNode()
public ConfigTreeBuilder finishNode(java.util.function.Consumer<ConfigBranch> action)