T - the type of value the produced ConfigLeaf will holdpublic class ConfigLeafBuilder<T> extends ConfigNodeBuilder
ConfigLeafs.
The settings created by this builder are considered atomic, and do not allow specifications at the component level.
Settings with aggregate types, such as arrays and collections, should be created using ConfigAggregateBuilder.
ConfigLeaf| Modifier and Type | Field and Description |
|---|---|
protected java.util.List<Constraint<? super T>> |
constraintList |
protected java.lang.Class<T> |
type |
attributes, comment, name, parent| Constructor and Description |
|---|
ConfigLeafBuilder(ConfigTreeBuilder parentNode,
java.lang.String name,
java.lang.Class<T> type)
Creates a new scalar
ConfigLeafBuilder. |
| Modifier and Type | Method and Description |
|---|---|
ConstraintsBuilder<T> |
beginConstraints()
Creates a constraint builder for this
ConfigLeafBuilder. |
ConfigLeaf<T> |
build()
Builds the
ConfigLeaf. |
ConfigTreeBuilder |
finishValue() |
ConfigTreeBuilder |
finishValue(java.util.function.Consumer<ConfigLeaf<T>> action) |
java.lang.Class<T> |
getType() |
<A> ConfigLeafBuilder<T> |
withAttribute(FiberId id,
java.lang.Class<A> type,
A defaultValue)
Adds a
ConfigAttribute to the built ConfigLeaf. |
ConfigLeafBuilder<T> |
withComment(java.lang.String comment)
Sets the
ConfigLeaf's comment. |
ConfigLeafBuilder<T> |
withDefaultValue(T defaultValue)
Sets the default value.
|
ConfigLeafBuilder<T> |
withFinality()
Marks a setting as final.
|
ConfigLeafBuilder<T> |
withFinality(boolean isFinal)
Sets the finality.
|
ConfigLeafBuilder<T> |
withListener(java.util.function.BiConsumer<T,T> consumer)
Adds a listener to the
ConfigLeaf. |
ConfigLeafBuilder<T> |
withName(java.lang.String name)
Sets the
ConfigLeaf's name. |
withAttribute, withAttributes@Nonnull protected final java.lang.Class<T> type
protected java.util.List<Constraint<? super T>> constraintList
public ConfigLeafBuilder(ConfigTreeBuilder parentNode, @Nonnull java.lang.String name, @Nonnull java.lang.Class<T> type)
ConfigLeafBuilder.parentNode - the ConfigTreeBuilder this builder originates fromname - the name of the ConfigLeaf produced by this buildertype - the class object representing the type of values this builder will create settings for@Nonnull public java.lang.Class<T> getType()
public ConfigLeafBuilder<T> withName(@Nonnull java.lang.String name)
ConfigLeaf's name.withName in class ConfigNodeBuildername - the namethis builderConfigTree.lookup(java.lang.String)public ConfigLeafBuilder<T> withComment(java.lang.String comment)
ConfigLeaf'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> ConfigLeafBuilder<T> withAttribute(FiberId id, java.lang.Class<A> type, A defaultValue)
ConfigAttribute to the built ConfigLeaf.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 ConfigLeafBuilder<T> withListener(java.util.function.BiConsumer<T,T> consumer)
ConfigLeaf.
Listeners are called when the value of a ConfigLeaf is changed. They are of type BiConsumer: the first argument being the old value, and the second argument being the new value.
Listeners set with this method are chained: if there was already one specified, a new listener is created that calls the old one first, and then the new one.
consumer - the listenerthis builderpublic ConfigLeafBuilder<T> withDefaultValue(T defaultValue)
If null, or if this method is never called, the ConfigLeaf will have no default value.
Note that every ConfigLeaf created from this builder will share a reference
to the given defaultValue. Immutability is encouraged.
defaultValue - the default valuethis builderpublic ConfigLeafBuilder<T> withFinality()
As a result of this method, any attempt to update the value of the resulting setting will fail.
This method behaves as if: this.setFinal(true).
this builderwithFinality(boolean)public ConfigLeafBuilder<T> withFinality(boolean isFinal)
If true, the produced setting can not be changed.
It will be initialised with its default value, if there is one. Afterwards, it can not be changed again;
ConfigLeaf.setValue(Object) will always return false.
isFinal - whether or not the value can be changed after buildingthis builderpublic ConstraintsBuilder<T> beginConstraints()
ConfigLeafBuilder.ConstraintsBuilderpublic ConfigLeaf<T> build()
ConfigLeaf.
If a parent was specified in the constructor, the ConfigLeaf will also be registered to its parent node.
This method should not be called multiple times if the default value is intended to be mutated. Multiple calls will result in duplicated references to the default value.
build in class ConfigNodeBuilderConfigLeafpublic ConfigTreeBuilder finishValue()
public ConfigTreeBuilder finishValue(java.util.function.Consumer<ConfigLeaf<T>> action)