public class ConfigTreeBuilder extends ConfigNodeBuilder implements ConfigTree
Usage example:
ConfigBranch config = ConfigTree.builder()
.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(),
PropertyMirrorattributes, parent| Constructor and Description |
|---|
ConfigTreeBuilder(ConfigTree parent,
java.lang.String name)
Creates a new builder with initial settings.
|
| Modifier and Type | Method and Description |
|---|---|
ConfigTreeBuilder |
applyFromPojo(java.lang.Object pojo)
Configure this builder using a POJO (Plain Old Java Object).
|
ConfigTreeBuilder |
applyFromPojo(java.lang.Object pojo,
AnnotatedSettings settings)
Configure this builder using a POJO (Plain Old Java Object).
|
<C extends java.util.Collection<E>,E> |
beginAggregateValue(java.lang.String name,
java.lang.Class<? super C> collectionType,
java.lang.Class<E> elementType,
C defaultValue)
Creates an aggregate
ConfigLeafBuilder. |
<E> ConfigAggregateBuilder<E[],E> |
beginAggregateValue(java.lang.String name,
E[] defaultValue)
Creates an aggregate
ConfigLeafBuilder. |
<E> ConfigAggregateBuilder<java.util.List<E>,E> |
beginListValue(java.lang.String name,
java.lang.Class<E> elementType,
E... defaultValues)
Creates a
ConfigAggregateBuilder for a List settings with the given default elements. |
<E> ConfigAggregateBuilder<java.util.Set<E>,E> |
beginSetValue(java.lang.String name,
java.lang.Class<E> elementType,
E... defaultElements)
Creates a
ConfigAggregateBuilder for a Set settings with the given default elements. |
<T> ConfigLeafBuilder<T> |
beginValue(java.lang.String name,
java.lang.Class<T> type,
T defaultValue)
Creates a scalar
ConfigLeafBuilder with the given default value. |
ConfigBranch |
build()
Construct a new
ConfigNode based on this builder's specifications. |
ConfigTreeBuilder |
finishBranch() |
ConfigTreeBuilder |
finishBranch(java.util.function.Consumer<ConfigBranch> action) |
ConfigTreeBuilder |
fork(java.lang.String name)
Forks this builder, creating a subtree whose parent is this node.
|
NodeCollection |
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.
|
<A> ConfigTreeBuilder |
withAttribute(FiberId id,
java.lang.Class<A> type,
A defaultValue)
Adds a
ConfigAttribute to the built ConfigBranch. |
ConfigTreeBuilder |
withChild(ConfigNode item)
Attempts to introduce a new child to this builder.
|
ConfigTreeBuilder |
withChild(ConfigNode item,
boolean overwrite)
Attempts to introduce a new child to this builder.
|
ConfigTreeBuilder |
withComment(java.lang.String comment)
Sets the
ConfigBranch's comment. |
ConfigTreeBuilder |
withName(java.lang.String name)
Sets the
ConfigBranch's 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.
|
<T> ConfigTreeBuilder |
withValue(java.lang.String name,
java.lang.Class<T> type,
T defaultValue)
Adds a
ConfigLeaf with the given type and default value to the tree. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbuilder, builderpublic ConfigTreeBuilder(@Nullable
ConfigTree parent,
@Nullable
java.lang.String name)
parent - the initial parentname - the initial nameConfigTree.builder(),
ConfigTree.builder(ConfigTree, String)@Nonnull public NodeCollection getItems()
The returned collection is guaranteed to have no two nodes with the same name. Elements may be freely added and removed from it.
getItems in interface ConfigTreeNodeCollection.add(ConfigNode, boolean),
NodeCollection.removeByName(String)@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)
ConfigBranch's name.withName in class ConfigNodeBuildername - the namethis builderConfigTree.lookup(java.lang.String)public ConfigTreeBuilder withComment(@Nullable java.lang.String comment)
ConfigBranch's comment.
If null, or if this method is never called, the ConfigLeaf won't have a comment.
An empty comment (non null, but only consisting of whitespace) will be serialised.
withComment in class ConfigNodeBuildercomment - the commentthis builderpublic <A> ConfigTreeBuilder withAttribute(FiberId id, java.lang.Class<A> type, A defaultValue)
ConfigAttribute to the built ConfigBranch.withAttribute in class ConfigNodeBuilderA - the type of values stored in the attributeid - the id of the attributetype - the class object representing the type of values stored in the attributedefaultValue - the attribute's default valuethis, for chainingConfigNode.getAttributes()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 chainingFiberExceptionSetting,
Settings,
AnnotatedSettings.applyToNode(ConfigTree, Object)public ConfigTreeBuilder applyFromPojo(java.lang.Object pojo, AnnotatedSettings settings) 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 treesettings - an AnnotatedSettings instance used to configure this builderthis, for chainingFiberException@Setting,
@Settings,
AnnotatedSettings.applyToNode(ConfigTree, Object)public <T> ConfigLeafBuilder<T> beginValue(@Nonnull java.lang.String name, @Nonnull java.lang.Class<T> type, @Nullable T defaultValue)
ConfigLeafBuilder with the given default value.T - the type type representstype - the class of the type of value the ConfigLeaf produced by the builder holdsConfigLeafBuilder,
withValue(String, Class, Object),
beginAggregateValue(String, Object[]),
beginAggregateValue(String, Class, Class, Collection),
beginListValue(String, Class, Object[]),
beginSetValue(String, Class, Object[])public <T> ConfigTreeBuilder withValue(@Nonnull java.lang.String name, @Nonnull java.lang.Class<T> type, @Nullable T defaultValue)
ConfigLeaf with the given type and default value to the tree.
This method allows only basic configuration of the created leaf.
For more flexibility, one of the begin*Value methods can be used.
T - the type of value the ConfigLeaf holds.name - the name of the child leaftype - the type of values held by the leafdefaultValue - the default value of the ConfigLeaf to create.this, for chainingbeginValue(String, Class, Object),
beginAggregateValue(String, Object[]),
beginAggregateValue(String, Class, Class, Collection),
beginListValue(String, Class, Object[]),
beginSetValue(String, Class, Object[])public <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 <E> ConfigAggregateBuilder<java.util.List<E>,E> beginListValue(@Nonnull java.lang.String name, java.lang.Class<E> elementType, E... defaultValues)
ConfigAggregateBuilder for a List settings with the given default elements.
This method should not be called by intermediary generic methods
(eg. <T> void f(ConfigTreeBuilder b, T t) {b.beginListValue("", t);}),
as it will prevent type checking while building the tree.
Use beginAggregateValue(String, Class, Class, Collection) in those cases instead.
E - the type of elements contained by the setdefaultValues - the default values of thepublic <E> ConfigAggregateBuilder<java.util.Set<E>,E> beginSetValue(@Nonnull java.lang.String name, java.lang.Class<E> elementType, E... defaultElements)
ConfigAggregateBuilder for a Set settings with the given default elements.E - the type of elements contained by the setdefaultElements - the elements contained by default in the set settingpublic <C extends java.util.Collection<E>,E> ConfigAggregateBuilder<C,E> beginAggregateValue(@Nonnull java.lang.String name, @Nonnull java.lang.Class<? super C> collectionType, @Nullable java.lang.Class<E> elementType, @Nonnull C defaultValue)
ConfigLeafBuilder.C - the type of collection defaultValue isE - the type elementType representscollectionType - the class object representing the type of collection to create a setting forelementType - the class object representing the type of elements defaultValue holdsdefaultValue - the default collection of values the ConfigLeaf will hold.public ConfigTreeBuilder withChild(@Nonnull ConfigNode item) throws DuplicateChildException
item - The child to addthis, for chainingDuplicateChildException - if there was already a child by the same namePropertypublic ConfigTreeBuilder withChild(@Nonnull ConfigNode item, boolean overwrite) throws DuplicateChildException
item - The child to addoverwrite - whether existing items should be overwrittenthis, for chainingDuplicateChildException - if there was already a child by the same namepublic ConfigTreeBuilder fork(java.lang.String name)
name - the name of the new Nodepublic ConfigBranch build() throws RuntimeFiberException
ConfigNode based on this builder's specifications.
Calling this method more than once with the same parameters (specifically same parent and/or children) may result in exceptions being thrown, as the resulting tree structure will be invalid.
build in class ConfigNodeBuilderConfigNodeRuntimeFiberException - if building the node results in an invalid treepublic ConfigTreeBuilder finishBranch()
public ConfigTreeBuilder finishBranch(java.util.function.Consumer<ConfigBranch> action)