Package me.tnoctua.nmodutils.util
Class ConfigHandler
java.lang.Object
me.tnoctua.nmodutils.util.ConfigHandler
-
Constructor Summary
ConstructorsConstructorDescriptionConfigHandler(String path, Supplier<com.google.gson.JsonObject> toJson, Consumer<com.google.gson.JsonObject> fromJson) Instance of a configuration file. -
Method Summary
Modifier and TypeMethodDescriptionvoidload()Loads configuration from disk.com.google.gson.JsonObjectread()Reads the configuration file and returns a JSON object representation.voidsave()Saves the configuration to disk.voidwrite(com.google.gson.JsonObject json) Writes the provided JSON object to the configuration file.
-
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 extensiontoJson- method to serialize the configuration into a JSON ObjectfromJson- 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
-