T - the type of value the produced ConfigValue will holdB - the type of thispublic abstract class ConfigValueBuilder<T,B extends ConfigValueBuilder<T,B>>
extends java.lang.Object
ConfigValues.
This is the abstract base class for all builders of this type. Builders implementing this class include
Scalar and Aggregate for scalar (one-value) and aggregate (collection/array) values, respectively.
ConfigValue| Modifier and Type | Class and Description |
|---|---|
static class |
ConfigValueBuilder.Aggregate<A,E>
A
ConfigValueBuilder that produces aggregate ConfigValues. |
static class |
ConfigValueBuilder.Scalar<T>
A
ConfigValueBuilder that produces scalar ConfigValues. |
| Modifier and Type | Field and Description |
|---|---|
protected java.util.List<Constraint<? super T>> |
constraintList |
protected java.lang.Class<T> |
type |
| Modifier and Type | Method and Description |
|---|---|
static <C extends java.util.Collection<E>,E> |
aggregate(java.lang.Class<? super C> collectionType,
java.lang.Class<E> componentType)
Creates and returns an
aggregate builder for a collection type. |
static <E> ConfigValueBuilder.Aggregate<E[],E> |
aggregate(java.lang.Class<E[]> arrayType)
Creates and returns an
aggregate builder for an array type. |
ConfigValue<T> |
build()
Builds the
ConfigValue. |
abstract ConstraintsBuilder<B,T,?> |
constraints()
Creates a constraint builder for this
ConfigValueBuilder. |
static boolean |
isAggregate(java.lang.Class<?> type)
Determines if a
Class object represents an aggregate type,
ie. |
static <T> ConfigValueBuilder.Scalar<T> |
scalar(java.lang.Class<T> type)
Creates and returns a scalar
ConfigValueBuilder. |
protected B |
self() |
B |
setFinal()
Marks a setting as final.
|
B |
setFinal(boolean isFinal)
Sets the finality.
|
B |
withComment(java.lang.String comment)
Sets the
ConfigValue's comment. |
B |
withDefaultValue(T defaultValue)
Sets the default value.
|
B |
withListener(java.util.function.BiConsumer<T,T> consumer)
Adds a listener to the
ConfigValue. |
B |
withName(java.lang.String name)
Sets the
ConfigValue's name. |
B |
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 static boolean isAggregate(java.lang.Class<?> type)
Class object represents an aggregate type,
ie. if it is an Array or a Collection.type - the type to checktrue if type is an aggregate type;
false otherwisepublic static <E> ConfigValueBuilder.Aggregate<E[],E> aggregate(@Nonnull java.lang.Class<E[]> arrayType)
aggregate builder for an array type.E - the type of values held by arrayTypearrayType - the class of the array used for this aggregate builderisAggregate(java.lang.Class<?>)public static <C extends java.util.Collection<E>,E> ConfigValueBuilder.Aggregate<C,E> aggregate(@Nonnull java.lang.Class<? super C> collectionType, @Nonnull java.lang.Class<E> componentType)
aggregate builder for a collection type.C - the type collectionType represents. eg. ListE - the type componentType represents. eg. IntegercollectionType - the class of the collection used for this aggregate buildercomponentType - the class of the type of elements collectionType holdspublic static <T> ConfigValueBuilder.Scalar<T> scalar(java.lang.Class<T> type)
ConfigValueBuilder.T - the type type represents. For example, this could be Integertype - the class of the type used for this builderConfigValueBuilder.Scalarpublic B 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 B 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 B 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 B withDefaultValue(T defaultValue)
If null, or if this method is never called, the ConfigValue will have no default value.
defaultValue - the default valuethis builderpublic B 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 B 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 B withParent(Node node)
ConfigValue will be registered to.node - The node the ConfigValue will be registered to.protected final B self()
public abstract ConstraintsBuilder<B,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