Class ObjectProperty<T>
java.lang.Object
net.darkhax.pricklemc.common.api.config.property.ObjectProperty<T>
- All Implemented Interfaces:
IConfigProperty<T>
- Direct Known Subclasses:
AbstractArrayProperty,CodecProperty,ConfigObjectProperty,RangedProperty,RegexStringProperty
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final IPropertyAdapter<ObjectProperty<?>> The property adapter that is used when a field does not have an explicit property adapter. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncomment()Gets the comment for the property.Gets the default value for the property.voidread(com.google.gson.stream.JsonReader reader, PropertyResolver resolver, org.slf4j.Logger logger) Reads the value from the JSON and applies it to the parent object.readValue(com.google.gson.stream.JsonReader reader, PropertyResolver resolver, org.slf4j.Logger logger) Reads a value from the JSON reader.booleanValidates if a value is valid for the property.value()Gets the current value of the property.voidwrite(com.google.gson.stream.JsonWriter writer, PropertyResolver resolver, org.slf4j.Logger logger) Writes the value to the JSON writer.voidwriteAdditionalComments(com.google.gson.stream.JsonWriter writer, PropertyResolver resolver, org.slf4j.Logger logger) Writes additional decorators to the JSON writer.booleanChecks if the default value should be written as a decorator.voidwriteDefaultValue(com.google.gson.stream.JsonWriter writer, PropertyResolver resolver, org.slf4j.Logger logger) Handles writing the default value to the JSON writer.voidwriteValue(T value, com.google.gson.stream.JsonWriter writer, PropertyResolver resolver, org.slf4j.Logger logger) Writes a value to the JSON writer.
-
Field Details
-
FALLBACK_ADAPTER
The property adapter that is used when a field does not have an explicit property adapter.
-
-
Constructor Details
-
ObjectProperty
-
-
Method Details
-
comment
Gets the comment for the property.- Returns:
- The comment for the property.
-
defaultValue
Gets the default value for the property. This is generally the value that the field was initialized with.- Returns:
- The default value for the property.
-
writeDefaultValue
public boolean writeDefaultValue()Checks if the default value should be written as a decorator.- Returns:
- Should the default value be written?
-
value
Gets the current value of the property.- Specified by:
valuein interfaceIConfigProperty<T>- Returns:
- The current value of the property.
-
read
public void read(com.google.gson.stream.JsonReader reader, PropertyResolver resolver, org.slf4j.Logger logger) throws IOException Description copied from interface:IConfigPropertyReads the value from the JSON and applies it to the parent object.- Specified by:
readin interfaceIConfigProperty<T>- Parameters:
reader- A reader containing a stream of JSON data.resolver- Resolves properties with GSON or config properties.logger- A log instance used to log warnings and errors encountered when the value is read.- Throws:
IOException- Fatal errors should be thrown if invalid data is encountered.
-
write
public void write(com.google.gson.stream.JsonWriter writer, PropertyResolver resolver, org.slf4j.Logger logger) throws IOException Description copied from interface:IConfigPropertyWrites the value to the JSON writer.- Specified by:
writein interfaceIConfigProperty<T>- Parameters:
writer- A writer to write JSON data to.resolver- Resolves properties with GSON or config properties.logger- A log instance used to log warnings and errors encountered when saving the value.- Throws:
IOException- Fatal errors should be thrown if the property can not be written.
-
writeValue
public void writeValue(T value, com.google.gson.stream.JsonWriter writer, PropertyResolver resolver, org.slf4j.Logger logger) throws IOException Writes a value to the JSON writer.- Parameters:
value- The value to be written.writer- A writer to write JSON data to.resolver- Resolves properties with GSON or config properties.logger- 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.
-
readValue
public T readValue(com.google.gson.stream.JsonReader reader, PropertyResolver resolver, org.slf4j.Logger logger) throws IOException Reads a value from the JSON reader.- Parameters:
reader- A reader containing a stream of JSON data.resolver- Resolves properties with GSON or config properties.logger- A log instance used to log warnings and errors encountered when the value is read.- Returns:
- The value that was read from the reader.
- Throws:
IOException- A fatal exception may be thrown if the value could not be read.
-
writeDefaultValue
public void writeDefaultValue(com.google.gson.stream.JsonWriter writer, PropertyResolver resolver, org.slf4j.Logger logger) throws IOException Handles writing the default value to the JSON writer.- Parameters:
writer- A writer to write JSON data to.resolver- Resolves properties with GSON or config properties.logger- 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 writer, PropertyResolver resolver, org.slf4j.Logger logger) throws IOException Writes additional decorators to the JSON writer.- Parameters:
writer- A writer to write JSON data to.resolver- Resolves properties with GSON or config properties.logger- 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>- 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.
-