Package info.u_team.u_team_core.util
Class ConfigUtil
java.lang.Object
info.u_team.u_team_core.util.ConfigUtil
Utility methods for loading and reading json config files with gson
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
loadConfig
(Path directory, String name, com.google.gson.Gson gson, Function<com.google.gson.stream.JsonWriter, T> write, Function<BufferedReader, T> read) Load and create a config file if not already there from a default value.static <T> T
loadConfig
(Path directory, String name, com.google.gson.Gson gson, T defaultValue, BiConsumer<com.google.gson.stream.JsonWriter, T> write, Function<BufferedReader, T> read) Load and create a config file if not already there from a default value.static <T> T
loadConfig
(Path directory, String name, String extension, com.google.gson.Gson gson, Function<com.google.gson.stream.JsonWriter, T> write, Function<BufferedReader, T> read) Load and create a config file if not already there from a default value.static <T> T
loadConfig
(Path directory, String name, String extension, com.google.gson.Gson gson, T defaultValue, BiConsumer<com.google.gson.stream.JsonWriter, T> write, Function<BufferedReader, T> read) Load and create a config file if not already there from a default value.
-
Field Details
-
JSON_EXTENSION
Default extension of json files- See Also:
-
-
Constructor Details
-
ConfigUtil
public ConfigUtil()
-
-
Method Details
-
loadConfig
public static <T> T loadConfig(Path directory, String name, com.google.gson.Gson gson, Function<com.google.gson.stream.JsonWriter, T> write, Function<BufferedReader, throws IOExceptionT> read) Load and create a config file if not already there from a default value. UseGson
for serialization and deserialization. The extension of the file is automaticallyJSON_EXTENSION
- Type Parameters:
T
- Class to load with gson- Parameters:
directory
- Path of the directory where the file isname
- The file without the extensiongson
- Gson instance with possible registered serializerwrite
- Function that should write the default values to theJsonWriter
and return the the default instanceread
- Function that should read the values fromBufferedReader
and deserialize them and return a new instance of the class with the new values- Returns:
- Either the default instance if the file was created or an instance with loaded value from the config
- Throws:
IOException
-
loadConfig
public static <T> T loadConfig(Path directory, String name, String extension, com.google.gson.Gson gson, Function<com.google.gson.stream.JsonWriter, T> write, Function<BufferedReader, throws IOExceptionT> read) Load and create a config file if not already there from a default value. UseGson
for serialization and deserialization.- Type Parameters:
T
- Class to load with gson- Parameters:
directory
- Path of the directory where the file isname
- The file without the extensionextension
- Extension of the filegson
- Gson instance with possible registered serializerwrite
-Function
that should write the default values to theJsonWriter
and return the the default instanceread
-Function
that should read the values fromBufferedReader
and deserialize them and return a new instance of the class with the new values- Returns:
- Either the default instance if the file was created or an instance with loaded value from the config
- Throws:
IOException
-
loadConfig
public static <T> T loadConfig(Path directory, String name, com.google.gson.Gson gson, T defaultValue, BiConsumer<com.google.gson.stream.JsonWriter, T> write, Function<BufferedReader, throws IOExceptionT> read) Load and create a config file if not already there from a default value. UseGson
for serialization and deserialization. The extension of the file is automaticallyJSON_EXTENSION
- Type Parameters:
T
- Class to load with gson- Parameters:
directory
- Path of the directory where the file isname
- The file without the extensiongson
- Gson instance with possible registered serializerdefaultValue
- The default instance of the class that should be written if no config file is presentwrite
-BiConsumer
that should write the default values to theJsonWriter
read
-Function
that should read the values fromBufferedReader
and deserialize them and return a new instance of the class with the new values- Returns:
- Either the default instance if the file was created or an instance with loaded value from the config
- Throws:
IOException
-
loadConfig
public static <T> T loadConfig(Path directory, String name, String extension, com.google.gson.Gson gson, T defaultValue, BiConsumer<com.google.gson.stream.JsonWriter, T> write, Function<BufferedReader, throws IOExceptionT> read) Load and create a config file if not already there from a default value. UseGson
for serialization and deserialization.- Type Parameters:
T
- Class to load with gson- Parameters:
directory
- Path of the directory where the file isname
- The file without the extensionextension
- Extension of the filegson
- Gson instance with possible registered serializerdefaultValue
- The default instance of the class that should be written if no config file is presentwrite
-BiConsumer
that should write the default values to theJsonWriter
read
-Function
that should read the values fromBufferedReader
and deserialize them and return a new instance of the class with the new values- Returns:
- Either the default instance if the file was created or an instance with loaded value from the config
- Throws:
IOException
-