Class Property<T>
java.lang.Object
org.polyfrost.oneconfig.api.config.v1.Node
org.polyfrost.oneconfig.api.config.v1.Property<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
Note that this is notClass<T>because it holds the unwrapped type of the stored valueFields 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 changesaddCallback(@NotNull Predicate<T>... callbacks) addDisplayCondition(@NotNull Collection<Supplier<Property.Display>> conditions) addDisplayCondition(@NotNull Supplier<Property.Display> condition) addDisplayCondition(@NotNull Supplier<Property.Display>... conditions) addDisplayCondition(@NotNull Property<Boolean> condition, boolean hides) final voidaddDisplayListener(@NotNull Consumer<Property.Display> listener) Add a listener which is called whenever the display state of this property changes
UnlikeonDisplayChange(Consumer)any amount of listeners can be registered at once
Remember toremovethe listener when it is no longer neededfinal booleanThis is used by the frontend to know if this property is able to be displayed which is controlled byconditionsprotected final voidprotected final voidbooleandeepEquals(Object obj) Deep equals for a property meaning it checksequals(Object)and the value of this property against the given obj
In pretty much every case you should useequals(Object)instead
This is used for testing
Note that primitive arrays are not checkedfinal booleanabstract Tget()final <V> VgetAs()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 typefinal @NotNull Property.DisplayReturn the current display state of this property which is controlled byconditionsfinal booleanisArray()final booleanvoidonDisplayChange(Consumer<Property.Display> callback) voidOverwrite all data in this node with the data from another node
For a node all metadata will be copied from the input onto this and any duplicate keys will be overwritten For aPropertythe value and callbacks and display conditions are copied onto this For aTreeall children and properties will be overwritten if they are present and this operation is recursivestatic <T> Property<T> final booleanremoveCallback(@NotNull Predicate<T> callback) final booleanremoveDisplayListener(@NotNull Consumer<Property.Display> listener) voidfinal booleanSet the value of this property and call all callbacks
The value is only set and the callbacks only called if the value differs from the previous value usingObject.equals(Object)protected abstract voidfinal <V> booleansetAs(V value) Set the value of this property and call all callbacks
This method is unsafe and will throw aClassCastExceptionif the value is not of the correct typefinal <V> booleansetAsReferential(V value) Set the value of this property and call all callbacks
UnlikesetAs(Object)this will always set the value even if it is the same as the previous value
Use this method with cautionfinal <V> voidsetAsSilently(V value) booleansetReferential(T value) Set the value of this property and call all callbacks
Unlikeset(Object)this will always set the value even if it is the same as the previous value
Use this method with cautionfinal 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>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:
-
getDisplay
Return the current display state of this property which is controlled byconditions- See Also:
-
onDisplayChange
-
addDisplayListener
Add a listener which is called whenever the display state of this property changes
UnlikeonDisplayChange(Consumer)any amount of listeners can be registered at once
Remember toremovethe listener when it is no longer needed -
removeDisplayListener
-
addDisplayCondition
public final Property<T> addDisplayCondition(@NotNull @NotNull Supplier<Property.Display> condition) -
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() -
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- For a node all metadata will be copied from the input onto this and any duplicate keys will be overwritten
- For a
Propertythe value and callbacks and display conditions are copied onto this - For a
Treeall children and properties will be overwritten if they are present and this operation is recursive
- Specified by:
overwritein classNode- Parameters:
with- the node to overwrite this withpreserveMissingOptions- if true then any properties missing in THIS tree that are present in the input tree will be added to this treeskipOverwritten- **DEPENDS ON PARAM "ROOT" BEING NOT NULL** skips being overwritten if a child node has already been marked as overwritten in the root treeroot- The root tree used to mark overwritten nodes for skipOverwritten
May be null if skipOverwritten is false
-
clearCallbacks
protected final void clearCallbacks() -
set
Set the value of this property and call all callbacks
The value is only set and the callbacks only called if the value differs from the previous value usingObject.equals(Object) -
setReferential
Set the value of this property and call all callbacks
Unlikeset(Object)this will always set the value even if it is the same as the previous value
Use this method with caution -
set0
-
toString
-
get
-
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 and 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 and call all callbacks
UnlikesetAs(Object)this will always set the value even if it is the same as the previous value
Use this method with caution -
setAsSilently
public final <V> void setAsSilently(V value) -
deepEquals
Deep equals for a property meaning it checksequals(Object)and the value of this property against 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()
-