Interface Config
-
- All Superinterfaces:
UnmodifiableConfig
- All Known Subinterfaces:
CommentedConfig,CommentedFileConfig,FileConfig
- All Known Implementing Classes:
AbstractCommentedConfig,AbstractConfig,CommentedConfigWrapper,ConfigWrapper,ConvertedCommentedConfig,ConvertedCommentedFileConfig,ConvertedConfig,ConvertedFileConfig,FakeCommentedConfig
public interface Config extends UnmodifiableConfig
A (modifiable) configuration that contains key/value mappings. Configurations are generally not thread-safe.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceConfig.EntryA modifiable config entry.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default booleanadd(java.lang.String path, java.lang.Object value)Adds a config value.booleanadd(java.util.List<java.lang.String> path, java.lang.Object value)Adds a config value.default voidaddAll(UnmodifiableConfig config)Adds all the values of a config to this config, without replacing existing entries.default Configchecked()Returns a checked view of the config.voidclear()Removes all values from the config.static ConfigconcurrentCopy(UnmodifiableConfig config)Creates a new Config with the content of the given config.static ConfigconcurrentCopy(UnmodifiableConfig config, ConfigFormat<?> format)Creates a new Config with the content of the given config.static Configcopy(UnmodifiableConfig config)Creates a new Config with the content of the given config.static Configcopy(UnmodifiableConfig config, ConfigFormat<?> format)Creates a new Config with the content of the given config.static Configcopy(UnmodifiableConfig config, java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>> mapCreator)Creates a new Config with the content of the given config.static Configcopy(UnmodifiableConfig config, java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>> mapCreator, ConfigFormat<?> format)Creates a new Config with the content of the given config.ConfigcreateSubConfig()Creates a new sub config of this config, as created when a subconfig's creation is implied byset(List, Object)oradd(List, Object).java.util.Set<? extends Config.Entry>entrySet()Returns a Set view of the config's entries.static <T> java.util.function.Supplier<java.util.Map<java.lang.String,T>>getDefaultMapCreator(boolean concurrent)Returns a map supplier that fullfills the given requirements.static <T> java.util.function.Supplier<java.util.Map<java.lang.String,T>>getDefaultMapCreator(boolean concurrent, boolean insertionOrderPreserved)Returns a map supplier that fulfills the given requirements.static ConfiginMemory()Creates a Config with formatInMemoryFormat.defaultInstance().static ConfiginMemoryConcurrent()Creates a thread-safe Config with formatInMemoryFormat.defaultInstance().static ConfiginMemoryUniversal()Creates a Config with formatInMemoryFormat.withUniversalSupport().static ConfiginMemoryUniversalConcurrent()Creates a thread-safe Config with formatInMemoryFormat.withUniversalSupport().static booleanisInsertionOrderPreserved()Checks if the newly created configs keep the insertion order of their content.static Configof(ConfigFormat<? extends Config> format)Creates a Config of the given format.static Configof(java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>> mapCreator, ConfigFormat<?> format)Creates a Config backed by a certain kind of map, given by a supplier.static ConfigofConcurrent(ConfigFormat<? extends Config> format)Creates a thread-safe Config of the given format.default voidputAll(UnmodifiableConfig config)Copies all the values of a config into this config.default <T> Tremove(java.lang.String path)Removes a value from the config.<T> Tremove(java.util.List<java.lang.String> path)Removes a value from the config.default voidremoveAll(UnmodifiableConfig config)Removes all the values of the given config from this config.default <T> Tset(java.lang.String path, java.lang.Object value)Sets a config value.<T> Tset(java.util.List<java.lang.String> path, java.lang.Object value)Sets a config value.static voidsetInsertionOrderPreserved(boolean orderPreserved)Modifies the behavior of the new configurations with regards to the preservation of the order of config values.default UnmodifiableConfigunmodifiable()Returns an Unmodifiable view of the config.default voidupdate(java.lang.String path, java.lang.Object value)For scala: sets a config value.default voidupdate(java.util.List<java.lang.String> path, java.lang.Object value)For scala: sets a config value.java.util.Map<java.lang.String,java.lang.Object>valueMap()Returns a Map view of the config's values.static Configwrap(java.util.Map<java.lang.String,java.lang.Object> map, ConfigFormat<?> format)Creates a Config backed by a Map.-
Methods inherited from interface com.electronwill.nightconfig.core.UnmodifiableConfig
apply, apply, configFormat, contains, contains, get, get, getByte, getByte, getByteOrElse, getByteOrElse, getChar, getChar, getCharOrElse, getCharOrElse, getEnum, getEnum, getEnum, getEnum, getEnumOrElse, getEnumOrElse, getEnumOrElse, getEnumOrElse, getEnumOrElse, getEnumOrElse, getEnumOrElse, getEnumOrElse, getInt, getInt, getIntOrElse, getIntOrElse, getIntOrElse, getIntOrElse, getLong, getLong, getLongOrElse, getLongOrElse, getLongOrElse, getLongOrElse, getOptional, getOptional, getOptionalEnum, getOptionalEnum, getOptionalEnum, getOptionalEnum, getOptionalInt, getOptionalInt, getOptionalLong, getOptionalLong, getOrElse, getOrElse, getOrElse, getOrElse, getRaw, getRaw, getShort, getShort, getShortOrElse, getShortOrElse, isEmpty, isNull, isNull, size
-
-
-
-
Method Detail
-
set
default <T> T set(java.lang.String path, java.lang.Object value)Sets a config value.- Type Parameters:
T- the type of the old value- Parameters:
path- the value's path, each part separated by a dot. Example "a.b.c"value- the value to set- Returns:
- the old value if any, or
null
-
set
<T> T set(java.util.List<java.lang.String> path, java.lang.Object value)Sets a config value.- Type Parameters:
T- the type of the old value- Parameters:
path- the value's path, each element of the list is a different part of the path.value- the value to set- Returns:
- the old value if any, or
null
-
add
boolean add(java.util.List<java.lang.String> path, java.lang.Object value)Adds a config value. The value is set iff there is no value associated with the given path.- Parameters:
path- the value's path, each element of the list is a different part of the path.value- the value to set- Returns:
- true if the value has been added, false if a value is already associated with the given path
-
add
default boolean add(java.lang.String path, java.lang.Object value)Adds a config value. The value is set iff there is no value associated with the given path.- Parameters:
path- the value's path, each part separated by a dot. Example "a.b.c"value- the value to set- Returns:
- true if the value has been added, false if a value is already associated with the given path
-
addAll
default void addAll(UnmodifiableConfig config)
Adds all the values of a config to this config, without replacing existing entries.- Parameters:
config- the source config
-
putAll
default void putAll(UnmodifiableConfig config)
Copies all the values of a config into this config. Existing entries are replaced, missing entries are created.- Parameters:
config- the source config
-
remove
default <T> T remove(java.lang.String path)
Removes a value from the config.- Type Parameters:
T- the type of the old value- Parameters:
path- the value's path, each part separated by a dot. Example "a.b.c"- Returns:
- the old value if any, or
null
-
remove
<T> T remove(java.util.List<java.lang.String> path)
Removes a value from the config.- Type Parameters:
T- the type of the old value- Parameters:
path- the value's path, each element of the list is a different part of the path.- Returns:
- the old value if any, or
null
-
removeAll
default void removeAll(UnmodifiableConfig config)
Removes all the values of the given config from this config.- Parameters:
config- the values to remove
-
clear
void clear()
Removes all values from the config.
-
unmodifiable
default UnmodifiableConfig unmodifiable()
Returns an Unmodifiable view of the config. Any change to the original (modifiable) config is still reflected to the returned UnmodifiableConfig, so it's unmodifiable but not immutable.- Returns:
- an Unmodifiable view of the config.
-
checked
default Config checked()
Returns a checked view of the config. It checks that all the values put into the config are supported by the config's format (as per theConfigFormat.supportsType(Class)method. Trying to insert an unsupported value throws an IllegalArgumentException.The values that are in the config when this method is called are also checked.
- Returns:
- a checked view of the config.
-
valueMap
java.util.Map<java.lang.String,java.lang.Object> valueMap()
Returns a Map view of the config's values. Any change to the map is reflected in the config and vice-versa.- Specified by:
valueMapin interfaceUnmodifiableConfig- Returns:
- a Map view of the config's values.
-
entrySet
java.util.Set<? extends Config.Entry> entrySet()
Returns a Set view of the config's entries. Any change to the set or to the entries is reflected in the config, and vice-versa.- Specified by:
entrySetin interfaceUnmodifiableConfig- Returns:
- a Set view of the config's entries.
-
createSubConfig
Config createSubConfig()
Creates a new sub config of this config, as created when a subconfig's creation is implied byset(List, Object)oradd(List, Object).- Returns:
- a new sub config
-
update
default void update(java.lang.String path, java.lang.Object value)For scala: sets a config value.- Parameters:
path- the value's path, each part separated by a dot. Example "a.b.c"value- the value to set- See Also:
set(String, Object)
-
update
default void update(java.util.List<java.lang.String> path, java.lang.Object value)For scala: sets a config value.- Parameters:
path- the value's path, each element of the list is a different part of the path.value- the value to set- See Also:
set(List, Object)
-
of
static Config of(ConfigFormat<? extends Config> format)
Creates a Config of the given format.- Parameters:
format- the config's format- Returns:
- a new empty config
-
of
static Config of(java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>> mapCreator, ConfigFormat<?> format)
Creates a Config backed by a certain kind of map, given by a supplier. If you wish all your configs to preserve insertion order, please have a look at the more practical settingsetInsertionOrderPreserved(boolean).- Parameters:
mapCreator- a supplier which will be called to create all backing maps for this config (including sub-configs)format- the config's format- Returns:
- a new config backed by the map
-
ofConcurrent
static Config ofConcurrent(ConfigFormat<? extends Config> format)
Creates a thread-safe Config of the given format.- Parameters:
format- the config's format- Returns:
- a new empty, thread-safe config
-
inMemory
static Config inMemory()
Creates a Config with formatInMemoryFormat.defaultInstance().- Returns:
- a new empty config
-
inMemoryUniversal
static Config inMemoryUniversal()
Creates a Config with formatInMemoryFormat.withUniversalSupport().- Returns:
- a new empty config
-
inMemoryConcurrent
static Config inMemoryConcurrent()
Creates a thread-safe Config with formatInMemoryFormat.defaultInstance().- Returns:
- a new empty config
-
inMemoryUniversalConcurrent
static Config inMemoryUniversalConcurrent()
Creates a thread-safe Config with formatInMemoryFormat.withUniversalSupport().- Returns:
- a new empty config
-
wrap
static Config wrap(java.util.Map<java.lang.String,java.lang.Object> map, ConfigFormat<?> format)
Creates a Config backed by a Map. Any change to the map is reflected in the config and vice-versa. If you wish all your configs to preserve insertion order, please have a look at the more practical settingsetInsertionOrderPreserved(boolean).- Parameters:
map- the Map to useformat- the config's format- Returns:
- a new config backed by the map
-
copy
static Config copy(UnmodifiableConfig config)
Creates a new Config with the content of the given config. The returned config will have the same format as the copied config.- Parameters:
config- the config to copy- Returns:
- a copy of the config
-
copy
static Config copy(UnmodifiableConfig config, java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>> mapCreator)
Creates a new Config with the content of the given config. The returned config will have the same format as the copied config, and be backed by the given supplier. If you wish all your configs to preserve insertion order, please have a look at the more practical settingsetInsertionOrderPreserved(boolean).- Parameters:
config- the config to copymapCreator- a supplier which will be called to create all backing maps for this config (including sub-configs)- Returns:
- a copy of the config
- See Also:
of(Supplier, ConfigFormat)
-
copy
static Config copy(UnmodifiableConfig config, ConfigFormat<?> format)
Creates a new Config with the content of the given config.- Parameters:
config- the config to copyformat- the config's format- Returns:
- a copy of the config
-
copy
static Config copy(UnmodifiableConfig config, java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>> mapCreator, ConfigFormat<?> format)
Creates a new Config with the content of the given config. The returned config will be backed by the given map supplier. If you wish all your configs to preserve insertion order, please have a look at the more practical settingsetInsertionOrderPreserved(boolean).- Parameters:
config- the config to copymapCreator- a supplier which will be called to create all backing maps for this config (including sub-configs)format- the config's format- Returns:
- a copy of the config
- See Also:
of(Supplier, ConfigFormat)
-
concurrentCopy
static Config concurrentCopy(UnmodifiableConfig config)
Creates a new Config with the content of the given config. The returned config will have the same format as the copied config.- Parameters:
config- the config to copy- Returns:
- a thread-safe copy of the config
-
concurrentCopy
static Config concurrentCopy(UnmodifiableConfig config, ConfigFormat<?> format)
Creates a new Config with the content of the given config.- Parameters:
config- the config to copyformat- the config's format- Returns:
- a thread-safe copy of the config
-
isInsertionOrderPreserved
static boolean isInsertionOrderPreserved()
Checks if the newly created configs keep the insertion order of their content. By default this is not the case. This can be controlled with the `nightconfig.ordered` system property or by callingsetInsertionOrderPreserved(boolean).This setting does not apply to configurations created from a Map, from another Config, or with a specific map supplier.
- Returns:
- true if the new configs preserve the insertion order of their values, false to give no guarantee about the values ordering.
-
setInsertionOrderPreserved
static void setInsertionOrderPreserved(boolean orderPreserved)
Modifies the behavior of the new configurations with regards to the preservation of the order of config values.This setting does not apply to configurations created from a Map, from another Config, or with a specific map supplier.
- Parameters:
orderPreserved- true to make the new configs preserve the insertion order of their values, false to give no guarantee about the values ordering.- See Also:
isInsertionOrderPreserved()
-
getDefaultMapCreator
static <T> java.util.function.Supplier<java.util.Map<java.lang.String,T>> getDefaultMapCreator(boolean concurrent, boolean insertionOrderPreserved)Returns a map supplier that fulfills the given requirements.- Parameters:
concurrent- true to make the maps thread-safeinsertionOrderPreserved- true to make the maps preserve the insertion order of values- Returns:
- a map supplier corresponding to the given settings
-
getDefaultMapCreator
static <T> java.util.function.Supplier<java.util.Map<java.lang.String,T>> getDefaultMapCreator(boolean concurrent)
Returns a map supplier that fullfills the given requirements. It preserves (or not) the insertion order of its values according toisInsertionOrderPreserved().- Parameters:
concurrent- true to make the maps thread-safe- Returns:
- a map supplier corresponding to the given settings
-
-