T - the type of object that this ConfigKey should referencepublic class ConfigKey<T>
extends java.lang.Object
ConfigFile.| Modifier and Type | Field and Description |
|---|---|
private T |
def |
private java.lang.Object[] |
key
The path from root to node.
|
private static org.slf4j.Logger |
LOGGER
The ConfigKeys logger.
|
| Modifier | Constructor and Description |
|---|---|
private |
ConfigKey(java.lang.Object[] key)
Constructs a new
ConfigKey. |
private |
ConfigKey(java.lang.Object[] key,
T def)
Constructs a new
ConfigKey. |
| Modifier and Type | Method and Description |
|---|---|
T |
get(ConfigFile config)
Returns the value stored in configuration for this key.
|
T |
get(ConfigFile config,
T def)
Returns the value stored in configuration this key.
|
static <T> ConfigKey<T> |
of(java.lang.Object... key)
Convenience method to construct a new
ConfigKey. |
static <T> ConfigKey<T> |
of(java.lang.Object key)
Convenience method to construct a new
ConfigKey. |
static <T> ConfigKey<T> |
of(T def,
java.lang.Object... key)
Convenience method to construct a new
ConfigKey. |
static <T> ConfigKey<T> |
of(T def,
java.lang.Object key)
Convenience method to construct a new
ConfigKey. |
boolean |
set(ConfigFile config,
T value)
Sets and saves a value for the node located at the path for this key.
|
void |
setWithException(ConfigFile config,
T value)
Sets and saves a value for the node located at the path for this key.
|
private static final org.slf4j.Logger LOGGER
@Nonnull private final java.lang.Object[] key
@Nullable private final T def
private ConfigKey(@Nonnull
java.lang.Object[] key)
ConfigKey.
Note: Default value will be null.
key - the path to the node on any level@Nullable public T get(@Nonnull ConfigFile config)
If the path doesn't exist, there is no value, or an
exception occurs, the default value for this ConfigKey
will be returned.
config - the ConfigFile to look through@Nullable public T get(@Nonnull ConfigFile config, @Nullable T def)
Note: If this ConfigKey has a default value set, this method will ignore it and use the provided default value.
config - the ConfigFile to look throughdef - the default value to be returned if an existing value cannot be obtainedpublic void setWithException(@Nullable
ConfigFile config,
@Nullable
T value)
throws java.io.IOException
config - the ConfigFile to save tovalue - the value to change the node tojava.io.IOException - if the configuration file cannot be saved topublic boolean set(@Nullable
ConfigFile config,
@Nullable
T value)
config - the ConfigFile to save tovalue - the value to change the node topublic static <T> ConfigKey<T> of(java.lang.Object key)
ConfigKey.
The purpose of this method is purely to reduce
new ConfigKey(new Object[]{"string"}); to ConfigKey.of("string");.
public static <T> ConfigKey<T> of(java.lang.Object... key)
ConfigKey.
The purpose of this method is purely to reduce
new ConfigKey(new Object[]{"string"}); to ConfigKey.of("string");.
public static <T> ConfigKey<T> of(T def, java.lang.Object key)
ConfigKey.
The purpose of this method is purely to reduce
new ConfigKey(new Object[]{"string"}); to ConfigKey.of("string");.