- java.lang.Object
-
- xyz.tozymc.configuration.memory.MemoryConfigSection
-
- All Implemented Interfaces:
DataStorage,TcConfigSection
- Direct Known Subclasses:
FileConfigSection
public abstract class MemoryConfigSection extends Object implements TcConfigSection
The type ofTcConfigSectionthat is stored in memory.- Since:
- 1.0
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedMemoryConfigSection()Constructs new rootTcConfigSection.protectedMemoryConfigSection(@NotNull TcConfigSection parent, @NotNull String name)Constructs new childTcConfigSection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull TcConfigSectioncreateChild(@NotNull String path)Creates and returns the child section with specified path.@NotNull TcConfigSectioncreateChild(@NotNull String path, Map<String,?> values)Creates the child section by specified path with given values and returns it.@Nullable Objectget(@NotNull String path)Gets the object with given path.<T> Tget(@NotNull String path, @NotNull Class<T> type)Gets the value with given path.@Nullable TcConfigSectiongetChild(@NotNull String path)Gets the child section with specified path.@NotNull StringgetFullPath()Gets the path of this section.@UnmodifiableView @NotNull Set<String>getKeys(boolean deep)Gets the set of key that contains in this storage.@NotNull StringgetName()Gets the name of this section.<T> TgetOrDefault(@NotNull String path, @NotNull Class<T> type, T def)Gets the value with given path, returns the default value if requested value is null.@Nullable ObjectgetOrDefault(@NotNull String path, @Nullable Object def)Gets the value with given path, returns the default value if requested value is null.@Nullable TcConfigSectiongetParent()Gets the section that contains this section.@NotNull TcConfiggetRoot()Gets the root config that contains this section.@NotNull Map<String,?>getValues()Gets the copy map of values.booleanhasChild(@NotNull String path)Checks if this section contains the given path and the given path is configuration section.protected voidreloadSection(Map<String,?> map)@Nullable Objectset(@NotNull String path, @Nullable Object value)Sets the value to which the path is specified.@Nullable ObjectsetIfAbsent(@NotNull String path, @Nullable Object value)Sets the value to which the path is specified, the action is canceled when the path isn't in this storage.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface xyz.tozymc.configuration.DataStorage
compute, computeIfAbsent, computeIfPresent, contains, contains, find, find, getBoolean, getDouble, getDoubleList, getInt, getIntegerList, getKeys, getList, getList, getLong, getMapList, getString, getStringList, isBoolean, isDouble, isInt, isList, isLong, isString, merge, remove, replace
-
-
-
-
Constructor Detail
-
MemoryConfigSection
protected MemoryConfigSection()
Constructs new rootTcConfigSection.
-
MemoryConfigSection
protected MemoryConfigSection(@NotNull @NotNull TcConfigSection parent, @NotNull @NotNull String name)
Constructs new childTcConfigSection.- Parameters:
parent- Parent containing the child section.name- Name of section.
-
-
Method Detail
-
get
@Nullable public <T> T get(@NotNull @NotNull String path, @NotNull @NotNull Class<T> type)
Description copied from interface:DataStorageGets the value with given path.If the requested is instance of
TcConfigSection, the requested value will be deserialized to new object.If the requested value isn't instance of the type, this method will return
null.- Specified by:
getin interfaceDataStorage- Type Parameters:
T- Type of value.- Parameters:
path- Path to value.type- The class type of value.- Returns:
- The requested object.
- See Also:
TcConfigSerializations.deserializeObject(Class, Map)
-
getOrDefault
@Nullable public <T> T getOrDefault(@NotNull @NotNull String path, @NotNull @NotNull Class<T> type, @Nullable T def)
Description copied from interface:DataStorageGets the value with given path, returns the default value if requested value is null.If the requested is instance of
TcConfigSection, the requested value will be deserialized to new object.- Specified by:
getOrDefaultin interfaceDataStorage- Type Parameters:
T- Type of value.- Parameters:
path- Path to value.type- The class type of value.def- The default value.- Returns:
- The requested object.
- See Also:
TcConfigSerializations.deserializeObject(Class, Map)
-
get
@Nullable public @Nullable Object get(@NotNull @NotNull String path)
Description copied from interface:DataStorageGets the object with given path.- Specified by:
getin interfaceDataStorage- Parameters:
path- Path to object.- Returns:
- The requested object.
-
getOrDefault
@Nullable public @Nullable Object getOrDefault(@NotNull @NotNull String path, @Nullable @Nullable Object def)
Description copied from interface:DataStorageGets the value with given path, returns the default value if requested value is null.- Specified by:
getOrDefaultin interfaceDataStorage- Parameters:
path- Path to value.def- The default value.- Returns:
- The requested object.
-
set
@Nullable public @Nullable Object set(@NotNull @NotNull String path, @Nullable @Nullable Object value)
Description copied from interface:DataStorageSets the value to which the path is specified.If
valueis null, the path will be removed.- Specified by:
setin interfaceDataStorage- Parameters:
path- The path where the value will be set.value- The value to set.- Returns:
- The previous value.
-
setIfAbsent
@Nullable public @Nullable Object setIfAbsent(@NotNull @NotNull String path, @Nullable @Nullable Object value)
Description copied from interface:DataStorageSets the value to which the path is specified, the action is canceled when the path isn't in this storage.- Specified by:
setIfAbsentin interfaceDataStorage- Parameters:
path- The path where the value will be set.value- The value to set.- Returns:
- The previous value.
-
getKeys
@NotNull public @UnmodifiableView @NotNull Set<String> getKeys(boolean deep)
Description copied from interface:DataStorageGets the set of key that contains in this storage.If
deepistrue, this method will take the keys until the key isn't the key of the storage. Otherwise, this method only takes the 1st layer of this storage.- Specified by:
getKeysin interfaceDataStorage- Parameters:
deep- Whether to take the keys of the child storage.- Returns:
- Set of keys contained within this storage.
-
getValues
@NotNull public @NotNull Map<String,?> getValues()
Description copied from interface:DataStorageGets the copy map of values.Mapwill be representingTcConfigSection.- Specified by:
getValuesin interfaceDataStorage- Returns:
- Copy map of values.
-
hasChild
public boolean hasChild(@NotNull @NotNull String path)
Description copied from interface:TcConfigSectionChecks if this section contains the given path and the given path is configuration section.- Specified by:
hasChildin interfaceTcConfigSection- Parameters:
path- Path to child.- Returns:
- True if this section contains this path and this path is configuration section.
-
createChild
@NotNull public @NotNull TcConfigSection createChild(@NotNull @NotNull String path) throws TcConfigException
Description copied from interface:TcConfigSectionCreates and returns the child section with specified path.- Specified by:
createChildin interfaceTcConfigSection- Parameters:
path- The path where the child section will be created.- Returns:
- The created child section.
- Throws:
TcConfigException- Thrown when path is existed.
-
createChild
@NotNull public @NotNull TcConfigSection createChild(@NotNull @NotNull String path, Map<String,?> values) throws TcConfigException
Description copied from interface:TcConfigSectionCreates the child section by specified path with given values and returns it.- Specified by:
createChildin interfaceTcConfigSection- Parameters:
path- The path where the child section will be created.values- The values to set.- Returns:
- The created child section.
- Throws:
TcConfigException- Thrown when path is existed.
-
getChild
@Nullable public @Nullable TcConfigSection getChild(@NotNull @NotNull String path)
Description copied from interface:TcConfigSectionGets the child section with specified path.Returns
nullwhen child section not found.- Specified by:
getChildin interfaceTcConfigSection- Parameters:
path- Path to child.- Returns:
- The specified child section.
-
getParent
@Nullable public @Nullable TcConfigSection getParent()
Description copied from interface:TcConfigSectionGets the section that contains this section.Returns
nullwhen this section is root.- Specified by:
getParentin interfaceTcConfigSection- Returns:
- The section that contains this section.
-
getName
@NotNull public @NotNull String getName()
Description copied from interface:TcConfigSectionGets the name of this section.- Specified by:
getNamein interfaceTcConfigSection- Returns:
- This section name.
-
getFullPath
@NotNull public @NotNull String getFullPath()
Description copied from interface:TcConfigSectionGets the path of this section.The path can be used in the root config to get this section.
- Specified by:
getFullPathin interfaceTcConfigSection- Returns:
- This section path.
-
getRoot
@NotNull public @NotNull TcConfig getRoot()
Description copied from interface:TcConfigSectionGets the root config that contains this section.- Specified by:
getRootin interfaceTcConfigSection- Returns:
- The root config.
-
-