Class AbstractConfig
- java.lang.Object
-
- com.electronwill.nightconfig.core.AbstractConfig
-
- All Implemented Interfaces:
Config,UnmodifiableConfig,java.lang.Cloneable
- Direct Known Subclasses:
AbstractCommentedConfig
public abstract class AbstractConfig extends java.lang.Object implements Config, java.lang.Cloneable
An abstract Config that uses aMapto store its values. In practice it's often a HashMap, or a ConcurrentHashMap if the config is concurrent, but it accepts any type of Map.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractConfig.EntryWrapperA wrapper around aMap.Entry<String, Object>.-
Nested classes/interfaces inherited from interface com.electronwill.nightconfig.core.Config
Config.Entry
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>>mapCreator
-
Constructor Summary
Constructors Constructor Description AbstractConfig(boolean concurrent)Creates a new AbstractConfig backed by a newMap.AbstractConfig(UnmodifiableConfig toCopy, boolean concurrent)Creates a new AbstractConfig that is a copy of the specified config.AbstractConfig(UnmodifiableConfig toCopy, java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>> mapCreator)Creates a new AbstractConfig that is a copy of the specified config, and with all backing maps supplied by the givenSupplier.AbstractConfig(java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>> mapCreator)Creates a new AbstractConfig with all backing maps supplied by the givenSupplier.AbstractConfig(java.util.Map<java.lang.String,java.lang.Object> map)Creates a new AbstractConfig backed by the specifiedMap.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanadd(java.util.List<java.lang.String> path, java.lang.Object value)Adds a config value.voidclear()Removes all values from the config.abstract AbstractConfigclone()Creates and return a copy of this config.booleancontains(java.util.List<java.lang.String> path)Checks if the config contains a value at some path.java.util.Set<? extends Config.Entry>entrySet()Returns a Set view of the config's entries.booleanequals(java.lang.Object obj)protected 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.<T> TgetRaw(java.util.List<java.lang.String> path)Gets a value from the config.protected static <T> java.util.function.Supplier<java.util.Map<java.lang.String,T>>getWildcardMapCreator(java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>> mapCreator)inthashCode()booleanisNull(java.util.List<java.lang.String> path)Checks if the config contains a null value at some path.<T> Tremove(java.util.List<java.lang.String> path)Removes a value from the config.<T> Tset(java.util.List<java.lang.String> path, java.lang.Object value)Sets a config value.intsize()Gets the size of the config.java.lang.StringtoString()java.util.Map<java.lang.String,java.lang.Object>valueMap()Returns a Map view of the config's values.-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.electronwill.nightconfig.core.Config
add, addAll, checked, createSubConfig, putAll, remove, removeAll, set, unmodifiable, update, update
-
Methods inherited from interface com.electronwill.nightconfig.core.UnmodifiableConfig
apply, apply, configFormat, 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, getShort, getShort, getShortOrElse, getShortOrElse, isEmpty, isNull
-
-
-
-
Constructor Detail
-
AbstractConfig
public AbstractConfig(boolean concurrent)
Creates a new AbstractConfig backed by a newMap.
-
AbstractConfig
public AbstractConfig(java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>> mapCreator)
Creates a new AbstractConfig with all backing maps supplied by the givenSupplier.- Parameters:
mapCreator- A supplier that will be called to create all config maps
-
AbstractConfig
public AbstractConfig(java.util.Map<java.lang.String,java.lang.Object> map)
Creates a new AbstractConfig backed by the specifiedMap.- Parameters:
map- the map to use to store the config values.
-
AbstractConfig
public AbstractConfig(UnmodifiableConfig toCopy, boolean concurrent)
Creates a new AbstractConfig that is a copy of the specified config.- Parameters:
toCopy- the config to copy
-
AbstractConfig
public AbstractConfig(UnmodifiableConfig toCopy, java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>> mapCreator)
Creates a new AbstractConfig that is a copy of the specified config, and with all backing maps supplied by the givenSupplier.- Parameters:
toCopy- the config to copymapCreator- A supplier that will be called to create all config maps
-
-
Method Detail
-
getDefaultMapCreator
protected static <T> java.util.function.Supplier<java.util.Map<java.lang.String,T>> getDefaultMapCreator(boolean concurrent)
Description copied from interface:ConfigReturns a map supplier that fullfills the given requirements. It preserves (or not) the insertion order of its values according toConfig.isInsertionOrderPreserved().- Parameters:
concurrent- true to make the maps thread-safe- Returns:
- a map supplier corresponding to the given settings
-
getWildcardMapCreator
protected static <T> java.util.function.Supplier<java.util.Map<java.lang.String,T>> getWildcardMapCreator(java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>> mapCreator)
-
getRaw
public <T> T getRaw(java.util.List<java.lang.String> path)
Description copied from interface:UnmodifiableConfigGets a value from the config. Doesn't convertNullObject.NULL_OBJECTtonull.- Specified by:
getRawin interfaceUnmodifiableConfig- Type Parameters:
T- the value's type- Parameters:
path- the value's path, each element of the list is a different part of the path.- Returns:
- the value at the given path, or
nullif there is no such value.
-
set
public <T> T set(java.util.List<java.lang.String> path, java.lang.Object value)Description copied from interface:ConfigSets a config value.
-
add
public boolean add(java.util.List<java.lang.String> path, java.lang.Object value)Description copied from interface:ConfigAdds a config value. The value is set iff there is no value associated with the given path.
-
remove
public <T> T remove(java.util.List<java.lang.String> path)
Description copied from interface:ConfigRemoves a value from the config.
-
contains
public boolean contains(java.util.List<java.lang.String> path)
Description copied from interface:UnmodifiableConfigChecks if the config contains a value at some path.- Specified by:
containsin interfaceUnmodifiableConfig- Parameters:
path- the path to check, each element of the list is a different part of the path.- Returns:
trueif the path is associated with a value,falseif it's not.
-
isNull
public boolean isNull(java.util.List<java.lang.String> path)
Description copied from interface:UnmodifiableConfigChecks if the config contains a null value at some path.- Specified by:
isNullin interfaceUnmodifiableConfig- Parameters:
path- the path to check, each element of the list is a different part of the path.- Returns:
trueif the path is associated withNullObject.NULL_OBJECT,falseif it's associated with another value or with no value.
-
clear
public void clear()
Description copied from interface:ConfigRemoves all values from the config.
-
size
public int size()
Description copied from interface:UnmodifiableConfigGets the size of the config.- Specified by:
sizein interfaceUnmodifiableConfig- Returns:
- the number of top-level elements in the config.
-
valueMap
public java.util.Map<java.lang.String,java.lang.Object> valueMap()
Description copied from interface:ConfigReturns a Map view of the config's values. Any change to the map is reflected in the config and vice-versa.- Specified by:
valueMapin interfaceConfig- Specified by:
valueMapin interfaceUnmodifiableConfig- Returns:
- a Map view of the config's values.
-
entrySet
public java.util.Set<? extends Config.Entry> entrySet()
Description copied from interface:ConfigReturns 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 interfaceConfig- Specified by:
entrySetin interfaceUnmodifiableConfig- Returns:
- a Set view of the config's entries.
-
clone
public abstract AbstractConfig clone()
Creates and return a copy of this config.- Overrides:
clonein classjava.lang.Object- Returns:
- a new Config that contains the same entries as this config.
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-