T - the type of value the produced ConfigValue will holdpublic class ConfigValueBuilder<T>
extends java.lang.Object
ConfigValues.
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.
ConfigValue| Modifier and Type | Field and Description |
|---|---|
protected java.util.List<Constraint<? super T>> |
constraintList |
protected java.lang.Class<T> |
type |
| Constructor and Description |
|---|
ConfigValueBuilder(java.lang.String name,
java.lang.Class<T> type)
Creates a new scalar
ConfigValueBuilder. |
| Modifier and Type | Method and Description |
|---|---|
ConfigValue<T> |
build()
Builds the
ConfigValue. |
ConstraintsBuilder<? extends ConfigValueBuilder<T>,T> |
constraints()
Creates a constraint builder for this
ConfigValueBuilder. |
ConfigValueBuilder<T> |
setFinal()
Marks a setting as final.
|
ConfigValueBuilder<T> |
setFinal(boolean isFinal)
Sets the finality.
|
ConfigValueBuilder<T> |
withComment(java.lang.String comment)
Sets the
ConfigValue's comment. |
ConfigValueBuilder<T> |
withDefaultValue(T defaultValue)
Sets the default value.
|
ConfigValueBuilder<T> |
withListener(java.util.function.BiConsumer<T,T> consumer)
Adds a listener to the
ConfigValue. |
ConfigValueBuilder<T> |
withName(java.lang.String name)
Sets the
ConfigValue's name. |
ConfigValueBuilder<T> |
withParent(Node node)
Sets the node that the
ConfigValue will be registered to. |
@Nonnull protected final java.lang.Class<T> type
protected java.util.List<Constraint<? super T>> constraintList
public ConfigValueBuilder(@Nonnull
java.lang.String name,
@Nonnull
java.lang.Class<T> type)
ConfigValueBuilder.name - the name of the ConfigValue produced by this buildertype - the class object representing the type of values this builder will create settings forpublic ConfigValueBuilder<T> withName(java.lang.String name)
ConfigValue's name.
If null, or if this method is never called, the ConfigValue won't have a name. Thus, it might be ignored during (de)serialisation. It also won't be able to be found by name in its parent node.
name - the namethis builderNode.lookup(java.lang.String)public ConfigValueBuilder<T> withComment(java.lang.String comment)
ConfigValue's comment.
If null, or if this method is never called, the ConfigValue won't have a comment. An empty comment (non null, but only consisting of whitespace) will be serialised.
comment - the commentthis builderpublic ConfigValueBuilder<T> withListener(java.util.function.BiConsumer<T,T> consumer)
ConfigValue.
Listeners are called when the value of a ConfigValue 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 ConfigValueBuilder<T> withDefaultValue(T defaultValue)
If null, or if this method is never called, the ConfigValue will have no default value.
defaultValue - the default valuethis builderpublic ConfigValueBuilder<T> setFinal()
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 buildersetFinal(boolean)public ConfigValueBuilder<T> setFinal(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.
isFinal - the finalitythis builderpublic ConfigValueBuilder<T> withParent(Node node)
ConfigValue will be registered to.node - The node the ConfigValue will be registered to.public ConstraintsBuilder<? extends ConfigValueBuilder<T>,T> constraints()
ConfigValueBuilder.ConstraintsBuilderpublic ConfigValue<T> build()
ConfigValue.
If a parent was specified using withParent(me.zeroeightsix.fiber.tree.Node), the ConfigValue will also be registered to its parent node.
ConfigValue