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

public abstract class Property<T> extends Node implements Serializable
Class which represents a property in a tree
to actually create a property see the Properties class
See Also:
  • Field Details

    • type

      @NotNull public final transient @NotNull Class<?> type
      This is the type of the property and is used for casting
      Note that this is not Class<T> because it holds the unwrapped type of the stored value
    • callbacks

      protected transient List<@NotNull Predicate<@Nullable T>> callbacks
  • Constructor Details

    • Property

      protected Property(@Nullable @Nullable String id, @Nullable @Nullable Object title, @Nullable @Nullable Object description, @NotNull @NotNull Class<T> type)
  • Method Details

    • recast

      public static <T> Property<T> recast(@NotNull @NotNull Property<?> prop)
    • canDisplay

      public final boolean canDisplay()
      This is used by the frontend to know if this property is able to be displayed which is controlled by conditions
      See Also:
    • getDisplay

      @NotNull public final @NotNull Property.Display getDisplay()
      Return the current display state of this property which is controlled by conditions
      See Also:
    • onDisplayChange

      public void onDisplayChange(Consumer<Property.Display> callback)
    • addDisplayListener

      public final void addDisplayListener(@NotNull @NotNull Consumer<Property.Display> listener)
      Add a listener which is called whenever the display state of this property changes
      Unlike onDisplayChange(Consumer) any amount of listeners can be registered at once
      Remember to remove the listener when it is no longer needed
    • removeDisplayListener

      public final boolean removeDisplayListener(@NotNull @NotNull Consumer<Property.Display> listener)
    • addDisplayCondition

      public final Property<T> addDisplayCondition(@NotNull @NotNull Supplier<Property.Display> condition)
    • addDisplayCondition

      public final Property<T> addDisplayCondition(@NotNull @NotNull Property<Boolean> condition, boolean hides)
    • 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

      public final Property<T> addCallback(@NotNull @NotNull Predicate<T> callback)
      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

      @SafeVarargs public final Property<T> addCallback(@NotNull @NotNull Predicate<T>... callbacks)
    • addCallback

      public final Property<T> addCallback(@NotNull @NotNull Collection<Predicate<T>> callbacks)
    • removeCallback

      public final boolean removeCallback(@NotNull @NotNull Predicate<T> callback)
    • removeCallbackIf

      @Experimental public final boolean removeCallbackIf(@NotNull @NotNull Predicate<? super Predicate<T>> filter)
    • removeDisplayConditionIf

      @Experimental public final boolean removeDisplayConditionIf(@NotNull @NotNull Predicate<? super Supplier<Property.Display>> filter)
    • overwrite

      public void overwrite(Node with, boolean preserveMissingOptions, boolean skipOverwritten, @Nullable @Nullable Tree root)
      Description copied from class: Node
      Overwrite 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 Property the value and callbacks and display conditions are copied onto this
      • For a Tree all children and properties will be overwritten if they are present and this operation is recursive
      Specified by:
      overwrite in class Node
      Parameters:
      with - the node to overwrite this with
      preserveMissingOptions - if true then any properties 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()
    • set

      public final boolean set(@Nullable T value)
      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 using Object.equals(Object)
    • setReferential

      public boolean setReferential(@Nullable T value)
      Set the value of this property and call all callbacks
      Unlike set(Object) this will always set the value even if it is the same as the previous value
      Use this method with caution
    • set0

      protected abstract void set0(@Nullable T value)
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • get

      @Nullable public abstract T 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 a ClassCastException if 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 a ClassCastException if 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
      Unlike setAs(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

      public boolean deepEquals(Object obj)
      Deep equals for a property meaning it checks equals(Object) and the value of this property against the given obj
      In pretty much every case you should use equals(Object) instead
      This is used for testing
      Note that primitive arrays are not checked
      Specified by:
      deepEquals in class Node
    • equals

      public final boolean equals(Object obj)
      Overrides:
      equals in class Object
    • isPrimitive

      public final boolean isPrimitive()
      Returns:
      true if the value is a primitive array
    • isArray

      public final boolean isArray()