public final class ConfigLeafImpl<T> extends ConfigNodeImpl implements ConfigLeaf<T>
| Constructor and Description |
|---|
ConfigLeafImpl(String name,
SerializableType<T> type,
String comment,
T defaultValue,
BiConsumer<T,T> listener)
Creates a
ConfigLeaf. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
accepts(T value)
Returns
true if this property can be set to the given raw value. |
void |
addChangeListener(BiConsumer<T,T> listener) |
SerializableType<T> |
getConfigType() |
T |
getDefaultValue()
Returns the default value for this item.
|
BiConsumer<T,T> |
getListener()
Returns the listener for this item.
|
T |
getValue()
Returns this
ConfigLeaf's current value. |
boolean |
setValue(T value)
Sets the value held by this
ConfigLeaf. |
String |
toString() |
attachTo, detach, getAttributes, getAttributeValue, getAttributeValue, getComment, getName, getOrCreateAttribute, getParentclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetTypeattachTo, detach, getAttributes, getAttributeValue, getAttributeValue, getName, getOrCreateAttribute, getParentgetCommentpublic ConfigLeafImpl(@Nonnull String name, @Nonnull SerializableType<T> type, @Nullable String comment, @Nonnull T defaultValue, @Nonnull BiConsumer<T,T> listener)
ConfigLeaf.name - the name for this nodetype - the type of value this item holdscomment - the comment for this nodedefaultValue - the default value for this nodelistener - 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.ConfigLeafBuilder@Nonnull 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.
public SerializableType<T> getConfigType()
getConfigType in interface ConfigLeaf<T>public boolean accepts(@Nonnull T value)
ConfigLeaftrue if this property can be set to the given raw value.
This method does not account for possible corrections offered by the type's constraints.
In other words, it returns true if and only if every constraint of this property's
config type accepts the given value as is.
accepts in interface ConfigLeaf<T>accepts in interface Property<T>value - the value to checktrue if this property accepts the given value, false otherwise.SerializableType.accepts(Object)public boolean setValue(@Nonnull T value)
ConfigLeafConfigLeaf.
If the provided value does not satisfy this setting's type constraints:
true. 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)@Nonnull public 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>public void addChangeListener(BiConsumer<T,T> listener)
addChangeListener in interface ConfigLeaf<T>@Nonnull public T getDefaultValue()
ConfigLeafgetDefaultValue in interface ConfigLeaf<T>public String toString()
toString in class ConfigNodeImpl