Class MemorySection
- All Implemented Interfaces:
ConfigurationSection
- Direct Known Subclasses:
MemoryConfiguration
Synchronized with the commit on 07-June-2022.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs an empty memory section for use as a root configuration section. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDefault(@NotNull String path, @Nullable Object value) Sets the default value in the root at the given path as provided.protected final voidclear()Clears the internal map.final booleanChecks if this configuration section contains the given path.final booleanChecks if this configuration section contains the given path.static @NotNull StringcreatePath(@NotNull ConfigurationSection section, @Nullable String key) Creates a full path to the given configuration section from its root configuration.static @NotNull StringcreatePath(@NotNull ConfigurationSection section, @Nullable String key, @Nullable ConfigurationSection relative) Creates a relative path to the given configuration section from the given relative section.final @NotNull ConfigurationSectioncreateSection(@NotNull String path) Creates an empty configuration section at the given path.final @NotNull ConfigurationSectioncreateSection(@NotNull String path, @NotNull Map<?, ?> map) Creates a configuration section at the given path, with the given values.final @Nullable ObjectGets the value at the given path.final @Nullable ObjectGets the value at the given path, returning the given default value if one has not been set.final booleangetBoolean(@NotNull String path) Gets the boolean value at the given path.final booleangetBoolean(@NotNull String path, boolean def) Gets the boolean value at the given path.getBooleanList(@NotNull String path) Gets the list of booleans at the given path.final byteGets the byte value at the given path.final byteGets the byte value at the given path.getByteList(@NotNull String path) Gets the list of bytes at the given path.final charGets the char value at the given path.final charGets the char value at the given path.getCharList(@NotNull String path) Gets the list of chars at the given path.getComments(@NotNull String path) Gets the comments by path.final @Nullable ConfigurationSectiongetConfigurationSection(@NotNull String path) Gets the configuration section value at the given path.final @NotNull StringGets the path of this configuration section from its root configuration.final @Nullable ConfigurationSectionGets the equivalent configuration section from the default configuration defined inConfigurationSection.getRoot().final doubleGets the double value at the given path.final doubleGets the double value at the given path.getDoubleList(@NotNull String path) Gets the list of doubles at the given path.final floatGets the float value at the given path.final floatGets the float value at the given path.getFloatList(@NotNull String path) Gets the list of floats at the given path.getInlineComments(@NotNull String path) Gets the inline comments by path.final intGets the int value at the given path.final intGets the int value at the given path.getIntList(@NotNull String path) Gets the list of ints at the given path.getKeys(boolean deep) Gets a set containing a copy of all keys in this configuration section.final @Nullable List<?>Gets the list value at the given path.final @Nullable List<?>Gets the list value at the given path.final longGets the long value at the given path.final longGets the long value at the given path.getLongList(@NotNull String path) Gets the list of longs at the given path.getMapList(@NotNull String path) Gets the list of maps at the given path.final @NotNull StringgetName()Gets the name of this individual configuration section in its path.final <T> TGets the value of typeTat the given path.final <T> TGets the value of typeTat the given path.@Nullable ConfigurationSectionGets the parent configuration section that directly contains this section.final @Nullable ConfigurationgetRoot()Gets the root configuration that contains this configuration section.final <T extends ConfigurationSerializable>
TgetSerializable(@NotNull String path, @NotNull Class<T> clazz) Gets the configuration serializable value of typeTat the given path.final <T extends ConfigurationSerializable>
TgetSerializable(@NotNull String path, @NotNull Class<T> clazz, T def) Gets the configuration serializable value of typeTvalue at the given path.final shortGets the short value at the given path.final shortGets the short value at the given path.getShortList(@NotNull String path) Gets the list of shorts at the given path.final @Nullable StringGets the string value at the given path.final @Nullable StringGets the string value at the given path.getStringList(@NotNull String path) Gets the list of strings at the given path.getValues(boolean deep) Gets a map containing a copy of all keys and their respective values for this configuration section.final booleanChecks if the value at the given path is a boolean.final booleanChecks if the value at the given path is a byte.final booleanChecks if the value at the given path is a char.final booleanisConfigurationSection(@NotNull String path) Checks if the value at the given path is a configuration section.final booleanChecks if the value at the given path is a double.final booleanChecks if the value at the given path is a float.final booleanChecks if the value at the given path is an int.final booleanChecks if the value at the given path is a generic list.final booleanChecks if the value at the given path is a long.final booleanChecks if the value at the given path is a number.final booleanChecks if this configuration section has a value set for the given path.final booleanChecks if the value at the given path is a short.final booleanChecks if the value at the given path is a string.final voidSets the given path to the given value.final voidsetComments(@NotNull String path, @Nullable List<String> comments) Sets the comments at the given path.final voidsetInlineComments(@NotNull String path, @Nullable List<String> inlineComments) Sets the inline comments at the given path.final @NotNull StringtoString()Creates a string representation of this memory section.
-
Constructor Details
-
MemorySection
Constructs an empty memory section for use as a root configuration section.NOTE: If the new memory section is not a configuration, an illegal argument exception will be thrown, as a configuration section cannot be orphaned by default, and all configuration sections must contain a root configuration.
- Throws:
IllegalStateException- If the new memory section is not a configuration.
-
-
Method Details
-
getKeys
Gets a set containing a copy of all keys in this configuration section.If
deepis set totrue, then the set will contain all keys within this configuration section as well as the keys of any children sections of this section, working recursively down through each child's potential children. As a result, all the keys will be the fully-qualified paths.If
deepis set tofalse, then the set will contain only the keys of any values of this configuration section, even if those values themselves are children configuration sections.In either case, the set will be unmodifiable, and any updates to the keys of this configuration section will not be reflected in the returned set.
- Specified by:
getKeysin interfaceConfigurationSection- Parameters:
deep-trueif the set is to contain the keys of the children configuration section(s) of this section (recursive),falseotherwise.- Returns:
- A copy of the set of keys contained within this configuration section.
-
getValues
Gets a map containing a copy of all keys and their respective values for this configuration section.If
deepis set totrue, then the map will contain all key-value pairings within this configuration section, as well as the key-value pairings of any children sections of this section, working recursively down through each child's potential children. As a result, all the keys will be the fully-qualified paths.If
deepis set tofalse, then the map will contain only the key-value pairings of this configuration section, even if those values themselves are children configuration sections.In either case, the map will be unmodifiable, and any updates to the keys, values, or the pairings of this configuration section will not be reflected in the returned set.
- Specified by:
getValuesin interfaceConfigurationSection- Parameters:
deep-trueif the map is to contain the key-value pairings of the children configuration section(s) of this section (recursive),falseotherwise.- Returns:
- A copy of the map of key-value pairings contained within this configuration section.
-
getCurrentPath
Gets the path of this configuration section from its root configuration.If this configuration section is a configuration itself, this will return an empty string.
If this configuration section is no longer contained within a root configuration for any reason, such as being replaced with a different value, this may return
null.This will return the fully-qualified path of this section. If only the final part of the path of this section is desired, please use
ConfigurationSection.getName().- Specified by:
getCurrentPathin interfaceConfigurationSection- Returns:
- The fully-qualified path of this configuration section relative
to its root configuration, or
nullif this section is orphaned.
-
getName
Gets the name of this individual configuration section in its path.This will always be the final part of
ConfigurationSection.getCurrentPath(), unless this configuration section is orphaned.- Specified by:
getNamein interfaceConfigurationSection- Returns:
- The name of this configuration section.
-
getRoot
Gets the root configuration that contains this configuration section.If this configuration section is itself a configuration, this will return this section.
If this configuration section is no longer contained within a root configuration for any reason, such as being replaced with a different value, this may return
null.- Specified by:
getRootin interfaceConfigurationSection- Returns:
- The root configuration containing this configuration section, or
nullif this section is orphaned.
-
getParent
Gets the parent configuration section that directly contains this section.If this configuration section is itself a configuration, this will return
null.If this configuration section is no longer contained within a root configuration for any reason, such as being replaced with a different value, this may return
null.- Specified by:
getParentin interfaceConfigurationSection- Returns:
- The parent configuration section containing this section, or
nullif this section does not have a parent.
-
getDefaultSection
Gets the equivalent configuration section from the default configuration defined inConfigurationSection.getRoot().If the root configuration contains no defaults, or the defaults do not contain a value for this configuration section's path, or the value at this path is not itself a configuration section, this will return
null.- Specified by:
getDefaultSectionin interfaceConfigurationSection- Returns:
- The equivalent configuration section in the default
configuration, or
nullif one does not exist or is not the correct type.
-
addDefault
Sets the default value in the root at the given path as provided.If no source configuration was provided as a default collection, then a new memory configuration will be created to hold the given default value.
If value is
null, the value will be removed from the default configuration source.If the value as returned by
ConfigurationSection.getDefaultSection()isnull, then this will create a new configuration section at the path, replacing anything that may have existed there previously.- Specified by:
addDefaultin interfaceConfigurationSection- Parameters:
path- The path of the default value to set.value- The value to set the default to.
-
getComments
@NotNull public final @NotNull @UnmodifiableView List<String> getComments(@NotNull @NotNull String path) Gets the comments by path.If no comments exist, and empty list will be returned. A
nullentry represents an empty line and an empty string represents an empty comment line (#with nothing after it).The returned list will be unmodifiable, and any changes to the underlying comments in this configuration section will not be reflected in the returned list.
- Specified by:
getCommentsin interfaceConfigurationSection- Parameters:
path- The path of the comments to get.- Returns:
- The comments as a list, where every entry represents a separate line.
-
getInlineComments
@NotNull public final @NotNull @UnmodifiableView List<String> getInlineComments(@NotNull @NotNull String path) Gets the inline comments by path.If no comments exist, an empty list will be returned. A
nullentry represents an empty line and an empty string represents an empty comment line (#with nothing after it).The returned list will be unmodifiable, and any changes to the underlying inline comments in this configuration section will not be reflected in the returned list.
- Specified by:
getInlineCommentsin interfaceConfigurationSection- Parameters:
path- The path of the comments to get.- Returns:
- The inline comments as a list, where every entry represents a separate line.
-
setComments
public final void setComments(@NotNull @NotNull String path, @Nullable @Nullable List<String> comments) Sets the comments at the given path.If the given list is
nullitself, any existing comments will be removed. Otherwise, the existing comments will be replaced with the contents of the given list, regardless of the previous comment values.A
nullentry in the list will result in an empty line, and an empty string as an entry will result in an empty comment line (#with nothing after it).- Specified by:
setCommentsin interfaceConfigurationSection- Parameters:
path- The path of the comments to set.comments- The new comments to set at the given path, where every entry in the list represents one line.nullto remove any existing comments.
-
setInlineComments
public final void setInlineComments(@NotNull @NotNull String path, @Nullable @Nullable List<String> inlineComments) Sets the inline comments at the given path.If the given list is
nullitself, any existing inline comments will be removed. Otherwise, the existing inline comments will be replaced with the contents of the given list, regardless of the previous comment values.A
nullentry in the list will result in an empty line, and an empty string as an entry will result in an empty comment line (#with nothing after it).- Specified by:
setInlineCommentsin interfaceConfigurationSection- Parameters:
path- The path of the inline comments to set.inlineComments- The new inline comments to set at the given path, where every entry in the list represents one line.nullto remove any existing inline comments.
-
createSection
Creates an empty configuration section at the given path.Any value that was previously set at this path will be overwritten. If the previous value was a configuration section itself, that section will be orphaned.
- Specified by:
createSectionin interfaceConfigurationSection- Parameters:
path- The path to create the configuration section at.- Returns:
- The newly-created configuration section.
-
createSection
@NotNull public final @NotNull ConfigurationSection createSection(@NotNull @NotNull String path, @NotNull @NotNull Map<?, ?> map) Creates a configuration section at the given path, with the given values.Any value that was previously set at this path will be overwritten. If the previous value was a configuration section itself, that section will be orphaned.
- Specified by:
createSectionin interfaceConfigurationSection- Parameters:
path- The path to create the configuration section at.map- The key-value pairings to place in the newly-created configuration section.- Returns:
- The newly-created configuration section.
-
isSet
Checks if this configuration section has a value set for the given path.If the value for the given path does not exist but a default value has been set, this will still return
false. If the status of a default value is desired, please useConfigurationSection.contains(String).- Specified by:
isSetin interfaceConfigurationSection- Parameters:
path- The path to check for existence.- Returns:
trueif this configuration section contains the given path, regardless of having a default,falseotherwise.- See Also:
-
set
Sets the given path to the given value. Any existing value will be replaced, regardless of what it and the new given value are.If the given value is
null, the entry will be removed.The given value may not be a configuration or a configuration section. If a new configuration section is desired, please use
ConfigurationSection.createSection(String).- Specified by:
setin interfaceConfigurationSection- Parameters:
path- The path to the given value.value- The new value to store at the given path.
-
contains
Checks if this configuration section contains the given path.If the value for the given path does not exist but a default value has been set, this will return
true. If the existence of a default value is to be ignored, please useConfigurationSection.contains(String, boolean), whereignoreDefaultistrue.- Specified by:
containsin interfaceConfigurationSection- Parameters:
path- The path to check for existence.- Returns:
trueif this configuration section contains the given path, either via an actual value or default value being set,falseotherwise.- See Also:
-
contains
Checks if this configuration section contains the given path.If
trueis given forignoreDefault, then this will returntrueonly if a value has been set for the given path.If
falseis given forignoreDefaults, then this will returntrueif a value has been set for the given path, or if a default value has been set for the given path.- Specified by:
containsin interfaceConfigurationSection- Parameters:
path- The path to check for existence.ignoreDefault-trueif any default values should be ignored when checking for a value at the path,falseotherwise.- Returns:
trueif this configuration section contains an actual value at the given path, or if a default value has been set andignoreDefaultisfalse,falseotherwise.
-
get
Gets the value at the given path.If a value has not been set at the given path, but a default value has been set, this will return the default value. If no value and no default value have been set, this will return
null.- Specified by:
getin interfaceConfigurationSection- Parameters:
path- The path of the value to retrieve.- Returns:
- The requested value.
-
get
@Contract("_, !null -> !null") @Nullable public final @Nullable Object get(@NotNull @NotNull String path, @Nullable @Nullable Object def) Gets the value at the given path, returning the given default value if one has not been set.If a value has not been set at the given path, the given default value will be returned, regardless of whether a default value exists in the root configuration.
- Specified by:
getin interfaceConfigurationSection- Parameters:
path- The path of the value to retrieve.def- The value to use as a default.- Returns:
- The requested value.
-
isBoolean
Checks if the value at the given path is a boolean.If the value exists at the given path but is not a boolean, this will return
false.If the value does not exist at the given path but a default value has been set, this will check the default value and return appropriately.
- Specified by:
isBooleanin interfaceConfigurationSection- Parameters:
path- The path of the boolean to check.- Returns:
trueif a boolean value exists, or if there is no value, a default has been set, and it is a boolean,falseotherwise.
-
getBoolean
Gets the boolean value at the given path.If the value exists at the given path but is not a boolean, this will return
false.If the value does not exist at the given path, but a default value has been set, this will check that value and return similar to the above.
- Specified by:
getBooleanin interfaceConfigurationSection- Parameters:
path- The path of the boolean to retrieve.- Returns:
- The requested boolean.
-
getBoolean
Gets the boolean value at the given path.If the value exists at the given path but is not a boolean, or if the value does not exist at the given path, this will return the given default.
If a default value has been set in the root configuration, it will be ignored, even if the given path does not have a set value.
- Specified by:
getBooleanin interfaceConfigurationSection- Parameters:
path- The path of the boolean to retrieve.def- The boolean to use as the default.- Returns:
- The requested boolean.
-
isNumber
Checks if the value at the given path is a number.If the value exists at the given path but is not a number, this will return
false.If the value does not exist at the give path but a default value has been set, this will check that value and return appropriately.
This method is meant to be a more generic check than the specific number-based checks below, such as
ConfigurationSection.isByte(String), orConfigurationSection.isDouble(String). Those methods check to see if the requested value (or default) is of the exact type, whereas this method will simply check for a number.- Specified by:
isNumberin interfaceConfigurationSection- Parameters:
path- The path of the number to check.- Returns:
trueif a number value exists, or if there is no value, a default has been set, and it is a number,falseotherwise.- See Also:
-
isByte
Checks if the value at the given path is a byte.If the value exists at the given path but is not a byte, this will return
false.If the value does not exist at the given path but a default value has been set, this will check that value and return appropriately.
This method will check to see if the requested value (or default) is specifically a byte. If the value is another type of number, this will return
false. To check for a generic number please useConfigurationSection.isNumber(String).- Specified by:
isBytein interfaceConfigurationSection- Parameters:
path- The path of the byte to check.- Returns:
trueif a byte value exists, or if there is no value, a default has been set, and it is a byte,falseotherwise.- See Also:
-
getByte
Gets the byte value at the given path.If the value exists at the given path but is not a byte, this will return
(byte) 0.If the value does not exist at the given path, but a default value has been set, this will check that value and return similar to the above.
- Specified by:
getBytein interfaceConfigurationSection- Parameters:
path- The path of the byte to retrieve.- Returns:
- The requested byte.
-
getByte
Gets the byte value at the given path.If the value exists at the given path but is not a byte, or if the value does not exist at the given path, this will return the given default.
If a default value has been set in the root configuration, it will be ignored, even if the given path does not have a set value.
- Specified by:
getBytein interfaceConfigurationSection- Parameters:
path- The path of the byte to retrieve.def- The byte to use as the default.- Returns:
- The requested byte.
-
isShort
Checks if the value at the given path is a short.If the value exists at the given path but is not a short, this will return
false.If the value does not exist at the given path but a default value has been set, this will check that value and return appropriately.
This method will check to see if the requested value (or default) is specifically a short. If the value is another type of number, this will return
false. To check for a generic number, please useConfigurationSection.isNumber(String).- Specified by:
isShortin interfaceConfigurationSection- Parameters:
path- The path of the short to check.- Returns:
trueif a short value exists, or if there is no value, a default has been set, and it is a short,falseotherwise.- See Also:
-
getShort
Gets the short value at the given path.If the value exists at the given path but is not a short, this will return
(short) 0.If the value does not exist at the given path, but a default value has been set, this will check that value and return similar to the above.
- Specified by:
getShortin interfaceConfigurationSection- Parameters:
path- The path of the short to retrieve.- Returns:
- The requested short.
-
getShort
Gets the short value at the given path.If the value exists at the given path but is not a short, or if the value does not exist at the given path, this will return the given default.
If a default value has been set in the root configuration, it will be ignored, even if the given path does not have a set value.
- Specified by:
getShortin interfaceConfigurationSection- Parameters:
path- The path of the short to retrieve.def- The short to use as the default.- Returns:
- The requested short.
-
isInt
Checks if the value at the given path is an int.If the value exists at the given path but is not an int, this will return
false.If the value does not exist at the given path but a default value has been set, this will check that value and return appropriately.
This method will check to see if the requested value (or default) is specifically an int. If the value is another type of number, this will return
false. To check for a generic number, please useConfigurationSection.isNumber(String).- Specified by:
isIntin interfaceConfigurationSection- Parameters:
path- The path of the int to check.- Returns:
trueif an int value exists, or if there is no value, a default has been set, and it is an int,falseotherwise.- See Also:
-
getInt
Gets the int value at the given path.If the value exists at the given path but is not an int, this will return
0.If the value does not exist at the given path, but a default value has been set, this will check that value and return similar to the above.
- Specified by:
getIntin interfaceConfigurationSection- Parameters:
path- The path of the int to retrieve.- Returns:
- The requested int.
-
getInt
Gets the int value at the given path.If the value exists at the given path but is not an int, or if the value does not exist at the given path, this will return the given default.
If a default value has been set in the root
Configuration, it will be ignored, even if the given path does not have a set value.- Specified by:
getIntin interfaceConfigurationSection- Parameters:
path- The path of the int to retrieve.def- The int to use as the default.- Returns:
- The requested int.
-
isLong
Checks if the value at the given path is a long.If the value exists at the given path but is not a long, this will return
false.If the value does not exist at the given path but a default value has been set, this will check that value and return appropriately.
This method will check to see if the requested value (or default) is specifically a long. If the value is another type of number, this will return
false. To check for a generic number, please useConfigurationSection.isNumber(String).- Specified by:
isLongin interfaceConfigurationSection- Parameters:
path- The path of the long to check.- Returns:
trueif a long value exists, or if there is no value, a default has been set, and it is a long,falseotherwise.- See Also:
-
getLong
Gets the long value at the given path.If the value exists at the given path but is not a long, this will return
0L.If the value does not exist at the given path, but a default value has been set, this will check that value and return similar to the above.
- Specified by:
getLongin interfaceConfigurationSection- Parameters:
path- The path of the long to retrieve.- Returns:
- The requested long.
-
getLong
Gets the long value at the given path.If the value exists at the given path but is not a long, or if the value does not exist at the given path, this will return the given default.
If a default value has been set in the root configuration, it will be ignored, even if the given path does not have a set value.
- Specified by:
getLongin interfaceConfigurationSection- Parameters:
path- The path of the long to retrieve.def- The long to use as the default.- Returns:
- The requested long.
-
isFloat
Checks if the value at the given path is a float.If the value exists at the given path but is not a float, this will return
false.If the value does not exist at the given path but a default value has been set, this will check that value and return appropriately.
This method will check to see if the requested value (or default) is specifically a float. If the value is another type of number, this will return
false. To check for a generic number, please useConfigurationSection.isNumber(String).- Specified by:
isFloatin interfaceConfigurationSection- Parameters:
path- The path of the float to check.- Returns:
trueif a float value exists, or if there is no value, a default has been set, and it is a float,falseotherwise.- See Also:
-
getFloat
Gets the float value at the given path.If the value exists at the given path but is not a float, this will return
0.0F.If the value does not exist at the given path, but a default value has been set, this will check that value and return similar to the above.
- Specified by:
getFloatin interfaceConfigurationSection- Parameters:
path- The path of the float to retrieve.- Returns:
- The requested float.
-
getFloat
Gets the float value at the given path.If the value exists at the given path but is not a float, or if the value does not exist at the given path, this will return the given default.
If a default value has been set in the root configuration, it will be ignored, even if the given path does not have a set value.
- Specified by:
getFloatin interfaceConfigurationSection- Parameters:
path- The path of the float to retrieve.def- The float to use as the default.- Returns:
- The requested float.
-
isDouble
Checks if the value at the given path is a double.If the value exists at the given path but is not a double, this will return
false.If the value does not exist at the given path but a default value has been set, this will check that value and return appropriately.
This method will check to see if the requested value (or default) is specifically a double. If the value is another type of number, this will return
false. To check for a generic number, please useConfigurationSection.isNumber(String).- Specified by:
isDoublein interfaceConfigurationSection- Parameters:
path- The path of the double to check.- Returns:
trueif a double value exists, or if there is no value, a default has been set, and it is a double,falseotherwise.- See Also:
-
getDouble
Gets the double value at the given path.If the value exists at the given path but is not a double, this will return
0.0D.If the value does not exist at the given path, but a default value has been set, this will check that value and return similar to the above.
- Specified by:
getDoublein interfaceConfigurationSection- Parameters:
path- The path of the double to retrieve.- Returns:
- The requested double.
-
getDouble
Gets the double value at the given path.If the value exists at the given path but is not a double, or if the value does not exist at the given path, this will return the given default.
If a default value has been set in the root configuration, it will be ignored, even if the given path does not have a set value.
- Specified by:
getDoublein interfaceConfigurationSection- Parameters:
path- The path of the double to retrieve.def- The double to use as the default.- Returns:
- The requested double.
-
isChar
Checks if the value at the given path is a char.If the value exists at the given path but is not a char, this will return
false.If the value does not exist at the given path but a default value has been set, this will check that value and return appropriately.
- Specified by:
isCharin interfaceConfigurationSection- Parameters:
path- The path of the char to check.- Returns:
trueif a char value exists, or if there is no value, a default has been set, and it is a char,falseotherwise.
-
getChar
Gets the char value at the given path.If the value exists at the given path but is not a char, this will return
-