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(ConfigNodeBuilder parentNode,
java.lang.String name,
java.lang.Class<T> type)
Creates a new scalar
ConfigValueBuilder. |
| Modifier and Type | Method and Description |
|---|---|
ConstraintsBuilder<T> |
beginConstraints()
Creates a constraint builder for this
ConfigValueBuilder. |
ConfigValue<T> |
build()
Builds the
ConfigValue. |
ConfigNodeBuilder |
finishValue() |
ConfigNodeBuilder |
finishValue(java.util.function.Consumer<ConfigValue<T>> action) |
ConfigValueBuilder<T> |
withComment(java.lang.String comment)
Sets the
ConfigValue's comment. |
ConfigValueBuilder<T> |
withDefaultValue(T defaultValue)
Sets the default value.
|
ConfigValueBuilder<T> |
withFinality()
Marks a setting as final.
|
ConfigValueBuilder<T> |
withFinality(boolean isFinal)
Sets the finality.
|
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. |
@Nonnull protected final java.lang.Class<T> type
protected java.util.List<Constraint<? super T>> constraintList
public ConfigValueBuilder(ConfigNodeBuilder parentNode, @Nonnull java.lang.String name, @Nonnull java.lang.Class<T> type)
ConfigValueBuilder.parentNode - the ConfigNodeBuilder this builder originates fromname - 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.
Note that every ConfigValue created from this builder will share a reference
to the given defaultValue. Immutability is encouraged.
defaultValue - the default valuethis builderpublic ConfigValueBuilder<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 ConfigValueBuilder<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;
ConfigValue.setValue(Object) will always return false.
isFinal - whether or not the value can be changed after buildingthis builderpublic ConstraintsBuilder<T> beginConstraints()
ConfigValueBuilder.ConstraintsBuilderpublic ConfigValue<T> build()
ConfigValue.
If a parent was specified in the constructor, the ConfigValue 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.
ConfigValuepublic ConfigNodeBuilder finishValue()
public ConfigNodeBuilder finishValue(java.util.function.Consumer<ConfigValue<T>> action)