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
Represents an array of values in the config object.
-
Field Summary
FieldsModifier and TypeFieldDescriptionA set of Java types that align with the types of JSON primitives.Fields inherited from class net.darkhax.pricklemc.common.api.config.property.ObjectProperty
FALLBACK_ADAPTER -
Constructor Summary
ConstructorsConstructorDescriptionAbstractArrayProperty(Field field, Object parent, T defaultValue, Value valueMeta, ArraySettings meta, IComment comment) Constructor for an array property. -
Method Summary
Modifier and TypeMethodDescriptionabstract booleanChecks if the array value contains a complex entry.abstract booleanChecks if the array value is empty.abstract booleanisOverInlineThreshold(T value) Checks if the length of the array value is over the inline threshold.settings()Gets settings for the array value.booleanValidates if a value is valid for the property.voidwriteAdditionalComments(com.google.gson.stream.JsonWriter out, PropertyResolver resolver, org.slf4j.Logger log) Writes additional decorators to the JSON writer.abstract voidwriteArrayValues(T value, com.google.gson.stream.JsonWriter out, PropertyResolver resolver, org.slf4j.Logger log) Writes entries of the array value to a JSONWriter.voidwriteValue(T value, com.google.gson.stream.JsonWriter out, PropertyResolver resolver, org.slf4j.Logger log) Writes a value to the JSON writer.Methods inherited from class net.darkhax.pricklemc.common.api.config.property.ObjectProperty
comment, defaultValue, read, readValue, value, write, writeDefaultValue, writeDefaultValue
-
Field Details
-
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
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
Checks if the array value contains a complex entry.- Parameters:
value- The array value.- Returns:
- If the array value contains a complex entry.
-
isEmpty
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
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:ObjectPropertyWrites a value to the JSON writer.- Overrides:
writeValuein classObjectProperty<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:ObjectPropertyWrites additional decorators to the JSON writer.- Overrides:
writeAdditionalCommentsin classObjectProperty<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
Description copied from interface:IConfigPropertyValidates if a value is valid for the property.- Specified by:
validatein interfaceIConfigProperty<T>- Overrides:
validatein classObjectProperty<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.
-