Interface MapNode

All Superinterfaces:
CommentableNode<Map<Object,Node<?>>>, Node<Map<Object,Node<?>>>

public sealed interface MapNode extends CommentableNode<Map<Object,Node<?>>>
A Node implementation that represents a Map (Object - Node).

The implementing class of this interface keeps the order of keys using LinkedHashMap.

  • Field Details

    • IMPLEMENTATION_CLASS

      @Internal static final Class<? extends MapNode> IMPLEMENTATION_CLASS
      An implementation Class of this interface.
  • Method Details

    • create

      @NotNull static @NotNull MapNode create()
      Creates a new MapNode.
      Returns:
      a new MapNode
    • create

      @NotNull static @NotNull MapNode create(@NotNull @NotNull Map<?,?> map)
      Creates a new MapNode with entries in the given Map.
      Parameters:
      map - a Map to add entries to the new MapNode
      Returns:
      a new MapNode with entries in the given Map
    • empty

      @NotNull static @NotNull MapNode empty()
      Gets a MapNode that is always empty.

      The returning MapNode cannot be modified using methods like set(Object, Object).

      Returns:
      a MapNode that is always empty
    • value

      @UnknownNullability @UnmodifiableView Map<Object,Node<?>> value()
      Description copied from interface: Node
      Gets an object which this Node holds
      Specified by:
      value in interface Node<Map<Object,Node<?>>>
      Returns:
      an object which this Node holds
    • get

      @NotNull default @NotNull Node<?> get(@NotNull @NotNull Object key)
      Gets a Node to which the specified key is mapped, or NullNode.NULL if this MapNode contains no mapping for the key.
      Parameters:
      key - the key to get
      Returns:
      a Node to which the specified key is mapped, or NullNode.NULL if this MapNode contains no mapping for the key
    • getOrDefault

      @NotNull @NotNull Node<?> getOrDefault(@NotNull @NotNull Object key, @NotNull @NotNull Node<?> defaultNode)
      Gets a Node to which the specified key is mapped, or the specified Node if this MapNode contains no mapping for the key.
      Parameters:
      key - the key to get
      defaultNode - the Node to return when this MapNode contains no mapping for the key
      Returns:
      a Node to which the specified key is mapped, or the specified Node if this MapNode contains no mapping for the key
    • set

      @NotNull @NotNull Node<?> set(@NotNull @NotNull Object key, @Nullable @Nullable Object value)
      Sets a Node to the specified key.

      If null is specified as value, the key will be removed from the map.

      Parameters:
      key - the key to set
      value - the value to set, or null if removing the key
      Returns:
      the Node to which the specified key is mapped previously, or NullNode.NULL if the key is not mapped
    • setIfAbsent

      @Nullable @Nullable Node<?> setIfAbsent(@NotNull @NotNull Object key, @NotNull @NotNull Object value)
      Sets a Node if this MapNode does not contain the specified key.
      Parameters:
      key - the key to set
      value - the value to set
      Returns:
      the Node to which the specified key is mapped previously, or null if the key is not mapped
    • clear

      void clear()
      Clears this MapNode.
    • copy

      @NotNull @NotNull MapNode copy()
      Copies this MapNode.

      The entries in this MapNode will also be copied using Node.fromObject(Object).

      Returns:
      a copied MapNode
    • asView

      @NotNull @NotNull @UnmodifiableView MapNode asView()
      Gets a view of this MapNode.

      The returning MapNode cannot be modified, but this MapNode can still be modified, so the entries may be changed by other codes using this instance.

      Returns:
      a view of this MapNode
    • getList

      @NotNull default @NotNull @UnmodifiableView ListNode getList(@NotNull @NotNull Object key)
      Gets the ListNode to which the specified key is mapped.

      The returning ListNode is a view, so it cannot be modified. To modify ListNode, use getOrCreateList(Object).

      Parameters:
      key - the key to get
      Returns:
      the view of ListNode to which the specified key is mapped, or ListNode.empty() if the key is not mapped
    • createList

      @NotNull @NotNull ListNode createList(@NotNull @NotNull Object key)
      Creates a new ListNode 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

      @NotNull default @NotNull ListNode getOrCreateList(@NotNull @NotNull Object key)
      Gets the ListNode to which the specified key is mapped, or creates a new ListNode using createList(Object).
      Parameters:
      key - the key to get
      Returns:
      the ListNode to which the specified key is mapped, or createList(Object) if the key is not mapped
    • getMap

      @NotNull default @NotNull @Unmodifiable MapNode getMap(@NotNull @NotNull Object key)
      Gets the MapNode to which the specified key is mapped.

      The returning MapNode is a view, so it cannot be modified. To modify MapNode, use getOrCreateMap(Object).

      Parameters:
      key - the key to get
      Returns:
      the view of MapNode to which the specified key is mapped, or empty() if the key is not mapped to MapNode
    • createMap

      @NotNull @NotNull @Unmodifiable MapNode createMap(@NotNull @NotNull Object key)
      Creates a new MapNode 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

      @NotNull default @NotNull MapNode getOrCreateMap(@NotNull @NotNull Object key)
      Gets the MapNode to which the specified key is mapped, or creates a new MapNode using createMap(Object).
      Parameters:
      key - the key to get
      Returns:
      the MapNode to which the specified key is mapped, or createMap(Object) if the key is not mapped to MapNode
    • getString

      @NotNull default @NotNull String getString(@NotNull @NotNull Object key)
      Gets the String value to which the specified key is mapped, or an empty String.
      Parameters:
      key - the key to get
      Returns:
      the String to which the specified key is mapped, or an empty String if the key is not mapped to StringValue
    • getString

      @NotNull default @NotNull String getString(@NotNull @NotNull Object key, @NotNull @NotNull String def)
      Gets the String value to which the specified key is mapped, or the specified value.
      Parameters:
      key - the key to get
      def - the default value
      Returns:
      the String to which the specified key is mapped, or the specified value if the key is not mapped to StringValue
    • getStringOrNull

      @Nullable default @Nullable String getStringOrNull(@NotNull @NotNull Object key)
      Gets the String value to which the specified key is mapped, or null.
      Parameters:
      key - the key to get
      Returns:
      the String to which the specified key is mapped, or null if the key is not mapped to StringValue
    • getEnum

      @NotNull default <E extends Enum<E>> E getEnum(@NotNull @NotNull Object key, @NotNull E def)
      Gets the Enum value or parses StringValue to Enum.

      This method is implemented with the following specification:

      Type Parameters:
      E - the type of the Enum
      Parameters:
      key - the key to get
      def - the default value
      Returns:
      the Enum value
    • getEnum

      @Nullable default <E extends Enum<E>> E getEnum(@NotNull @NotNull Object key, @NotNull @NotNull Class<E> enumClass)
      Gets the Enum value or parses StringValue to Enum.

      This method is implemented with the following specification:

      Type Parameters:
      E - the type of the Enum
      Parameters:
      key - the key to get
      enumClass - the Class of the Enum
      Returns:
      the Enum value or null
    • getBoolean

      default boolean getBoolean(@NotNull @NotNull Object key)
      Gets the boolean value to which the specified key is mapped, or false.
      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 to BooleanValue
    • getBoolean

      default boolean getBoolean(@NotNull @NotNull Object key, boolean def)
      Gets the boolean value to which the specified key is mapped, or the specified boolean value.
      Parameters:
      key - the key to get
      def - 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

      default int getInteger(@NotNull @NotNull Object key)
      Gets the int value to which the specified key is mapped, or 0.
      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 to NumberValue
    • getInteger

      default int getInteger(@NotNull @NotNull Object key, int def)
      Gets the int value to which the specified key is mapped, or the specified int value.
      Parameters:
      key - the key to get
      def - 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

      default long getLong(@NotNull @NotNull Object key)
      Gets the long value to which the specified key is mapped, or 0.
      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 to NumberValue
    • getLong

      default long getLong(@NotNull @NotNull Object key, long def)
      Gets the long value to which the specified key is mapped, or the specified long value.
      Parameters:
      key - the key to get
      def - 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

      default float getFloat(@NotNull @NotNull Object key)
      Gets the float value to which the specified key is mapped, or 0.
      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 to NumberValue
    • getFloat

      default float getFloat(@NotNull @NotNull Object key, float def)
      Gets the float value to which the specified key is mapped, or the specified float value.
      Parameters:
      key - the key to get
      def - 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

      default double getDouble(@NotNull @NotNull Object key)
      Gets the double value to which the specified key is mapped, or 0.
      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 to NumberValue
    • getDouble

      default double getDouble(@NotNull @NotNull Object key, double def)
      Gets the double value to which the specified key is mapped, or the specified double value.
      Parameters:
      key - the key to get
      def - 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

      default byte getByte(@NotNull @NotNull Object key)
      Gets the byte value to which the specified key is mapped, or 0.
      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 to NumberValue
    • getByte

      default byte getByte(@NotNull @NotNull Object key, byte def)
      Gets the byte value to which the specified key is mapped, or the specified byte value.
      Parameters:
      key - the key to get
      def - 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

      default short getShort(@NotNull @NotNull Object key)
      Gets the short value to which the specified key is mapped, or 0.
      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 to NumberValue
    • getShort

      default short getShort(@NotNull @NotNull Object key, short def)
      Gets the short value to which the specified key is mapped, or the specified short value.
      Parameters:
      key - the key to get
      def - 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

      default char getChar(@NotNull @NotNull Object key)
      Gets the char value to which the specified key is mapped, or false.
      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 to CharValue
    • getChar

      default char getChar(@NotNull @NotNull Object key, char def)
      Gets the char value to which the specified key is mapped, or the specified char value.
      Parameters:
      key - the key to get
      def - 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