public class ConfigLeafImpl<T> extends ConfigNodeImpl implements ConfigLeaf<T>
| Constructor and Description |
|---|
ConfigLeafImpl(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
ConfigLeaf. |
| 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 a class object representing the type of values this node can hold.
|
T |
getValue()
Returns this
ConfigLeaf's current value. |
boolean |
setValue(T value)
Sets the value held by this
ConfigLeaf. |
java.lang.String |
toString() |
getComment, getNameclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetNamegetCommentpublic ConfigLeafImpl(@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)
ConfigLeaf.name - the name for this nodecomment - the comment for this nodedefaultValue - the default value for this node
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 ConfigLeaf is built by a ConfigLeafBuilder, 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 holdsConfigLeafBuilder,
ConfigAggregateBuilder@Nullable public T getValue()
ConfigLeafConfigLeaf's current value.
If no successful call to ConfigLeaf.setValue(Object) has been made,
this method returns this node's default value.
@Nonnull public java.lang.Class<T> getType()
ConfigLeafThe returned class object can be used for various runtime type checks, as well as constraint configuration.
public boolean setValue(@Nullable
T value)
ConfigLeafConfigLeaf.
If the value does not satisfy this setting's constraints,
the current value is not updated and the method returns false.
setValue in interface ConfigLeaf<T>setValue in interface Property<T>value - the new value this ConfigLeaf should holdtrue if this property changed as a result of the call, and false otherwise.ConfigLeaf.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.
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 ConfigLeaf<T>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()
ConfigLeafWhen this item's value changes, the consumer will be called with the old value as first argument and the new value as second argument.
getListener in interface ConfigLeaf<T>@Nullable public T getDefaultValue()
ConfigLeafgetDefaultValue in interface ConfigLeaf<T>@Nonnull public java.util.List<Constraint<? super T>> getConstraints()
ConfigLeaf For a call to ConfigLeaf.setValue(T) to pass (and such, return true), the value must satisfy all constraints in this list.
getConstraints in interface ConfigLeaf<T>public java.lang.String toString()
toString in class ConfigNodeImpl