public class MemorySection extends Object implements ConfigurationSection
ConfigurationSection that is stored in memory.
Synchronized with the commit on 20-December-2021.| Modifier and Type | Field and Description |
|---|---|
protected Map<String,org.bspfsystems.yamlconfiguration.configuration.SectionPathData> |
map |
| Modifier | Constructor and Description |
|---|---|
protected |
MemorySection()
Creates an empty
MemorySection for use as a root
ConfigurationSection. |
protected |
MemorySection(@NotNull ConfigurationSection parent,
@NotNull String path)
Creates an empty
MemorySection with the specified parent and
path. |
| Modifier and Type | Method and Description |
|---|---|
void |
addDefault(@NotNull String path,
@Nullable Object value)
Sets the default value in the root at the given path as provided.
|
boolean |
contains(@NotNull String path)
Checks if this
ConfigurationSection contains the given path. |
boolean |
contains(@NotNull String path,
boolean ignoreDefault)
Checks if this
ConfigurationSection contains the given path. |
static @NotNull String |
createPath(@NotNull ConfigurationSection section,
@Nullable String key)
Creates a full path to the given
ConfigurationSection from its
root Configuration. |
static @NotNull String |
createPath(@NotNull ConfigurationSection section,
@Nullable String key,
@Nullable ConfigurationSection relative)
Creates a relative path to the given
ConfigurationSection from
the given relative ConfigurationSection. |
@NotNull ConfigurationSection |
createSection(@NotNull String path)
Creates an empty
ConfigurationSection at the specified path. |
@NotNull ConfigurationSection |
createSection(@NotNull String path,
@NotNull Map<?,?> map)
Creates a
ConfigurationSection at the specified path, with the
specified values. |
@Nullable Object |
get(@NotNull String path)
Gets the
Object at the given path. |
@Nullable Object |
get(@NotNull String path,
@Nullable Object def)
Gets the
Object at the given path, returning the given default
value if none has been set. |
boolean |
getBoolean(@NotNull String path)
Gets the
boolean value at the given path. |
boolean |
getBoolean(@NotNull String path,
boolean def)
Gets the
boolean value at the given path. |
@NotNull List<Boolean> |
getBooleanList(@NotNull String path)
|
byte |
getByte(@NotNull String path)
Gets the
byte value at the given path. |
byte |
getByte(@NotNull String path,
byte def)
Gets the
byte value at the given path. |
@NotNull List<Byte> |
getByteList(@NotNull String path)
|
char |
getChar(@NotNull String path)
Gets the
char value at the given path. |
char |
getChar(@NotNull String path,
char def)
Gets the
char value at the given path. |
@NotNull List<Character> |
getCharList(@NotNull String path)
Gets the
List of Characters at the given path. |
@NotNull List<String> |
getComments(@NotNull String path)
Gets the requested comment
List by path. |
@Nullable ConfigurationSection |
getConfigurationSection(@NotNull String path)
Gets the
ConfigurationSection value at the given path. |
@NotNull String |
getCurrentPath()
Gets the path of this
ConfigurationSection from its root
Configuration |
protected @Nullable Object |
getDefault(@NotNull String path)
Gets the default
Object for the given path. |
@Nullable ConfigurationSection |
getDefaultSection()
Gets the equivalent
ConfigurationSection from the default
Configuration defined in ConfigurationSection.getRoot(). |
double |
getDouble(@NotNull String path)
Gets the
double value at the given path. |
double |
getDouble(@NotNull String path,
double def)
Gets the
double value at the given path. |
@NotNull List<Double> |
getDoubleList(@NotNull String path)
|
float |
getFloat(@NotNull String path)
Gets the
float value at the given path. |
float |
getFloat(@NotNull String path,
float def)
Gets the
float value at the given path. |
@NotNull List<Float> |
getFloatList(@NotNull String path)
|
@NotNull List<String> |
getInLineComments(@NotNull String path)
Gets the requested inline comment
List by path. |
int |
getInt(@NotNull String path)
Gets the
int value at the given path. |
int |
getInt(@NotNull String path,
int def)
Gets the
int value at the given path. |
@NotNull List<Integer> |
getIntList(@NotNull String path)
|
@NotNull Set<String> |
getKeys(boolean deep)
Gets a
Set containing all keys in this
ConfigurationSection. |
@Nullable List<?> |
getList(@NotNull String path)
Gets the
List value at the given path. |
@Nullable List<?> |
getList(@NotNull String path,
@Nullable List<?> def)
Gets the
List value at the given path. |
long |
getLong(@NotNull String path)
Gets the
long value at the given path. |
long |
getLong(@NotNull String path,
long def)
Gets the
long value at the given path. |
@NotNull List<Long> |
getLongList(@NotNull String path)
|
@NotNull List<Map<?,?>> |
getMapList(@NotNull String path)
|
@NotNull String |
getName()
Gets the name of this individual
ConfigurationSection, in the
path. |
<T> T |
getObject(@NotNull String path,
@NotNull Class<T> clazz)
Gets the
Object value of type T at the given path. |
<T> T |
getObject(@NotNull String path,
@NotNull Class<T> clazz,
T def)
Gets the
Object value of type T at the given path. |
@Nullable ConfigurationSection |
getParent()
Gets the parent
ConfigurationSection that directly contains
this ConfigurationSection. |
@Nullable Configuration |
getRoot()
Gets the root
Configuration that contains this
ConfigurationSection |
<T extends ConfigurationSerializable> |
getSerializable(@NotNull String path,
@NotNull Class<T> clazz)
Gets the
ConfigurationSerializable value of type T at the
given path. |
<T extends ConfigurationSerializable> |
getSerializable(@NotNull String path,
@NotNull Class<T> clazz,
T def)
Gets the
ConfigurationSerializable value of type T value
at the given path. |
short |
getShort(@NotNull String path)
Gets the
short value at the given path. |
short |
getShort(@NotNull String path,
short def)
Gets the
short value at the given path. |
@NotNull List<Short> |
getShortList(@NotNull String path)
|
@Nullable String |
getString(@NotNull String path)
Gets the
String value at the given path. |
@Nullable String |
getString(@NotNull String path,
@Nullable String def)
Gets the
String value at the given path. |
@NotNull List<String> |
getStringList(@NotNull String path)
|
@NotNull Map<String,Object> |
getValues(boolean deep)
Gets a
Map containing all keys and their values for this
ConfigurationSection. |
boolean |
isBoolean(@NotNull String path)
Checks if the value at the given path is a
boolean. |
boolean |
isByte(@NotNull String path)
Checks if the value at the given path is a
byte. |
boolean |
isChar(@NotNull String path)
Checks if the value at the given path is a
char. |
boolean |
isConfigurationSection(@NotNull String path)
Checks if the value at the given path is a
ConfigurationSection. |
boolean |
isDouble(@NotNull String path)
Checks if the value at the given path is a
double. |
boolean |
isFloat(@NotNull String path)
Checks if the value at the given path is a
float. |
boolean |
isInt(@NotNull String path)
Checks if the value at the given path is an
int. |
boolean |
isList(@NotNull String path)
Checks if the value at the given path is a
List. |
boolean |
isLong(@NotNull String path)
Checks if the value at the given path is a
long. |
boolean |
isSet(@NotNull String path)
Checks if this
ConfigurationSection has a value set for the
given path. |
boolean |
isShort(@NotNull String path)
Checks if the value at the given path is a
short. |
boolean |
isString(@NotNull String path)
Checks if the value at the given path is a
String. |
protected void |
mapChildrenKeys(@NotNull Set<String> output,
@NotNull ConfigurationSection section,
boolean deep)
Maps the keys of the given child
ConfigurationSection. |
protected void |
mapChildrenValues(@NotNull Map<String,Object> output,
@NotNull ConfigurationSection section,
boolean deep)
Maps the key-value pairs of the given child
ConfigurationSection. |
void |
set(@NotNull String path,
@Nullable Object value)
Sets the specified path to the given value.
|
void |
setComments(@NotNull String path,
@Nullable List<String> comments)
Sets the comment
List at the specified path. |
void |
setInLineComments(@NotNull String path,
@Nullable List<String> inLineComments)
Sets the inline comment
List at the specified path. |
String |
toString()
Creates a
String representation of this MemorySection. |
protected MemorySection()
throws IllegalStateException
MemorySection for use as a root
ConfigurationSection.
Note: If the new MemorySection is not a
Configuration, an IllegalStateException will be thrown.
IllegalStateException - If the new MemorySection is not a
Configuration.protected MemorySection(@NotNull
@NotNull ConfigurationSection parent,
@NotNull
@NotNull String path)
MemorySection with the specified parent and
path.parent - The parent ConfigurationSection that contains the
new MemorySection.path - The path that the new MemorySection will be set on.IllegalArgumentException - If the parent or path is null,
or if the parent contains no root
Configuration.@NotNull public @NotNull Set<String> getKeys(boolean deep)
Set containing all keys in this
ConfigurationSection.
If deep is set to true, then the Set will contain
all keys within any child
ConfigurationSection(s) (and their
respective children, etc.) contained within this
ConfigurationSection. The keys will be in a valid path notation
for use.
If deep is set to false, then the Set will
contain only the keys of any direct children, and not any of those
children's children.
getKeys in interface ConfigurationSectiondeep - true if the Set is to contain the keys of the
children ConfigurationSection(s)
of this ConfigurationSection, false
otherwise.Set of keys contained within this
ConfigurationSection.@NotNull public @NotNull Map<String,Object> getValues(boolean deep)
Map containing all keys and their values for this
ConfigurationSection.
If deep is set to true, then the Map will contain
all keys and their respective values within any child
ConfigurationSection(s) (and their
respective children, etc.) contained in this
ConfigurationSection. The keys will be in a valid path notation
for use.
If deep is set to false, then the Map will
contain only the keys and respective values of any direct children, and
not any of those children's children.
getValues in interface ConfigurationSectiondeep - true if the Map is to contain the keys and
respective values of the children
ConfigurationSection(s) of this
ConfigurationSection, false otherwise.Map of keys and their respective values contained
within this ConfigurationSection.@NotNull public @NotNull String getCurrentPath()
ConfigurationSection from its root
Configuration
For any Configuration themselves, this will return an empty
String.
If this ConfigurationSection is no longer contained within its
root for any reason, such as being replaced with a different value, this
may return null.
To retrieve the single name of this section, that is, the final part of
the path returned by this method, you may use
ConfigurationSection.getName().
getCurrentPath in interface ConfigurationSectionConfigurationSection relative to its root.@NotNull public @NotNull String getName()
ConfigurationSection, in the
path.
This will always be the final part of
ConfigurationSection.getCurrentPath(), unless this
ConfigurationSection is orphaned.
getName in interface ConfigurationSectionConfigurationSection.@Nullable public @Nullable Configuration getRoot()
Configuration that contains this
ConfigurationSection
For any Configuration themselves, this will return its own
object.
If this ConfigurationSection is no longer contained within its
root for any reason, such as being replaced with a different value, this
may return null.
getRoot in interface ConfigurationSectionConfiguration containing this
ConfigurationSection.@Nullable public @Nullable ConfigurationSection getParent()
ConfigurationSection that directly contains
this ConfigurationSection.
For any Configuration themselves, this will return null.
If this ConfigurationSection is no longer contained within its
parent for any reason, such as being replaced with a different value,
this may return null.
getParent in interface ConfigurationSectionConfigurationSection containing this
ConfigurationSection.@Nullable public @Nullable ConfigurationSection getDefaultSection()
ConfigurationSection from the default
Configuration defined in ConfigurationSection.getRoot().
If the root contains no defaults, or the defaults do not contain a
value for this path, or the value at this path is not a
ConfigurationSection, then this will return null.
getDefaultSection in interface ConfigurationSectionConfigurationSection in the default
ConfigurationSection.public void addDefault(@NotNull
@NotNull String path,
@Nullable
@Nullable Object value)
If no source Configuration was provided as a default
collection, then a new MemoryConfiguration will be created to
hold the new default value.
If value is null, the value will be removed from the default
Configuration source.
If the value as returned by
ConfigurationSection.getDefaultSection() is null, then
this will create a new ConfigurationSection at the path,
replacing anything that may have existed there previously.
addDefault in interface ConfigurationSectionpath - The path of the value to set.value - The value to set the default to.@NotNull public @NotNull List<String> getComments(@NotNull @NotNull String path)
List by path.
If no comments exist, and empty List will be returned. A
null entry represents an empty line and an empty String
represents an empty comment line.
getComments in interface ConfigurationSectionpath - Path of the comments to get.List of the requested comments, where
every entry represents one line.@NotNull public @NotNull List<String> getInLineComments(@NotNull @NotNull String path)
List by path.
If no comments exist, an empty List will be returned. A
null entry represents an empty line and an empty String
represents an empty comment ine.
getInLineComments in interface ConfigurationSectionpath - Path of the comments to get.List of the requested comments, where
every entry represents one line.public void setComments(@NotNull
@NotNull String path,
@Nullable
@Nullable List<String> comments)
List at the specified path.
If value is null, the comments will be removed. A null
entry is an empty line and an empty String entry is an empty
comment line. If the path does not exist, no comments will be set. Any
existing comments will be replaced, regardless of what the new comments
are.
Some implementations may have limitations on what persists. See their individual javadocs for details.
setComments in interface ConfigurationSectionpath - Path of the comments to set.comments - New comments to set at the path, every entry represents
one line.public void setInLineComments(@NotNull
@NotNull String path,
@Nullable
@Nullable List<String> inLineComments)
List at the specified path.
If value is null, the comments will be removed. A null
entry is an empty line and an empty String entry is an empty
comment line. If the path does not exist, no comment will be set. Any
existing comments will be replaced, regardless of what the new comments
are.
Some implementations may have limitations on what persists. See their individual javadocs for details.
setInLineComments in interface ConfigurationSectionpath - Path of the comments to set.inLineComments - New comments to set at the path, every entry
represents one line.@NotNull public @NotNull ConfigurationSection createSection(@NotNull @NotNull String path)
ConfigurationSection at the specified path.
Any value that was previously set at this path will be overwritten. If
the previous value was itself a ConfigurationSection, it will
be orphaned.
createSection in interface ConfigurationSectionpath - The path to create the ConfigurationSection at.ConfigurationSection.@NotNull public @NotNull ConfigurationSection createSection(@NotNull @NotNull String path, @NotNull @NotNull Map<?,?> map)
ConfigurationSection at the specified path, with the
specified values.
Any value that was previously set at this path will be overwritten. If
the previous value was itself a ConfigurationSection, it will
be orphaned.
createSection in interface ConfigurationSectionpath - The path to create the ConfigurationSection at.map - The key-value pairs to place in the
ConfigurationSection.ConfigurationSection.public boolean isSet(@NotNull
@NotNull String path)
ConfigurationSection has a value set for the
given path.
If the value for the requested path does not exist but a default value
has been specified, this will still return false.
isSet in interface ConfigurationSectionpath - The path to check for existence.true if this ConfigurationSection contains the
requested path, regardless of having a default. false
otherwisepublic void set(@NotNull
@NotNull String path,
@Nullable
@Nullable Object value)
If the value is null, the entry will be removed. Any existing
entry will be replaced, regardless of what the new value is.
Some implementations may have limitations on what you may store. See
their individual javadocs for details. No implementations should allow
you to store a Configuration or a ConfigurationSection,
please use ConfigurationSection.createSection(String) for that.
set in interface ConfigurationSectionpath - The path to the given value.value - The (new) value stored at the given path.public boolean contains(@NotNull
@NotNull String path)
ConfigurationSection contains the given path.
If the value for the requested path does not exist but a default value
has been specified, this will return true.
contains in interface ConfigurationSectionpath - The path to check for existence.true if this ConfigurationSection contains the
requested path, either via default or being set. false
otherwise.public boolean contains(@NotNull
@NotNull String path,
boolean ignoreDefault)
ConfigurationSection contains the given path.
If true is specified for ignoreDefaults, then this will
return true only if a value has been set for the given path.
If false is specified for ignoreDefaults, then this will
return true if a value has been set for the given path, or if a
default value has been set for the given path.
contains in interface ConfigurationSectionpath - The path to check for existence.ignoreDefault - true if any default values should be ignored
when checking for a value at the path, false
otherwise.true if this ConfigurationSection contains a
value at the requested path, or if a default value has been set
and ignoreDefaults is false. false
otherwise.@Nullable public @Nullable Object get(@NotNull @NotNull String path)
Object 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.
get in interface ConfigurationSectionpath - The path of the Object to retrieve.Object.@Contract(value="_, !null -> !null") @Nullable public @Nullable Object get(@NotNull @NotNull String path, @Nullable @Nullable Object def)
Object at the given path, returning the given default
value if none has 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.
get in interface ConfigurationSectionpath - The path of the Object to retrieve.def - The Object to use as a default value.Object.public boolean isBoolean(@NotNull
@NotNull String path)
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 that value and return appropriately.
isBoolean in interface ConfigurationSectionpath - The path of the boolean to check.true if a boolean value exists, or if there is no
value, a default has been set, and it is a boolean.
false otherwise.public boolean getBoolean(@NotNull
@NotNull String path)
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.
getBoolean in interface ConfigurationSectionpath - The path of the boolean to retrieve.boolean.public boolean getBoolean(@NotNull
@NotNull String path,
boolean def)
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.
getBoolean in interface ConfigurationSectionpath - The path of the boolean to retrieve.def - The boolean to use as the default.boolean.public boolean isByte(@NotNull
@NotNull String path)
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.
isByte in interface ConfigurationSectionpath - The path of the byte to check.true if a byte value exists, or if there is no
value, a default has been set, and it is a byte.
false otherwise.public byte getByte(@NotNull
@NotNull String path)
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.
getByte in interface ConfigurationSectionpath - The path of the byte to retrieve.byte.public byte getByte(@NotNull
@NotNull String path,
byte def)
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.
getByte in interface ConfigurationSectionpath - The path of the byte to retrieve.def - The byte to use as the default.byte.public boolean isShort(@NotNull
@NotNull String path)
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.
isShort in interface ConfigurationSectionpath - The path of the short to check.true if a short value exists, or if there is no
value, a default has been set, and it is a short.
false otherwise.public short getShort(@NotNull
@NotNull String path)
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.
getShort in interface ConfigurationSectionpath - The path of the short to retrieve.short.public short getShort(@NotNull
@NotNull String path,
short def)
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.
getShort in interface ConfigurationSectionpath - The path of the short to retrieve.def - The short to use as the default.short.public boolean isInt(@NotNull
@NotNull String path)
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.
isInt in interface ConfigurationSectionpath - The path of the int to check.true if an int value exists, or if there is no
value, a default has been set, and it is an int.
false otherwise.public int getInt(@NotNull
@NotNull String path)
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.
getInt in interface ConfigurationSectionpath - The path of the int to retrieve.int.public int getInt(@NotNull
@NotNull String path,
int def)
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.
getInt in interface ConfigurationSectionpath - The path of the int to retrieve.def - The int to use as the default.int.public boolean isLong(@NotNull
@NotNull String path)
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.
isLong in interface ConfigurationSectionpath - The path of the long to check.true if a long value exists, or if there is no
value, a default has been set, and it is a long.
false otherwise.public long getLong(@NotNull
@NotNull String path)
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.
getLong in interface ConfigurationSectionpath - The path of the long to retrieve.long.public long getLong(@NotNull
@NotNull String path,
long def)
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.
getLong in interface ConfigurationSectionpath - The path of the long to retrieve.def - The long to use as the default.long.public boolean isFloat(@NotNull
@NotNull String path)
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.
isFloat in interface ConfigurationSectionpath - The path of the float to check.true if a float value exists, or if there is no
value, a default has been set, and it is a float.
false otherwise.public float getFloat(@NotNull
@NotNull String path)
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.
getFloat in interface ConfigurationSectionpath - The path of the float to retrieve.float.public float getFloat(@NotNull
@NotNull String path,
float def)
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.
getFloat in interface ConfigurationSectionpath - The path of the float to retrieve.def - The float to use as the default.float.public boolean isDouble(@NotNull
@NotNull String path)
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.
isDouble in interface ConfigurationSectionpath - The path of the double to check.true if a double value exists, or if there is no
value, a default has been set, and it is a double.
false otherwise.public double getDouble(@NotNull
@NotNull String path)
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.
getDouble in interface ConfigurationSectionpath - The path of the double to retrieve.double.public double getDouble(@NotNull
@NotNull String path,
double def)
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.
getDouble in interface ConfigurationSectionpath - The path of the double to retrieve.def - The double to use as the default.double.public boolean isChar(@NotNull
@NotNull String path)
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.
isChar in interface ConfigurationSectionpath - The path of the char to check.true if a char value exists, or if there is no
value, a default has been set, and it is a char.
false otherwise.public char getChar(@NotNull
@NotNull String path)
char value at the given path.
If the value exists at the given path but is not a char, this
will return