Interface MapNode
Node
implementation that represents a Map
(Object
- Node
).
The implementing class of this interface keeps the order of keys using LinkedHashMap
.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescription@NotNull @UnmodifiableView MapNode
asView()
Gets a view of thisMapNode
.void
clear()
Clears thisMapNode
.@NotNull MapNode
copy()
Copies thisMapNode
.static @NotNull MapNode
create()
Creates a newMapNode
.static @NotNull MapNode
@NotNull ListNode
createList
(@NotNull Object key) Creates a newListNode
and set it to the specified key.@NotNull @Unmodifiable MapNode
Creates a newMapNode
and set it to the specified key.static @NotNull MapNode
empty()
Gets aMapNode
that is always empty.default @NotNull Node<?>
Gets aNode
to which the specified key is mapped, orNullNode.NULL
if thisMapNode
contains no mapping for the key.default boolean
getBoolean
(@NotNull Object key) Gets the boolean value to which the specified key is mapped, orfalse
.default boolean
getBoolean
(@NotNull Object key, boolean def) Gets the boolean value to which the specified key is mapped, or the specified boolean value.default byte
Gets the byte value to which the specified key is mapped, or0
.default byte
Gets the byte value to which the specified key is mapped, or the specified byte value.default char
Gets the char value to which the specified key is mapped, orfalse
.default char
Gets the char value to which the specified key is mapped, or the specified char value.default double
Gets the double value to which the specified key is mapped, or0
.default double
Gets the double value to which the specified key is mapped, or the specified double value.default <E extends Enum<E>>
Edefault <E extends Enum<E>>
Edefault float
Gets the float value to which the specified key is mapped, or0
.default float
Gets the float value to which the specified key is mapped, or the specified float value.default int
getInteger
(@NotNull Object key) Gets the int value to which the specified key is mapped, or0
.default int
getInteger
(@NotNull Object key, int def) Gets the int value to which the specified key is mapped, or the specified int value.default @NotNull @UnmodifiableView ListNode
Gets theListNode
to which the specified key is mapped.default long
Gets the long value to which the specified key is mapped, or0
.default long
Gets the long value to which the specified key is mapped, or the specified long value.default @NotNull @Unmodifiable MapNode
Gets theMapNode
to which the specified key is mapped.default @NotNull ListNode
getOrCreateList
(@NotNull Object key) Gets theListNode
to which the specified key is mapped, or creates a newListNode
usingcreateList(Object)
.default @NotNull MapNode
getOrCreateMap
(@NotNull Object key) Gets theMapNode
to which the specified key is mapped, or creates a newMapNode
usingcreateMap(Object)
.@NotNull Node<?>
getOrDefault
(@NotNull Object key, @NotNull Node<?> defaultNode) default short
Gets the short value to which the specified key is mapped, or0
.default short
Gets the short value to which the specified key is mapped, or the specified short value.default @NotNull String
default @NotNull String
Gets theString
value to which the specified key is mapped, or the specified value.default @Nullable String
getStringOrNull
(@NotNull Object key) Gets theString
value to which the specified key is mapped, ornull
.@NotNull Node<?>
Sets aNode
to the specified key.@Nullable Node<?>
setIfAbsent
(@NotNull Object key, @NotNull Object value) value()
Gets an object which thisNode
holdsMethods inherited from interface com.github.siroshun09.configapi.core.node.CommentableNode
getComment, getCommentOrNull, hasComment, setComment
Methods inherited from interface com.github.siroshun09.configapi.core.node.Node
accept, asOptional, hasValue
-
Field Details
-
IMPLEMENTATION_CLASS
An implementationClass
of this interface.
-
-
Method Details
-
create
Creates a newMapNode
.- Returns:
- a new
MapNode
-
create
-
empty
Gets aMapNode
that is always empty.The returning
MapNode
cannot be modified using methods likeset(Object, Object)
.- Returns:
- a
MapNode
that is always empty
-
value
Description copied from interface:Node
Gets an object which thisNode
holds -
get
Gets aNode
to which the specified key is mapped, orNullNode.NULL
if thisMapNode
contains no mapping for the key.- Parameters:
key
- the key to get- Returns:
- a
Node
to which the specified key is mapped, orNullNode.NULL
if thisMapNode
contains no mapping for the key
-
getOrDefault
@NotNull @NotNull Node<?> getOrDefault(@NotNull @NotNull Object key, @NotNull @NotNull Node<?> defaultNode) -
set
Sets aNode
to the specified key.If
null
is specified as value, the key will be removed from the map.- Parameters:
key
- the key to setvalue
- the value to set, ornull
if removing the key- Returns:
- the
Node
to which the specified key is mapped previously, orNullNode.NULL
if the key is not mapped
-
setIfAbsent
@Nullable @Nullable Node<?> setIfAbsent(@NotNull @NotNull Object key, @NotNull @NotNull Object value) - Parameters:
key
- the key to setvalue
- the value to set- Returns:
- the
Node
to which the specified key is mapped previously, ornull
if the key is not mapped
-
clear
void clear()Clears thisMapNode
. -
copy
Copies thisMapNode
.The entries in this
MapNode
will also be copied usingNode.fromObject(Object)
.- Returns:
- a copied
MapNode
-
asView
Gets a view of thisMapNode
.The returning
MapNode
cannot be modified, but thisMapNode
can still be modified, so the entries may be changed by other codes using this instance.- Returns:
- a view of this
MapNode
-
getList
Gets theListNode
to which the specified key is mapped.The returning
ListNode
is a view, so it cannot be modified. To modifyListNode
, usegetOrCreateList(Object)
.- Parameters:
key
- the key to get- Returns:
- the view of
ListNode
to which the specified key is mapped, orListNode.empty()
if the key is not mapped
-
createList
Creates a newListNode
and set it to the specified key.The
Node
to which the specified key is mapped previously will be removed.- Parameters:
key
- the key to set- Returns:
- a new
ListNode
to which the specified key is mapped
-
getOrCreateList
Gets theListNode
to which the specified key is mapped, or creates a newListNode
usingcreateList(Object)
.- Parameters:
key
- the key to get- Returns:
- the
ListNode
to which the specified key is mapped, orcreateList(Object)
if the key is not mapped
-
getMap
Gets theMapNode
to which the specified key is mapped.The returning
MapNode
is a view, so it cannot be modified. To modifyMapNode
, usegetOrCreateMap(Object)
. -
createMap
Creates a newMapNode
and set it to the specified key.The
Node
to which the specified key is mapped previously will be removed.- Parameters:
key
- the key to set- Returns:
- a new
MapNode
to which the specified key is mapped
-
getOrCreateMap
Gets theMapNode
to which the specified key is mapped, or creates a newMapNode
usingcreateMap(Object)
.- Parameters:
key
- the key to get- Returns:
- the
MapNode
to which the specified key is mapped, orcreateMap(Object)
if the key is not mapped toMapNode
-
getString
- Parameters:
key
- the key to get- Returns:
- the
String
to which the specified key is mapped, or an emptyString
if the key is not mapped toStringValue
-
getString
@NotNull default @NotNull String getString(@NotNull @NotNull Object key, @NotNull @NotNull String def) Gets theString
value to which the specified key is mapped, or the specified value.- Parameters:
key
- the key to getdef
- the default value- Returns:
- the
String
to which the specified key is mapped, or the specified value if the key is not mapped toStringValue
-
getStringOrNull
Gets theString
value to which the specified key is mapped, ornull
.- Parameters:
key
- the key to get- Returns:
- the
String
to which the specified key is mapped, ornull
if the key is not mapped toStringValue
-
getEnum
Gets theEnum
value or parsesStringValue
toEnum
.This method is implemented with the following specification:
- The
Node
to which the specified key is mapped isEnumValue
and it is appropriate the specified type of the enum, returnsEnumValue.value()
-
The
Node
to which the specified key is mapped isStringValue
, try to parse the string toEnum
usingEnum.valueOf(Class, String)
- If the string value is invalid, returns the specified value
- Otherwise, returns the specified value
- The
-
getEnum
@Nullable default <E extends Enum<E>> E getEnum(@NotNull @NotNull Object key, @NotNull @NotNull Class<E> enumClass) Gets theEnum
value or parsesStringValue
toEnum
.This method is implemented with the following specification:
- The
Node
to which the specified key is mapped isEnumValue
and it is appropriate the specified type of the enum, returnsEnumValue.value()
-
The
Node
to which the specified key is mapped isStringValue
, try to parse the string toEnum
usingEnum.valueOf(Class, String)
- If the string value is invalid, returns
null
- If the string value is invalid, returns
- Otherwise, returns
null
- The
-
getBoolean
Gets the boolean value to which the specified key is mapped, orfalse
.- Parameters:
key
- the key to get- Returns:
- the boolean value to which the specified key is mapped, or
false
if the key is not mapped toBooleanValue
-
getBoolean
Gets the boolean value to which the specified key is mapped, or the specified boolean value.- Parameters:
key
- the key to getdef
- the default value- Returns:
- the boolean value to which the specified key is mapped, or the specified value if the key is not mapped to
BooleanValue
-
getInteger
Gets the int value to which the specified key is mapped, or0
.- Parameters:
key
- the key to get- Returns:
- the int value to which the specified key is mapped, or
0
if the key is not mapped toNumberValue
-
getInteger
Gets the int value to which the specified key is mapped, or the specified int value.- Parameters:
key
- the key to getdef
- the default value- Returns:
- the int value to which the specified key is mapped, or the specified value if the key is not mapped to
NumberValue
-
getLong
Gets the long value to which the specified key is mapped, or0
.- Parameters:
key
- the key to get- Returns:
- the long value to which the specified key is mapped, or
0
if the key is not mapped toNumberValue
-
getLong
Gets the long value to which the specified key is mapped, or the specified long value.- Parameters:
key
- the key to getdef
- the default value- Returns:
- the long value to which the specified key is mapped, or the specified value if the key is not mapped to
NumberValue
-
getFloat
Gets the float value to which the specified key is mapped, or0
.- Parameters:
key
- the key to get- Returns:
- the float value to which the specified key is mapped, or
0
if the key is not mapped toNumberValue
-
getFloat
Gets the float value to which the specified key is mapped, or the specified float value.- Parameters:
key
- the key to getdef
- the default value- Returns:
- the float value to which the specified key is mapped, or the specified value if the key is not mapped to
NumberValue
-
getDouble
Gets the double value to which the specified key is mapped, or0
.- Parameters:
key
- the key to get- Returns:
- the double value to which the specified key is mapped, or
0
if the key is not mapped toNumberValue
-
getDouble
Gets the double value to which the specified key is mapped, or the specified double value.- Parameters:
key
- the key to getdef
- the default value- Returns:
- the double value to which the specified key is mapped, or the specified value if the key is not mapped to
NumberValue
-
getByte
Gets the byte value to which the specified key is mapped, or0
.- Parameters:
key
- the key to get- Returns:
- the byte value to which the specified key is mapped, or
0
if the key is not mapped toNumberValue
-
getByte
Gets the byte value to which the specified key is mapped, or the specified byte value.- Parameters:
key
- the key to getdef
- the default value- Returns:
- the byte value to which the specified key is mapped, or the specified value if the key is not mapped to
NumberValue
-
getShort
Gets the short value to which the specified key is mapped, or0
.- Parameters:
key
- the key to get- Returns:
- the short value to which the specified key is mapped, or
0
if the key is not mapped toNumberValue
-
getShort
Gets the short value to which the specified key is mapped, or the specified short value.- Parameters:
key
- the key to getdef
- the default value- Returns:
- the short value to which the specified key is mapped, or the specified value if the key is not mapped to
NumberValue
-
getChar
Gets the char value to which the specified key is mapped, orfalse
.- Parameters:
key
- the key to get- Returns:
- the char value to which the specified key is mapped, or
Character.MIN_VALUE
if the key is not mapped toCharValue
-
getChar
Gets the char value to which the specified key is mapped, or the specified char value.- Parameters:
key
- the key to getdef
- the default value- Returns:
- the char value to which the specified key is mapped, or the specified value if the key is not mapped to
CharValue
-