Class AbstractArrayProperty<T>

java.lang.Object
net.darkhax.pricklemc.common.api.config.property.ObjectProperty<T>
net.darkhax.pricklemc.common.api.config.property.array.AbstractArrayProperty<T>
Type Parameters:
T - The type of value held in the array.
All Implemented Interfaces:
IConfigProperty<T>
Direct Known Subclasses:
ArrayProperty, CollectionArrayProperty

public abstract class AbstractArrayProperty<T> extends ObjectProperty<T>
Represents an array of values in the config object.
  • Field Details

    • BASIC_TYPES

      public static final Set<Class<?>> BASIC_TYPES
      A set of Java types that align with the types of JSON primitives. This is used to determine if an array contains complex values or not.
  • Constructor Details

    • AbstractArrayProperty

      public AbstractArrayProperty(Field field, Object parent, T defaultValue, Value valueMeta, ArraySettings meta, IComment comment)
      Constructor for an array property.
      Parameters:
      field - The field this property represents.
      parent - The object that the field is defined on.
      defaultValue - The default value of the property.
      valueMeta - Basic metadata available to most properties.
      meta - Metadata specific to the array.
      comment - The comment for the property.
  • Method Details

    • isOverInlineThreshold

      public abstract boolean isOverInlineThreshold(T value)
      Checks if the length of the array value is over the inline threshold.
      Parameters:
      value - The array value.
      Returns:
      If the length of the array value is over the inline threshold.
    • isComplex

      public abstract boolean isComplex(T value)
      Checks if the array value contains a complex entry.
      Parameters:
      value - The array value.
      Returns:
      If the array value contains a complex entry.
    • isEmpty

      public abstract boolean isEmpty(T value)
      Checks if the array value is empty.
      Parameters:
      value - The array value.
      Returns:
      If the array value is empty.
    • writeArrayValues

      public abstract void writeArrayValues(T value, com.google.gson.stream.JsonWriter out, PropertyResolver resolver, org.slf4j.Logger log)
      Writes entries of the array value to a JSONWriter.
      Parameters:
      value - The array value.
      out - The JSON writer to write data to.
      resolver - A resolver for GSON objects and config properties.
      log - A logger that can be used to display errors and warnings.
    • settings

      public ArraySettings settings()
      Gets settings for the array value. These are specified using an annotation on the field.
      Returns:
      The settings for the array.
    • writeValue

      public void writeValue(T value, com.google.gson.stream.JsonWriter out, PropertyResolver resolver, org.slf4j.Logger log) throws IOException
      Description copied from class: ObjectProperty
      Writes a value to the JSON writer.
      Overrides:
      writeValue in class ObjectProperty<T>
      Parameters:
      value - The value to be written.
      out - A writer to write JSON data to.
      resolver - Resolves properties with GSON or config properties.
      log - A log instance used to log warnings and errors encountered when saving the value.
      Throws:
      IOException - A fatal exception may be thrown if the value could not be written.
    • writeAdditionalComments

      public void writeAdditionalComments(com.google.gson.stream.JsonWriter out, PropertyResolver resolver, org.slf4j.Logger log) throws IOException
      Description copied from class: ObjectProperty
      Writes additional decorators to the JSON writer.
      Overrides:
      writeAdditionalComments in class ObjectProperty<T>
      Parameters:
      out - A writer to write JSON data to.
      resolver - Resolves properties with GSON or config properties.
      log - A log instance used to log warnings and errors encountered when saving the value.
      Throws:
      IOException - A fatal exception may be thrown if the decorators could not be written.
    • validate

      public boolean validate(T value) throws IllegalArgumentException
      Description copied from interface: IConfigProperty
      Validates if a value is valid for the property.
      Specified by:
      validate in interface IConfigProperty<T>
      Overrides:
      validate in class ObjectProperty<T>
      Parameters:
      value - The value to validate.
      Returns:
      If the value is true or not. Invalid properties will not be applied when reading the value from JSON.
      Throws:
      IllegalArgumentException - Generally a fatal exception should be raised when the value is invalid.