Class AutoConfig

java.lang.Object
io.github.thecsdev.tcdcommons.api.config.AutoConfig
All Implemented Interfaces:
ACJsonHandler<com.google.gson.JsonObject>
Direct Known Subclasses:
TCDCommonsConfig

public class AutoConfig extends Object implements ACJsonHandler<com.google.gson.JsonObject>
  • Field Details

  • Constructor Details

  • Method Details

    • getPropertyFields

      public final List<Field> getPropertyFields()
      Returns all valid property fields for this object. Both declared fields as well as inherited fields are included. Property fields must be public non-static primitive types or ACJsonHandlers.
    • serializeProperty

      @Nullable protected final @Nullable com.google.gson.JsonElement serializeProperty(Field property)
      Serializes a Field that belongs to this AutoConfig object to a JsonElement.
      Parameters:
      property - The property Field from this AutoConfig.
      Returns:
      null if serialization fails or if the given Field type is unsupported.
    • deserializeProperty

      protected final boolean deserializeProperty(Field property, com.google.gson.JsonElement jEl)
      Deserializes a JsonElement to a given property (field) that belongs to this AutoConfig.
      Parameters:
      property - The property Field from this AutoConfig.
      jEl - The JsonElement to deserialize.
      Returns:
      true if nothing went wrong while deserializing the given property Field.
    • getPropertyName

      public final String getPropertyName(Field property)
      Checks if a given property Field has the SerializedAs annotation, and returns the name of the Field based on that.
      Parameters:
      property - The property Field from this AutoConfig.
      Returns:
      Field.getName() if the field doesn't have the SerializedAs annotation.
    • saveToJson

      public com.google.gson.JsonObject saveToJson()
      Description copied from interface: ACJsonHandler
      Saves the data from this object into a new JsonElement, and then returns the JsonElement.
      Specified by:
      saveToJson in interface ACJsonHandler<com.google.gson.JsonObject>
    • loadFromJson

      public boolean loadFromJson(com.google.gson.JsonObject json)
      Description copied from interface: ACJsonHandler
      Loads the data from a given JsonElement to this object, and then returns true if loading was successful.
      Specified by:
      loadFromJson in interface ACJsonHandler<com.google.gson.JsonObject>
      Parameters:
      json - The JsonElement to load the data from.
    • saveToFile

      public final void saveToFile(boolean log) throws IOException, SecurityException
      Saves this AutoConfig to it's file.
      Parameters:
      log - Would you like to log this operation to the console?
      Throws:
      IOException - If an I/O error occurs writing to or creating the file.
      SecurityException - See SecurityManager.checkWrite(String).
    • saveToFileOrCrash

      public final void saveToFileOrCrash(boolean log)
      Same as saveToFile(boolean), but any raised IOExceptions will not be handled.
      Parameters:
      log - Would you like to log this operation to the console?
      See Also:
    • trySaveToFile

      public final boolean trySaveToFile(boolean log)
      Same as saveToFile(boolean), but returns false if an IOException is raised.
      Parameters:
      log - Would you like to log this operation to the console?
      See Also:
    • loadFromFile

      public final void loadFromFile(boolean log) throws IOException
      Loads this AutoConfig from it's file.
      Parameters:
      log - Would you like to log this operation to the console?
      Throws:
      IOException - If an I/O error occurs reading from the file.
    • loadFromFileOrCrash

      public final void loadFromFileOrCrash(boolean log)
      Same as loadFromFile(boolean), but any raised IOExceptions will not be handled.
      Parameters:
      log - Would you like to log this operation to the console?
      See Also:
    • tryLoadFromFile

      public final boolean tryLoadFromFile(boolean log)
      Same as loadFromFile(boolean), but returns false if an IOException is raised.
      Parameters:
      log - Would you like to log this operation to the console?
      See Also: