public abstract class Config
extends java.lang.Object
Constructor and Description |
---|
Config()
Constructs a Config instance and loads default configurations.
|
Config(boolean loadDefaults)
Constructs a Config instance.
|
Modifier and Type | Method and Description |
---|---|
<T> T |
get(ConfigEntry<T> entry)
Gets the value of a configuration entry.
|
java.util.Map<java.lang.String,java.lang.String> |
getAllConfig()
Retrieves a map containing all configuration entries.
|
java.util.Map<java.lang.String,java.lang.String> |
getConfigsWithPrefix(java.lang.String prefix)
Retrieves a map containing configuration entries that have keys with the specified prefix.
|
java.lang.String |
getRawString(java.lang.String key)
Retrieves the raw string value associated with the specified configuration key.
|
java.lang.String |
getRawString(java.lang.String key,
java.lang.String defaultValue)
Retrieves the raw string value associated with the specified configuration key, providing a
default value if the key is not found.
|
Config |
loadFromFile(java.lang.String name)
Loads configurations from a properties file.
|
void |
loadFromMap(java.util.Map<java.lang.String,java.lang.String> map,
java.util.function.Predicate<java.lang.String> predicate)
Loads configurations from a map.
|
void |
loadFromProperties(java.util.Properties properties)
Loads configurations from properties.
|
java.util.Properties |
loadPropertiesFromFile(java.io.File file)
Loads properties from a file.
|
<T> void |
set(ConfigEntry<T> entry,
T value)
Sets the value of a configuration entry.
|
public Config(boolean loadDefaults)
loadDefaults
- Set to true if default configurations should be loaded.public Config()
public Config loadFromFile(java.lang.String name) throws java.lang.Exception
name
- The name of the properties file.java.lang.Exception
- If there's an issue loading the properties.public <T> T get(ConfigEntry<T> entry) throws java.util.NoSuchElementException
T
- The type of the configuration value.entry
- The configuration entry to retrieve.java.util.NoSuchElementException
- If the configuration entry is not found.public java.lang.String getRawString(java.lang.String key)
key
- The configuration key for which the raw string value is requested.public java.lang.String getRawString(java.lang.String key, java.lang.String defaultValue)
key
- The configuration key for which the raw string value is requested.defaultValue
- The default value to be returned if the key is not found.public java.util.Map<java.lang.String,java.lang.String> getConfigsWithPrefix(java.lang.String prefix)
prefix
- The prefix that configuration keys should start with.public java.util.Map<java.lang.String,java.lang.String> getAllConfig()
public <T> void set(ConfigEntry<T> entry, T value)
T
- The type of the configuration value.entry
- The configuration entry for which the value needs to be set.value
- The new value to be assigned to the configuration entry.public void loadFromMap(java.util.Map<java.lang.String,java.lang.String> map, java.util.function.Predicate<java.lang.String> predicate)
map
- The map containing configuration key-value pairs.predicate
- The keys only match the predicate will be loaded to configMappublic void loadFromProperties(java.util.Properties properties)
properties
- The properties object containing configuration key-value pairs.public java.util.Properties loadPropertiesFromFile(java.io.File file) throws java.io.IOException
file
- The properties file to load from.java.io.IOException
- If there's an issue loading the properties.