T - The type of value this class holdspublic class ConfigValue<T> extends ConfigLeaf implements Property<T>
ConfigLeaf with some value of type T.ConfigLeaf,
ConfigValueBuilder,
ConfigAggregateBuilder| Constructor and Description |
|---|
ConfigValue(java.lang.String name,
java.lang.String comment,
T defaultValue,
java.util.function.BiConsumer<T,T> listener,
java.util.List<Constraint<? super T>> constraints,
java.lang.Class<T> type)
Creates a
ConfigValue. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
accepts(T value)
Returns
true if this property can be set to the given value. |
java.util.List<Constraint<? super T>> |
getConstraints()
Returns the list of constraints for this item.
|
T |
getDefaultValue()
Returns the default value for this item.
|
java.util.function.BiConsumer<T,T> |
getListener()
Returns the listener for this item.
|
java.lang.Class<T> |
getType()
Returns the class of the type of the value being held
|
T |
getValue()
Returns the value being held
|
boolean |
setValue(T value)
Sets the value of this property.
|
getComment, getName, toStringpublic ConfigValue(@Nonnull
java.lang.String name,
@Nullable
java.lang.String comment,
@Nullable
T defaultValue,
@Nonnull
java.util.function.BiConsumer<T,T> listener,
@Nonnull
java.util.List<Constraint<? super T>> constraints,
@Nonnull
java.lang.Class<T> type)
ConfigValue.name - the name for this itemcomment - the comment for this itemdefaultValue - the default value for this item
While the default value should generally satisfy the supplied constraints,
this is not enforced by this constructor.
This allows constraints such as ConstraintType.FINAL to work as intended.
If this ConfigValue is built by a ConfigValueBuilder, this criterion will always be met.
listener - the consumer or listener for this item. When this item's value changes, the consumer will be called with the old value as first argument and the new value as second argument.constraints - the list of constraints for this item. For a value to be accepted, all constraints must be satisfied.type - the type of value this item holdsConfigValueBuilder,
ConfigAggregateBuilder@Nullable public T getValue()
HasValue@Nonnull public java.lang.Class<T> getType()
HasValuepublic boolean setValue(@Nullable
T value)
Property This can fail and return false if, for example, the value did not satisfy the constraints of the property.
setValue in interface Property<T>value - the new value this property should receivetrue if this property changed as a result of the callProperty.accepts(Object)public boolean accepts(@Nullable
T value)
true if this property can be set to the given value.
A value is accepted if it satisfies every constraint
this setting has. Note that some constraints such as FinalConstraint
will cause even the current value to be rejected.
accepts in interface Property<T>value - the value to checktrue if this property accepts the given value, false otherwise.setValue(Object),
getConstraints()@Nonnull public java.util.function.BiConsumer<T,T> getListener()
When this item's value changes, the consumer will be called with the old value as first argument and the new value as second argument.
@Nullable public T getDefaultValue()
@Nonnull public java.util.List<Constraint<? super T>> getConstraints()
For a call to setValue(T) to pass (and such, return true), the value must satisfy all constraints in this list.