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

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>. this is 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:
    • onDisplayChange

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

      public final Property<T> addDisplayCondition(@NotNull @NotNull Supplier<Property.Display> condition)
      Add a display condition to this property.
    • 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()
      Remove all display conditions from this property.
    • 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)
    • 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. any duplicate keys will be overwritten.
      • For a Property, the value, callbacks and display conditions are copied onto this.
      • For a Tree, all children and properties will be overwritten if they are present. this operation is recursive.
      Specified by:
      overwrite in class Node
      Parameters:
      with - the node to overwrite this with
      preserveMissingOptions - 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

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

      public boolean setReferential(@Nullable T value)
      Set the value of this property. This will call all callbacks.
      Unlike set(Object), this will always set the value, regardless of 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()
      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 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. This will 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. This will call all callbacks.
      Unlike setAs(Object), this will always set the value, regardless of if it is the same as the previous value. Use this method with caution.
    • deepEquals

      public boolean deepEquals(Object obj)
      Deep equals for a property, meaning it will check equals(Object) and the value of this property with 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()
      Returns:
      true if the value is an array.