Class ConfigHandler

java.lang.Object
me.tnoctua.nmodutils.util.ConfigHandler

public class ConfigHandler extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
    ConfigHandler(String path, Supplier<com.google.gson.JsonObject> toJson, Consumer<com.google.gson.JsonObject> fromJson)
    Instance of a configuration file.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Loads configuration from disk.
    com.google.gson.JsonObject
    Reads the configuration file and returns a JSON object representation.
    void
    Saves the configuration to disk.
    void
    write(com.google.gson.JsonObject json)
    Writes the provided JSON object to the configuration file.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ConfigHandler

      public ConfigHandler(String path, Supplier<com.google.gson.JsonObject> toJson, Consumer<com.google.gson.JsonObject> fromJson)
      Instance of a configuration file.
      Parameters:
      path - path to the configuration file relative to config directory and without the file extension
      toJson - method to serialize the configuration into a JSON Object
      fromJson - method to deserialize the configuration from a JSON Object
  • Method Details

    • save

      public void save()
      Saves the configuration to disk.
    • load

      public void load()
      Loads configuration from disk.
    • write

      public void write(com.google.gson.JsonObject json)
      Writes the provided JSON object to the configuration file.
      Parameters:
      json - object to write
    • read

      public com.google.gson.JsonObject read()
      Reads the configuration file and returns a JSON object representation.
      Returns:
      file as JSON