Class Property<T>
java.lang.Object
org.polyfrost.oneconfig.api.config.v1.Node
org.polyfrost.oneconfig.api.config.v1.Property<T>
- Type Parameters:
T-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
Property.KtProperty
Class which represents a property in a tree.
to actually create a property, see the
to actually create a property, see the
Properties class.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic final classDeprecated. -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal @NotNull Class<?> This is the type of the property, and is used for casting.Fields inherited from class org.polyfrost.oneconfig.api.config.v1.Node
description, LOGGER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddCallback(@NotNull Collection<Predicate<T>> callbacks) addCallback(@NotNull Predicate<T> callback) Add a callback to this property, which is called when the value changes.addCallback(@NotNull Predicate<T>... callbacks) addDisplayCondition(@NotNull Collection<Supplier<Property.Display>> conditions) addDisplayCondition(@NotNull Supplier<Property.Display> condition) Add a display condition to this property.addDisplayCondition(@NotNull Supplier<Property.Display>... conditions) addDisplayCondition(@NotNull Property<Boolean> condition, boolean hides) final booleanThis is used by the frontend to know if this property is able to be displayed, which is controlled byconditions.protected final voidRemove all callbacks.protected final voidRemove all display conditions from this property.booleandeepEquals(Object obj) Deep equals for a property, meaning it will checkequals(Object)and the value of this property with the given obj.final booleanabstract Tget()Get the value of this property.final <V> VgetAs()Get the value of this property, cast to the specified type.final booleanisArray()final booleanvoidonDisplayChange(Consumer<Property.Display> callback) voidOverwrite all data in this node with the data from another node.static <T> Property<T> final booleanremoveCallback(@NotNull Predicate<T> callback) voidfinal booleanSet the value of this property.protected abstract voidfinal <V> booleansetAs(V value) Set the value of this property.final <V> booleansetAsReferential(V value) Set the value of this property.booleansetReferential(T value) Set the value of this property.final StringtoString()Methods inherited from class org.polyfrost.oneconfig.api.config.v1.Node
addMetadata, addMetadata, clearMetadata, consumeMetadata, getID, getMetadata, getMetadata, getOrPutMetadata, getTitle, hashCode, hasMetadata, overwrite, removeMetadata, setID, setTitle, strv
-
Field Details
-
type
This is the type of the property, and is used for casting.
Note that this is notClass<T>. this is because it holds the unwrapped type of the stored value. -
callbacks
-
-
Constructor Details
-
Property
-
-
Method Details
-
recast
-
canDisplay
public final boolean canDisplay()This is used by the frontend to know if this property is able to be displayed, which is controlled byconditions.- See Also:
-
onDisplayChange
-
addDisplayCondition
public final Property<T> addDisplayCondition(@NotNull @NotNull Supplier<Property.Display> condition) Add a display condition to this property. -
addDisplayCondition
-
addDisplayCondition
@SafeVarargs public final Property<T> addDisplayCondition(@NotNull @NotNull Supplier<Property.Display>... conditions) -
addDisplayCondition
public final Property<T> addDisplayCondition(@NotNull @NotNull Collection<Supplier<Property.Display>> conditions) -
revaluateDisplay
public void revaluateDisplay() -
clearDisplayConditions
protected final void clearDisplayConditions()Remove all display conditions from this property. -
addCallback
Add a callback to this property, which is called when the value changes.- Parameters:
callback- the callback to add. The new value is passed to the callback. Return true if you wish to cancel the setting of the property.
-
addCallback
-
addCallback
-
removeCallback
-
overwrite
public void overwrite(Node with, boolean preserveMissingOptions, boolean skipOverwritten, @Nullable @Nullable Tree root) Description copied from class:NodeOverwrite all data in this node with the data from another node.- Specified by:
overwritein classNode- Parameters:
with- the node to overwrite this withpreserveMissingOptions- if true, any properties that are missing in THIS tree that are present in the input tree, will be added to this tree.skipOverwritten- **DEPENDS ON PARAM "ROOT" BEING NOT NULL** - skips being overwritten if a child node has already been marked as overwritten in the root tree.root- The root tree used to mark overwritten nodes for skipOverwritten. May be null if skipOverwritten is false.
-
clearCallbacks
protected final void clearCallbacks()Remove all callbacks. -
set
Set the value of this property. This will call all callbacks.
The value (and callbacks) are only set/called if the value is different from the previous value (usingObject.equals(Object)). -
setReferential
Set the value of this property. This will call all callbacks.
Unlikeset(Object), this will always set the value, regardless of if it is the same as the previous value. Use this method with caution. -
set0
-
toString
-
get
Get the value of this property. -
getAs
public final <V> V getAs()Get the value of this property, cast to the specified type. This method is unsafe, and will throw aClassCastExceptionif the value is not of the correct type. -
setAs
public final <V> boolean setAs(V value) Set the value of this property. This will call all callbacks. This method is unsafe, and will throw aClassCastExceptionif the value is not of the correct type. -
setAsReferential
public final <V> boolean setAsReferential(V value) Set the value of this property. This will call all callbacks.
UnlikesetAs(Object), this will always set the value, regardless of if it is the same as the previous value. Use this method with caution. -
deepEquals
Deep equals for a property, meaning it will checkequals(Object)and the value of this property with the given obj.
In pretty much every case, you should useequals(Object)instead. This is used for testing. Note that primitive arrays are not checked.- Specified by:
deepEqualsin classNode
-
equals
-
isPrimitive
public final boolean isPrimitive()- Returns:
- true if the value is a primitive array.
-
isArray
public final boolean isArray()- Returns:
- true if the value is an array.
-