Interface ConfigurationNode

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int NUMBER_DEF
      Default value for unknown number results.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      ConfigurationNode appendListNode()
      Gets a new child node created as the next entry in the list.
      java.util.List<? extends ConfigurationNode> childrenList()
      Gets the "list children" attached to this node, if it has any.
      java.util.Map<java.lang.Object,​? extends ConfigurationNode> childrenMap()
      Gets the "map children" attached to this node, if it has any.
      ConfigurationNode copy()
      Creates a deep copy of this node.
      boolean empty()
      Return true when this node has a null or empty value.
      ConfigurationNode from​(ConfigurationNode other)
      Apply all data from other to this node, overwriting any existing data.
      default <V> @Nullable V get​(io.leangen.geantyref.TypeToken<V> type)
      Get the current value associated with this node.
      default <V> V get​(io.leangen.geantyref.TypeToken<V> type, java.util.function.Supplier<V> defSupplier)
      Get the current value associated with this node.
      default <V> V get​(io.leangen.geantyref.TypeToken<V> type, V def)
      Get the current value associated with this node.
      default <V> @Nullable V get​(java.lang.Class<V> type)
      Get the current value associated with this node.
      default <V> V get​(java.lang.Class<V> type, java.util.function.Supplier<V> defSupplier)
      Get the current value associated with this node.
      default <V> V get​(java.lang.Class<V> type, V def)
      Get the current value associated with this node.
      @Nullable java.lang.Object get​(java.lang.reflect.AnnotatedType type)
      Get the current value associated with this node.
      java.lang.Object get​(java.lang.reflect.AnnotatedType type, java.lang.Object def)
      Get the current value associated with this node.
      java.lang.Object get​(java.lang.reflect.AnnotatedType type, java.util.function.Supplier<?> defSupplier)
      Get the current value associated with this node.
      @Nullable java.lang.Object get​(java.lang.reflect.Type type)
      Get the current value associated with this node.
      java.lang.Object get​(java.lang.reflect.Type type, java.lang.Object def)
      Get the current value associated with this node.
      java.lang.Object get​(java.lang.reflect.Type type, java.util.function.Supplier<?> defSupplier)
      Get the current value associated with this node.
      default boolean getBoolean()
      Gets the value typed using the appropriate type conversion from Scalars.
      default boolean getBoolean​(boolean def)
      Gets the value typed using the appropriate type conversion from Scalars.
      default double getDouble()
      Gets the value typed using the appropriate type conversion from Scalars.
      default double getDouble​(double def)
      Gets the value typed using the appropriate type conversion from Scalars.
      default float getFloat()
      Gets the value typed using the appropriate type conversion from Scalars.
      default float getFloat​(float def)
      Gets the value typed using the appropriate type conversion from Scalars.
      default int getInt()
      Gets the value typed using the appropriate type conversion from Scalars.
      default int getInt​(int def)
      Gets the value typed using the appropriate type conversion from Scalars.
      default <V> @Nullable java.util.List<V> getList​(io.leangen.geantyref.TypeToken<V> type)
      If this node has list values, this function unwraps them and converts them to an appropriate type based on the provided function.
      default <V> java.util.List<V> getList​(io.leangen.geantyref.TypeToken<V> elementType, java.util.function.Supplier<java.util.List<V>> defSupplier)
      If this node has list values, this function unwraps them and converts them to an appropriate type based on the provided function.
      default <V> java.util.List<V> getList​(io.leangen.geantyref.TypeToken<V> elementType, java.util.List<V> def)
      If this node has list values, this function unwraps them and converts them to an appropriate type based on the provided function.
      default <V> @Nullable java.util.List<V> getList​(java.lang.Class<V> type)
      If this node has list values, this function unwraps them and converts them to an appropriate type based on the provided function.
      default <V> java.util.List<V> getList​(java.lang.Class<V> elementType, java.util.function.Supplier<java.util.List<V>> defSupplier)
      If this node has list values, this function unwraps them and converts them to an appropriate type based on the provided function.
      default <V> java.util.List<V> getList​(java.lang.Class<V> elementType, java.util.List<V> def)
      If this node has list values, this function unwraps them and converts them to an appropriate type based on the provided function.
      default long getLong()
      Gets the value typed using the appropriate type conversion from Scalars.
      default long getLong​(long def)
      Gets the value typed using the appropriate type conversion from Scalars.
      default @Nullable java.lang.String getString()
      Gets the value typed using the appropriate type conversion from Scalars.
      default java.lang.String getString​(java.lang.String def)
      Gets the value typed using the appropriate type conversion from Scalars.
      boolean hasChild​(java.lang.Iterable<?> path)
      Checks whether or not a non-virtual node is present at the relative path path.
      boolean hasChild​(java.lang.Object... path)
      Checks whether or not a non-virtual node is present at the relative path path.
      <V> @Nullable V hint​(RepresentationHint<V> hint)
      Query a representation hint from this node.
      <V> ConfigurationNode hint​(RepresentationHint<V> hint, @Nullable V value)
      Set a representation hint on this node.
      boolean isList()
      Gets if this node has "list children".
      boolean isMap()
      Gets if this node has "map children".
      boolean isNull()
      Get if this node has a 'null' value.
      @Nullable java.lang.Object key()
      Gets the "key" of this node.
      ConfigurationNode mergeFrom​(ConfigurationNode other)
      Set all the values from the given node that are not present in this node to their values in the provided node.
      ConfigurationNode node​(java.lang.Iterable<?> path)
      Gets the node at the given (relative) path, possibly traversing multiple levels of nodes.
      ConfigurationNode node​(java.lang.Object... path)
      Gets the node at the given (relative) path, possibly traversing multiple levels of nodes.
      ConfigurationOptions options()
      Gets the options that currently apply to this node.
      <V> @Nullable V ownHint​(RepresentationHint<V> hint)
      Query a representation hint from this node.
      java.util.Map<RepresentationHint<?>,​?> ownHints()
      Get an unmodifiable copy of representation hints stored on this node.
      @Nullable ConfigurationNode parent()
      Gets the parent of this node.
      NodePath path()
      Gets the full path of keys from the root node to this node.
      @Nullable java.lang.Object raw()
      Get the raw value of this node.
      ConfigurationNode raw​(@Nullable java.lang.Object value)
      Set the raw value of this node.
      @Nullable java.lang.Object rawScalar()
      Get the raw value of this node if the node is a scalar.
      boolean removeChild​(java.lang.Object key)
      Removes a direct child of this node.
      default <V> V require​(io.leangen.geantyref.TypeToken<V> type)
      Get the current value associated with this node, asserting that it is non-null.
      default <V> V require​(java.lang.Class<V> type)
      Get the current value associated with this node, asserting that it is non-null.
      default java.lang.Object require​(java.lang.reflect.Type type)
      Get the current value associated with this node, asserting that it is non-null.
      ConfigurationNode set​(@Nullable java.lang.Object value)
      Set this node's value to the given value.
      <V> ConfigurationNode set​(io.leangen.geantyref.TypeToken<V> type, @Nullable V value)
      Set this node's value to the given value.
      <V> ConfigurationNode set​(java.lang.Class<V> type, @Nullable V value)
      Set this node's value to the given value.
      ConfigurationNode set​(java.lang.reflect.AnnotatedType type, @Nullable java.lang.Object value)
      Set this node's value to the given value.
      ConfigurationNode set​(java.lang.reflect.Type type, @Nullable java.lang.Object value)
      Set this node's value to the given value.
      default <V> ConfigurationNode setList​(io.leangen.geantyref.TypeToken<V> elementType, @Nullable java.util.List<V> items)
      Set the node's value to the provided list.
      default <V> ConfigurationNode setList​(java.lang.Class<V> elementType, @Nullable java.util.List<V> items)
      Set the node's value to the provided list.
      default <V> java.util.stream.Collector<V,​? extends ConfigurationNode,​? extends ConfigurationNode> toListCollector​(io.leangen.geantyref.TypeToken<V> valueType)
      Create a collector that appends values to this node as list children.
      default <V> java.util.stream.Collector<V,​? extends ConfigurationNode,​? extends ConfigurationNode> toListCollector​(java.lang.Class<V> valueType)
      Create a collector that appends values to this node as list children.
      default <V> java.util.stream.Collector<java.util.Map.Entry<?,​V>,​? extends ConfigurationNode,​? extends ConfigurationNode> toMapCollector​(io.leangen.geantyref.TypeToken<V> valueType)
      Create a collector that appends values to this node as map children.
      default <V> java.util.stream.Collector<java.util.Map.Entry<?,​V>,​? extends ConfigurationNode,​? extends ConfigurationNode> toMapCollector​(java.lang.Class<V> valueType)
      Create a collector that appends values to this node as map children.
      boolean virtual()
      Gets if this node is virtual.
      default <S,​T>
      T
      visit​(ConfigurationVisitor.Safe<S,​T> visitor)
      Visit this node hierarchy as described in ConfigurationVisitor.
      <S,​T>
      T
      visit​(ConfigurationVisitor.Safe<S,​T> visitor, S state)
      Visit this node hierarchy as described in ConfigurationVisitor.
      default <S,​T,​E extends java.lang.Exception>
      T
      visit​(ConfigurationVisitor<S,​T,​E> visitor)
      Visit this node hierarchy as described in ConfigurationVisitor.
      <S,​T,​E extends java.lang.Exception>
      T
      visit​(ConfigurationVisitor<S,​T,​E> visitor, S state)
      Visit this node hierarchy as described in ConfigurationVisitor.
    • Method Detail

      • key

        @Nullable java.lang.Object key()
        Gets the "key" of this node.

        The key determines this ConfigurationNodes position within the overall configuration structure.

        If this node is currently virtual, this method's result may be inaccurate.

        Note that this method only returns the nearest "link" in the hierarchy, and does not return a representation of the full path. See path() for that.

        The ConfigurationNodes returned as values from childrenMap() will have keys derived from their pairing in the map node.

        The ConfigurationNodes returned from childrenList() will have keys derived from their position (index) in the list node.

        Returns:
        the key of this node
        Since:
        4.0.0
      • path

        NodePath path()
        Gets the full path of keys from the root node to this node.

        Node implementations may not keep a full path for each node, so this method may be somewhat complex to calculate. Most uses should not need to calculate the full path unless providing debug information

        Returns:
        an array compiled from the keys for each node up the hierarchy
        Since:
        4.0.0
      • parent

        @Nullable ConfigurationNode parent()
        Gets the parent of this node.

        If this node is currently virtual, this method's result may be inaccurate.

        Returns:
        the nodes parent
        Since:
        4.0.0
      • node

        ConfigurationNode node​(java.lang.Object... path)
        Gets the node at the given (relative) path, possibly traversing multiple levels of nodes.

        This is the main method used to navigate through the configuration.

        The path parameter effectively consumes an array of keys, which locate the unique position of a given node within the structure. Each element will navigate one level down in the configuration hierarchy

        A node is always returned by this method. If the given node does not exist in the structure, a virtual node will be returned which represents the position.

        Parameters:
        path - the path to fetch the node at
        Returns:
        the node at the given path, possibly virtual
        Since:
        4.0.0
      • node

        ConfigurationNode node​(java.lang.Iterable<?> path)
        Gets the node at the given (relative) path, possibly traversing multiple levels of nodes.

        This is the main method used to navigate through the configuration.

        The path parameter effectively consumes an array of keys, which locate the unique position of a given node within the structure.

        A node is always returned by this method. If the given node does not exist in the structure, a virtual node will be returned which represents the position.

        Parameters:
        path - the path to fetch the node at
        Returns:
        the node at the given path, possibly virtual
        Since:
        4.0.0
      • hasChild

        boolean hasChild​(java.lang.Object... path)
        Checks whether or not a non-virtual node is present at the relative path path.

        This allows checking for more remote nodes in the configuration hierarchy without having to instantiate new unattached node objects.

        Parameters:
        path - path to search at
        Returns:
        if a non-virtual child is present
        Since:
        4.0.0
      • hasChild

        boolean hasChild​(java.lang.Iterable<?> path)
        Checks whether or not a non-virtual node is present at the relative path path.

        This allows checking for more remote nodes in the configuration hierarchy without having to instantiate new unattached node objects.

        Parameters:
        path - path to search at
        Returns:
        if a non-virtual child is present
        Since:
        4.0.0
      • virtual

        boolean virtual()
        Gets if this node is virtual.

        Virtual nodes are nodes which are not attached to a wider configuration structure.

        A node is primarily "virtual" when it has no set value.

        Returns:
        true if this node is virtual
        Since:
        4.0.0
      • isNull

        boolean isNull()
        Get if this node has a 'null' value.

        This generally overlaps with the value of virtual(), but may be distinct in situations where the node has additional metadata (comment, attributes, etc).

        Returns:
        whether this node
        Since:
        4.1.0
      • isList

        boolean isList()
        Gets if this node has "list children".
        Returns:
        if this node has children in the form of a list
        Since:
        4.0.0
      • isMap

        boolean isMap()
        Gets if this node has "map children".
        Returns:
        if this node has children in the form of a map
        Since:
        4.0.0
      • empty

        boolean empty()
        Return true when this node has a null or empty value.

        Values that may result in this method returning true include:

        • null
        • the empty string
        • an empty map
        • an empty list
        • Any other type of empty collection

        This is a separate value from virtual(). Emptiness refers to the value of this node itself, while virtuality refers to whether or not this node is attached to a configuration structure.

        Returns:
        whether this node is empty
        Since:
        4.0.0
      • childrenList

        java.util.List<? extends ConfigurationNodechildrenList()
        Gets the "list children" attached to this node, if it has any.

        If this node does not have list children, an empty list is returned.

        Returns:
        the list children currently attached to this node
        Since:
        4.0.0
      • childrenMap

        java.util.Map<java.lang.Object,​? extends ConfigurationNodechildrenMap()
        Gets the "map children" attached to this node, if it has any.

        If this node does not have map children, an empty map returned.

        Returns:
        the map children currently attached to this node
        Since:
        4.0.0
      • toMapCollector

        default <V> java.util.stream.Collector<java.util.Map.Entry<?,​V>,​? extends ConfigurationNode,​? extends ConfigurationNodetoMapCollector​(io.leangen.geantyref.TypeToken<V> valueType)
        Create a collector that appends values to this node as map children.

        This collector does not accept values in parallel.

        Type Parameters:
        V - value type
        Parameters:
        valueType - marker for value type
        Returns:
        a new collector
        Since:
        4.0.0
      • toMapCollector

        default <V> java.util.stream.Collector<java.util.Map.Entry<?,​V>,​? extends ConfigurationNode,​? extends ConfigurationNodetoMapCollector​(java.lang.Class<V> valueType)
        Create a collector that appends values to this node as map children.

        This collector does not accept values in parallel.

        Type Parameters:
        V - value type
        Parameters:
        valueType - marker for value type
        Returns:
        a new collector
        Since:
        4.0.0
      • toListCollector

        default <V> java.util.stream.Collector<V,​? extends ConfigurationNode,​? extends ConfigurationNodetoListCollector​(io.leangen.geantyref.TypeToken<V> valueType)
        Create a collector that appends values to this node as list children.

        This collector does not accept values in parallel.

        Type Parameters:
        V - value type
        Parameters:
        valueType - marker for value type
        Returns:
        a new collector
        Since:
        4.0.0
      • toListCollector

        default <V> java.util.stream.Collector<V,​? extends ConfigurationNode,​? extends ConfigurationNodetoListCollector​(java.lang.Class<V> valueType)
        Create a collector that appends values to this node as list children.

        This collector does not accept values in parallel.

        Type Parameters:
        V - value type
        Parameters:
        valueType - marker for value type
        Returns:
        a new collector
        Since:
        4.0.0
      • require

        default <V> V require​(io.leangen.geantyref.TypeToken<V> type)
                       throws SerializationException
        Get the current value associated with this node, asserting that it is non-null.

        This method can be used when it is known that a certain key exists, or when implicit initialization is enabled for the expected type

        This method will perform deserialization using the appropriate TypeSerializer for the given type, or attempting to cast if no type serializer is found.

        Type Parameters:
        V - the type to get
        Parameters:
        type - the type to deserialize to
        Returns:
        the value if present and of the proper type
        Throws:
        java.util.NoSuchElementException - if the returned value is null
        SerializationException - if the value fails to be converted to the requested type
        Since:
        4.1.0
      • require

        default <V> V require​(java.lang.Class<V> type)
                       throws SerializationException
        Get the current value associated with this node, asserting that it is non-null.

        This method can be used when it is known that a certain key exists, or when implicit initialization is enabled for the expected type

        This method will also perform deserialization using the appropriate TypeSerializer for the given type, or casting if no type serializer is found.

        Type Parameters:
        V - the type to get
        Parameters:
        type - the type to deserialize to
        Returns:
        the value if present and of the proper type
        Throws:
        java.util.NoSuchElementException - if the returned value is null
        SerializationException - if the value fails to be converted to the requested type
        Since:
        4.1.0
      • require

        default java.lang.Object require​(java.lang.reflect.Type type)
                                  throws SerializationException
        Get the current value associated with this node, asserting that it is non-null.

        This method can be used when it is known that a certain key exists, or when implicit initialization is enabled for the expected type

        This method will attempt to deserialize the node's value to the provided Type using a configured TypeSerializer for the given type, or casting if no type serializer is found.

        Parameters:
        type - the type to deserialize to
        Returns:
        the value if present and of the proper type
        Throws:
        java.util.NoSuchElementException - if the returned value is null
        SerializationException - if the value fails to be converted to the requested type
        Since:
        4.1.0
      • get

        default <V> @Nullable V get​(io.leangen.geantyref.TypeToken<V> type)
                             throws SerializationException
        Get the current value associated with this node.

        This method will perform deserialization using the appropriate TypeSerializer for the given type, or attempting to cast if no type serializer is found.

        Type Parameters:
        V - the type to get
        Parameters:
        type - the type to deserialize to
        Returns:
        the value if present and of the proper type, else null
        Throws:
        SerializationException - if the value fails to be converted to the requested type
        Since:
        4.0.0
      • get

        default <V> V get​(io.leangen.geantyref.TypeToken<V> type,
                          V def)
                   throws SerializationException
        Get the current value associated with this node.

        This method will also perform deserialization using the appropriate TypeSerializer for the given type, or casting if no type serializer is found.

        Type Parameters:
        V - the type to get
        Parameters:
        type - the type to deserialize as.
        def - value to return if virtual() or value is not of appropriate type
        Returns:
        the value if of the proper type, else def
        Throws:
        SerializationException - if the value fails to be converted to the requested type
        Since:
        4.0.0
      • get

        default <V> V get​(io.leangen.geantyref.TypeToken<V> type,
                          java.util.function.Supplier<V> defSupplier)
                   throws SerializationException
        Get the current value associated with this node.

        This method will also perform deserialization using the appropriate TypeSerializer for the given type, or casting if no type serializer is found.

        Type Parameters:
        V - the type to get
        Parameters:
        type - the type to deserialize to
        defSupplier - the function that will be called to calculate a default value only if there is no existing value of the correct type
        Returns:
        the value if of the proper type, else def
        Throws:
        SerializationException - if the value fails to be converted to the requested type
        Since:
        4.0.0
      • get

        default <V> @Nullable V get​(java.lang.Class<V> type)
                             throws SerializationException
        Get the current value associated with this node.

        This method will also perform deserialization using the appropriate TypeSerializer for the given type, or casting if no type serializer is found.

        Type Parameters:
        V - the type to get
        Parameters:
        type - the type to deserialize to
        Returns:
        the value if present and of the proper type, else null
        Throws:
        SerializationException - if the value fails to be converted to the requested type
        Since:
        4.0.0
      • get

        default <V> V get​(java.lang.Class<V> type,
                          V def)
                   throws SerializationException
        Get the current value associated with this node.

        This method will also perform deserialization using the appropriate TypeSerializer for the given type, or casting if no type serializer is found.

        Type Parameters:
        V - the type to get
        Parameters:
        type - the type to deserialize as.
        def - value to return if virtual() or value is not of appropriate type
        Returns:
        the value if of the proper type, else def
        Throws:
        SerializationException - if the value fails to be converted to the requested type
        Since:
        4.0.0
      • get

        default <V> V get​(java.lang.Class<V> type,
                          java.util.function.Supplier<V> defSupplier)
                   throws SerializationException
        Get the current value associated with this node.

        This method will also perform deserialization using the appropriate TypeSerializer for the given type, or casting if no type serializer is found.

        Type Parameters:
        V - the type to get
        Parameters:
        type - the type to deserialize to
        defSupplier - the function that will be called to calculate a default value only if there is no existing value of the correct type
        Returns:
        the value if of the proper type, else def
        Throws:
        SerializationException - if the value fails to be converted to the requested type
        Since:
        4.0.0
      • get

        @Nullable java.lang.Object get​(java.lang.reflect.AnnotatedType type)
                                throws SerializationException
        Get the current value associated with this node.

        This method will attempt to deserialize the node's value to the provided AnnotatedType using a configured TypeSerializer for the given type, or casting if no type serializer is found.

        Parameters:
        type - the type to deserialize to
        Returns:
        the value if present and of the proper type, else null
        Throws:
        SerializationException - if the value fails to be converted to the requested type
        Since:
        4.2.0
      • get

        java.lang.Object get​(java.lang.reflect.AnnotatedType type,
                             java.lang.Object def)
                      throws SerializationException
        Get the current value associated with this node.

        This method will attempt to deserialize the node's value to the provided AnnotatedType using a configured TypeSerializer for the given type, or casting if no type serializer is found.

        Parameters:
        type - the type to deserialize as
        def - value to return if virtual() or value is not of appropriate type
        Returns:
        the value if of the proper type, else def
        Throws:
        SerializationException - if the value fails to be converted to the requested type
        Since:
        4.2.0
      • get

        java.lang.Object get​(java.lang.reflect.AnnotatedType type,
                             java.util.function.Supplier<?> defSupplier)
                      throws SerializationException
        Get the current value associated with this node.

        This method will attempt to deserialize the node's value to the provided AnnotatedType using a configured TypeSerializer for the given type, or casting if no type serializer is found.

        Parameters:
        type - the type to deserialize to
        defSupplier - the function that will be called to calculate a default value only if there is no existing value of the correct type
        Returns:
        the value if of the proper type, else def
        Throws:
        SerializationException - if the value fails to be converted to the requested type
        Since:
        4.2.0
      • get

        @Nullable java.lang.Object get​(java.lang.reflect.Type type)
                                throws SerializationException
        Get the current value associated with this node.

        This method will attempt to deserialize the node's value to the provided Type using a configured TypeSerializer for the given type, or casting if no type serializer is found.

        Parameters:
        type - the type to deserialize to
        Returns:
        the value if present and of the proper type, else null
        Throws:
        SerializationException - if the value fails to be converted to the requested type
        Since:
        4.0.0
      • get

        java.lang.Object get​(java.lang.reflect.Type type,
                             java.lang.Object def)
                      throws SerializationException
        Get the current value associated with this node.

        This method will attempt to deserialize the node's value to the provided Type using a configured TypeSerializer for the given type, or casting if no type serializer is found.

        Parameters:
        type - the type to deserialize as
        def - value to return if virtual() or value is not of appropriate type
        Returns:
        the value if of the proper type, else def
        Throws:
        SerializationException - if the value fails to be converted to the requested type
        Since:
        4.0.0
      • get

        java.lang.Object get​(java.lang.reflect.Type type,
                             java.util.function.Supplier<?> defSupplier)
                      throws SerializationException
        Get the current value associated with this node.

        This method will attempt to deserialize the node's value to the provided Type using a configured TypeSerializer for the given type, or casting if no type serializer is found.

        Parameters:
        type - the type to deserialize to
        defSupplier - the function that will be called to calculate a default value only if there is no existing value of the correct type
        Returns:
        the value if of the proper type, else def
        Throws:
        SerializationException - if the value fails to be converted to the requested type
        Since:
        4.0.0
      • getList

        default <V> @Nullable java.util.List<V> getList​(io.leangen.geantyref.TypeToken<V> type)
                                                 throws SerializationException
        If this node has list values, this function unwraps them and converts them to an appropriate type based on the provided function.

        If this node has a scalar value, this function treats it as a list with one value.

        Type Parameters:
        V - the expected type
        Parameters:
        type - the expected type
        Returns:
        an immutable copy of the values contained
        Throws:
        SerializationException - if any value fails to be converted to the requested type
        Since:
        4.0.0
      • getList

        default <V> java.util.List<V> getList​(io.leangen.geantyref.TypeToken<V> elementType,
                                              java.util.List<V> def)
                                       throws SerializationException
        If this node has list values, this function unwraps them and converts them to an appropriate type based on the provided function.

        If this node has a scalar value, this function treats it as a list with one value.

        Type Parameters:
        V - expected type
        Parameters:
        elementType - expected type
        def - default value if no appropriate value is set
        Returns:
        an immutable copy of the values contained that could be successfully converted, or def if no values could be converted.
        Throws:
        SerializationException - if any value fails to be converted to the requested type
        Since:
        4.0.0
      • getList

        default <V> java.util.List<V> getList​(io.leangen.geantyref.TypeToken<V> elementType,
                                              java.util.function.Supplier<java.util.List<V>> defSupplier)
                                       throws SerializationException
        If this node has list values, this function unwraps them and converts them to an appropriate type based on the provided function.

        If this node has a scalar value, this function treats it as a list with one value.

        Type Parameters:
        V - expected type
        Parameters:
        elementType - expected type
        defSupplier - function that will be called to calculate a default value only if there is no existing value of the correct type
        Returns:
        an immutable copy of the values contained that could be successfully converted, or def if no values could be converted.
        Throws:
        SerializationException - if any value fails to be converted to the requested type
        Since:
        4.0.0
      • getList

        default <V> @Nullable java.util.List<V> getList​(java.lang.Class<V> type)
                                                 throws SerializationException
        If this node has list values, this function unwraps them and converts them to an appropriate type based on the provided function.

        If this node has a scalar value, this function treats it as a list with one value.

        Type Parameters:
        V - the expected type
        Parameters:
        type - the expected type
        Returns:
        an immutable copy of the values contained
        Throws:
        SerializationException - if any value fails to be converted to the requested type
        Since:
        4.0.0
      • getList

        default <V> java.util.List<V> getList​(java.lang.Class<V> elementType,
                                              java.util.List<V> def)
                                       throws SerializationException
        If this node has list values, this function unwraps them and converts them to an appropriate type based on the provided function.

        If this node has a scalar value, this function treats it as a list with one value.

        Type Parameters:
        V - expected type
        Parameters:
        elementType - expected type
        def - default value if no appropriate value is set
        Returns:
        an immutable copy of the values contained that could be successfully converted, or def if no values could be converted.
        Throws:
        SerializationException - if any value fails to be converted to the requested type
        Since:
        4.0.0
      • getList

        default <V> java.util.List<V> getList​(java.lang.Class<V> elementType,
                                              java.util.function.Supplier<java.util.List<V>> defSupplier)
                                       throws SerializationException
        If this node has list values, this function unwraps them and converts them to an appropriate type based on the provided function.

        If this node has a scalar value, this function treats it as a list with one value.

        Type Parameters:
        V - expected type
        Parameters:
        elementType - expected type
        defSupplier - function that will be called to calculate a default value only if there is no existing value of the correct type
        Returns:
        an immutable copy of the values contained that could be successfully converted, or def if no values could be converted.
        Throws:
        SerializationException - if any value fails to be converted to the requested type
        Since:
        4.0.0
      • getString

        default @Nullable java.lang.String getString()
        Gets the value typed using the appropriate type conversion from Scalars.
        Returns:
        the value coerced to a String, or null if no value
        Since:
        4.0.0
        See Also:
        raw()
      • getString

        default java.lang.String getString​(java.lang.String def)
        Gets the value typed using the appropriate type conversion from Scalars.
        Parameters:
        def - the default value if no appropriate value is set
        Returns:
        the value coerced to a String, or def if no value
        Since:
        4.0.0
        See Also:
        raw()
      • getFloat

        default float getFloat()
        Gets the value typed using the appropriate type conversion from Scalars.
        Returns:
        the value coerced to a float, or NUMBER_DEF if not a float
        Since:
        4.0.0
        See Also:
        raw()
      • getFloat

        default float getFloat​(float def)
        Gets the value typed using the appropriate type conversion from Scalars.
        Parameters:
        def - the default value if no appropriate value is set
        Returns:
        the value coerced to a float, or def if not a float
        Since:
        4.0.0
        See Also:
        raw()
      • getDouble

        default double getDouble()
        Gets the value typed using the appropriate type conversion from Scalars.
        Returns:
        the value coerced to a double, or NUMBER_DEF if coercion failed
        Since:
        4.0.0
        See Also:
        raw()
      • getDouble

        default double getDouble​(double def)
        Gets the value typed using the appropriate type conversion from Scalars.
        Parameters:
        def - the default value if no appropriate value is set
        Returns:
        the value coerced to a double, or def if coercion failed
        Since:
        4.0.0
        See Also:
        raw()
      • getInt

        default int getInt()
        Gets the value typed using the appropriate type conversion from Scalars.
        Returns:
        value coerced to an integer, or NUMBER_DEF if coercion failed.
        Since:
        4.0.0
        See Also:
        raw()
      • getInt

        default int getInt​(int def)
        Gets the value typed using the appropriate type conversion from Scalars.
        Parameters:
        def - the default value if no appropriate value is set
        Returns:
        value coerced to an integer, or def if coercion failed.
        Since:
        4.0.0
        See Also:
        raw()
      • getLong

        default long getLong()
        Gets the value typed using the appropriate type conversion from Scalars.
        Returns:
        value coerced to a long, or NUMBER_DEF if coercion failed
        Since:
        4.0.0
        See Also:
        raw()
      • getLong

        default long getLong​(long def)
        Gets the value typed using the appropriate type conversion from Scalars.
        Parameters:
        def - the default value if no appropriate value is set
        Returns:
        value coerced to a long, or def if coercion failed
        Since:
        4.0.0
        See Also:
        raw()
      • getBoolean

        default boolean getBoolean()
        Gets the value typed using the appropriate type conversion from Scalars.
        Returns:
        value coerced to a boolean, or false if coercion failed
        Since:
        4.0.0
        See Also:
        raw()
      • getBoolean

        default boolean getBoolean​(boolean def)
        Gets the value typed using the appropriate type conversion from Scalars.
        Parameters:
        def - the default value if no appropriate value is set
        Returns:
        value coerced to a boolean, or def if coercion failed
        Since:
        4.0.0
        See Also:
        raw()
      • set

        ConfigurationNode set​(@Nullable java.lang.Object value)
                       throws SerializationException
        Set this node's value to the given value.

        The value type will be taken from the provided value's class and used to determine a serializer. To set a value of a parameterized type, the parameters must be explicitly specified.

        Parameters:
        value - the value to set
        Returns:
        this node
        Throws:
        SerializationException
        Since:
        4.0.0
      • set

        <V> ConfigurationNode set​(io.leangen.geantyref.TypeToken<V> type,
                                  @Nullable V value)
                           throws SerializationException
        Set this node's value to the given value.

        If the provided value is a Collection or a Map, it will be unwrapped into the appropriate configuration node structure.

        This method will also perform serialization using the appropriate TypeSerializer for the given type, or casting if no type serializer is found.

        Type Parameters:
        V - the type to serialize to
        Parameters:
        type - the type to use for serialization type information
        value - the value to set
        Returns:
        this node
        Throws:
        SerializationException - if the value fails to be converted to the requested type. No change will be made to the node.
        Since:
        4.0.0
      • set

        <V> ConfigurationNode set​(java.lang.Class<V> type,
                                  @Nullable V value)
                           throws SerializationException
        Set this node's value to the given value.

        If the provided value is a Collection or a Map, it will be unwrapped into the appropriate configuration node structure.

        This method will also perform serialization using the appropriate TypeSerializer for the given type, or casting if no type serializer is found.

        This method will fail if a raw type (i.e. a parameterized type without its type parameters) is passed.

        Type Parameters:
        V - the type to serialize to
        Parameters:
        type - the type to use for serialization type information
        value - the value to set
        Returns:
        this node
        Throws:
        java.lang.IllegalArgumentException - if a raw type is passed
        SerializationException - if the value fails to be converted to the requested type. No change will be made to the node.
        Since:
        4.0.0
      • set

        ConfigurationNode set​(java.lang.reflect.Type type,
                              @Nullable java.lang.Object value)
                       throws SerializationException
        Set this node's value to the given value.

        If the provided value is a Collection or a Map, it will be unwrapped into the appropriate configuration node structure.

        This method will also perform serialization using the appropriate TypeSerializer for the given type, or casting if no type serializer is found.

        This method will fail if a raw type (i.e. a parameterized type without its type parameters) is passed.

        Because this method accepts a non-parameterized Type parameter, it has no compile-time type checking. The variants that take TypeToken and set(Class, Object) should be preferred where possible.

        Parameters:
        type - the type to use for serialization type information
        value - the value to set
        Returns:
        this node
        Throws:
        java.lang.IllegalArgumentException - if a raw type is passed
        java.lang.IllegalArgumentException - if value is not either null or of type type
        SerializationException - if the value fails to be converted to the requested type. No change will be made to the node.
        Since:
        4.0.0
      • set

        ConfigurationNode set​(java.lang.reflect.AnnotatedType type,
                              @Nullable java.lang.Object value)
                       throws SerializationException
        Set this node's value to the given value.

        If the provided value is a Collection or a Map, it will be unwrapped into the appropriate configuration node structure.

        This method will also perform serialization using the appropriate TypeSerializer for the given type, or casting if no type serializer is found.

        This method will fail if a raw type (i.e. a parameterized type without its type parameters) is passed.

        Because this method accepts a non-parameterized Type parameter, it has no compile-time type checking. The variants that take TypeToken and set(Class, Object) should be preferred where possible.

        Parameters:
        type - the annotated type to use for serialization type information
        value - the value to set
        Returns:
        this node
        Throws:
        java.lang.IllegalArgumentException - if a raw type is passed
        java.lang.IllegalArgumentException - if value is not either null or of type type
        SerializationException - if the value fails to be converted to the requested type. No change will be made to the node.
        Since:
        4.2.0
      • setList

        default <V> ConfigurationNode setList​(java.lang.Class<V> elementType,
                                              @Nullable java.util.List<V> items)
                                       throws SerializationException
        Set the node's value to the provided list.

        This method provides a helper for constructing the appropriate Type for serializing a List

        Type Parameters:
        V - list element type, the T in List<T>
        Parameters:
        elementType - the type of the list elements. This must not be a raw type.
        items - the list to serializer
        Returns:
        this node
        Throws:
        SerializationException - if the value fails to be converted to the requested type.
        Since:
        4.0.0
        See Also:
        for details on restrictions.
      • setList

        default <V> ConfigurationNode setList​(io.leangen.geantyref.TypeToken<V> elementType,
                                              @Nullable java.util.List<V> items)
                                       throws SerializationException
        Set the node's value to the provided list.

        This method provides a helper for constructing the appropriate Type for serializing a List

        Type Parameters:
        V - list element type, the T in List<T>
        Parameters:
        elementType - the type of the list elements. This must not be a raw type.
        items - the list to serializer
        Returns:
        this node
        Throws:
        SerializationException - if the value fails to be converted to the requested type.
        Since:
        4.0.0
        See Also:
        for details on restrictions.
      • raw

        @Nullable java.lang.Object raw()
        Get the raw value of this node.

        The raw value is the plain value that will be passed to the loaders, without serialization except for unwrapping of maps and collections.

        Returns:
        this configuration's current value
        Since:
        4.0.0
        See Also:
        raw(Object)
      • raw

        ConfigurationNode raw​(@Nullable java.lang.Object value)
        Set the raw value of this node.

        The provided value must be of a type accepted by ConfigurationOptions.acceptsType(Class). No other serialization will be performed.

        Parameters:
        value - the value to set on this node
        Returns:
        this node
        Since:
        4.0.0
      • rawScalar

        @Nullable java.lang.Object rawScalar()
        Get the raw value of this node if the node is a scalar.

        The raw value is the plain value that will be passed to the loaders, without serialization.

        Map and list values will not be unboxed.

        Returns:
        this configuration's current value if it is a scalar, or else null.
        Since:
        4.0.0
        See Also:
        raw()
      • from

        ConfigurationNode from​(ConfigurationNode other)
        Apply all data from other to this node, overwriting any existing data.
        Parameters:
        other - source node
        Returns:
        this node
        Since:
        4.0.0
      • mergeFrom

        ConfigurationNode mergeFrom​(ConfigurationNode other)
        Set all the values from the given node that are not present in this node to their values in the provided node.

        Map keys will be merged. Lists and scalar values will be replaced.

        Parameters:
        other - the node to merge values from
        Returns:
        this node
        Since:
        4.0.0
      • removeChild

        boolean removeChild​(java.lang.Object key)
        Removes a direct child of this node.
        Parameters:
        key - the key of the node to remove
        Returns:
        if a node was removed
        Since:
        4.0.0
      • appendListNode

        ConfigurationNode appendListNode()
        Gets a new child node created as the next entry in the list.
        Returns:
        a new child created as the next entry in the list when it is attached
        Since:
        4.0.0
      • copy

        ConfigurationNode copy()
        Creates a deep copy of this node.

        If this node has child nodes (is a list or map), the child nodes will also be copied. This action is performed recursively.

        The resultant node will (initially) contain the same value(s) as this node, and will therefore be equal, however, changes made to the original will not be reflected in the copy, and vice versa.

        The actual scalar values that back the configuration will not be copied - only the node structure that forms the configuration. This is not a problem in most cases, as the scalar values stored in configurations are usually immutable. (e.g. strings, numbers, booleans).

        Returns:
        a copy of this node
        Since:
        4.0.0
      • visit

        default <S,​T,​E extends java.lang.Exception> T visit​(ConfigurationVisitor<S,​T,​E> visitor)
                                                                 throws E extends java.lang.Exception
        Visit this node hierarchy as described in ConfigurationVisitor.
        Type Parameters:
        S - the state type
        T - the terminal type
        E - exception type that may be thrown
        Parameters:
        visitor - the visitor
        Returns:
        returned terminal from the visitor
        Throws:
        E - when throw by visitor implementation
        E extends java.lang.Exception
        Since:
        4.0.0
      • visit

        <S,​T,​E extends java.lang.Exception> T visit​(ConfigurationVisitor<S,​T,​E> visitor,
                                                                S state)
                                                         throws E extends java.lang.Exception
        Visit this node hierarchy as described in ConfigurationVisitor.
        Type Parameters:
        T - the terminal type
        S - the state type
        E - exception type that may be thrown
        Parameters:
        visitor - the visitor
        state - the state to start with
        Returns:
        returned terminal from the visitor
        Throws:
        E - when throw by visitor implementation
        E extends java.lang.Exception
        Since:
        4.0.0
      • visit

        default <S,​T> T visit​(ConfigurationVisitor.Safe<S,​T> visitor)
        Visit this node hierarchy as described in ConfigurationVisitor.

        This overload will remove the need for exception handling for visitors that do not have any checked exceptions.

        Type Parameters:
        S - the state type
        T - the terminal type
        Parameters:
        visitor - the visitor
        Returns:
        the returned terminal from the visitor
        Since:
        4.0.0
      • visit

        <S,​T> T visit​(ConfigurationVisitor.Safe<S,​T> visitor,
                            S state)
        Visit this node hierarchy as described in ConfigurationVisitor.

        This overload will remove the need for exception handling for visitors that do not have any checked exceptions.

        Type Parameters:
        T - the terminal type
        S - the state type
        Parameters:
        visitor - the visitor
        state - the state to start with
        Returns:
        the returned terminal from the visitor
        Since:
        4.0.0
      • hint

        <V> ConfigurationNode hint​(RepresentationHint<V> hint,
                                   @Nullable V value)
        Set a representation hint on this node.

        Removing a hint from this node means the hint's value will be delegated to the node's parent. To explicitly revert to a hint's default, apply that default value.

        Type Parameters:
        V - hint value type
        Parameters:
        hint - the hint to set a value for
        value - value to set, or null to unset for self
        Returns:
        this node
        Since:
        4.0.0
      • hint

        <V> @Nullable V hint​(RepresentationHint<V> hint)
        Query a representation hint from this node.

        If the hint is not set on this node, its parents will be recursively checked for a value.

        Type Parameters:
        V - value type
        Parameters:
        hint - the hint to get
        Returns:
        value of the hint, or RepresentationHint.defaultValue()
        Since:
        4.0.0
      • ownHint

        <V> @Nullable V ownHint​(RepresentationHint<V> hint)
        Query a representation hint from this node.

        This will only check the current node, and return null rather than any default value.

        Type Parameters:
        V - value type
        Parameters:
        hint - the hint to get
        Returns:
        value of the hint, or null
        Since:
        4.0.0
      • ownHints

        java.util.Map<RepresentationHint<?>,​?> ownHints()
        Get an unmodifiable copy of representation hints stored on this node.

        This does not include inherited hints.

        Returns:
        copy of hints this node has set.
        Since:
        4.0.0