Class SimpleConfigurationNode

    • Method Detail

      • getValue

        public Object getValue​(Object def)
        Description copied from interface: ConfigurationNode
        Get the current value associated with this node.

        If this node has children, this method will recursively unwrap them to construct a List or a Map.

        Specified by:
        getValue in interface ConfigurationNode
        Parameters:
        def - The default value to return if this node has no set value
        Returns:
        This configuration's current value, or def if there is none
      • getValue

        public Object getValue​(@NonNull Supplier<Object> defSupplier)
        Description copied from interface: ConfigurationNode
        Get the current value associated with this node.

        If this node has children, this method will recursively unwrap them to construct a List or a Map.

        Specified by:
        getValue in interface ConfigurationNode
        Parameters:
        defSupplier - The function that will be called to calculate a default value only if there is no existing value
        Returns:
        This configuration's current value, or def if there is none
      • getValue

        public <T> T getValue​(@NonNull Function<Object,​T> transformer,
                              T def)
        Description copied from interface: ConfigurationNode
        Gets the appropriately transformed typed version of this node's value from the provided transformation function.
        Specified by:
        getValue in interface ConfigurationNode
        Type Parameters:
        T - The expected type
        Parameters:
        transformer - The transformation function
        def - The default value to return if this node has no set value or is not of a convertible type
        Returns:
        A transformed value of the correct type, or def either if no value is present or the value could not be converted
      • getValue

        public <T> T getValue​(@NonNull Function<Object,​T> transformer,
                              @NonNull Supplier<T> defSupplier)
        Description copied from interface: ConfigurationNode
        Gets the appropriately transformed typed version of this node's value from the provided transformation function.
        Specified by:
        getValue in interface ConfigurationNode
        Type Parameters:
        T - The expected type
        Parameters:
        transformer - The transformation function
        defSupplier - The function that will be called to calculate a default value only if there is no existing value of the correct type
        Returns:
        A transformed value of the correct type, or def either if no value is present or the value could not be converted
      • getList

        public <T> @NonNull List<T> getList​(@NonNull Function<Object,​T> transformer)
        Description copied from interface: ConfigurationNode
        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

        Specified by:
        getList in interface ConfigurationNode
        Type Parameters:
        T - The expected type
        Parameters:
        transformer - The transformation function
        Returns:
        An immutable copy of the values contained
      • getList

        public <T> List<T> getList​(@NonNull Function<Object,​T> transformer,
                                   List<T> def)
        Description copied from interface: ConfigurationNode
        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.

        Specified by:
        getList in interface ConfigurationNode
        Type Parameters:
        T - The expected type
        Parameters:
        transformer - The transformation function
        def - The 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
      • getList

        public <T> List<T> getList​(@NonNull Function<Object,​T> transformer,
                                   @NonNull Supplier<List<T>> defSupplier)
        Description copied from interface: ConfigurationNode
        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.

        Specified by:
        getList in interface ConfigurationNode
        Type Parameters:
        T - The expected type
        Parameters:
        transformer - The transformation function
        defSupplier - The 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
      • getList

        public <T> List<T> getList​(@NonNull TypeToken<T> type,
                                   List<T> def)
                            throws ObjectMappingException
        Description copied from interface: ConfigurationNode
        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.

        Specified by:
        getList in interface ConfigurationNode
        Type Parameters:
        T - The expected type
        Parameters:
        type - The expected type
        def - The 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:
        ObjectMappingException - If any value fails to be converted to the requested type
      • getList

        public <T> List<T> getList​(@NonNull TypeToken<T> type,
                                   @NonNull Supplier<List<T>> defSupplier)
                            throws ObjectMappingException
        Description copied from interface: ConfigurationNode
        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.

        Specified by:
        getList in interface ConfigurationNode
        Type Parameters:
        T - The expected type
        Parameters:
        type - The expected type
        defSupplier - The 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:
        ObjectMappingException - If any value fails to be converted to the requested type
      • getValue

        public <T> T getValue​(@NonNull TypeToken<T> type,
                              T def)
                       throws ObjectMappingException
        Description copied from interface: ConfigurationNode
        Get the current value associated with this node.

        If this node has children, this method will recursively unwrap them to construct a List or a Map.

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

        Specified by:
        getValue in interface ConfigurationNode
        Type Parameters:
        T - the type to get
        Parameters:
        type - The type to deserialize to
        def - The value to return if no value or value is not of appropriate type
        Returns:
        the value if of the proper type, else def
        Throws:
        ObjectMappingException - If the value fails to be converted to the requested type
      • getValue

        public <T> T getValue​(@NonNull TypeToken<T> type,
                              @NonNull Supplier<T> defSupplier)
                       throws ObjectMappingException
        Description copied from interface: ConfigurationNode
        Get the current value associated with this node.

        If this node has children, this method will recursively unwrap them to construct a List or a Map.

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

        Specified by:
        getValue in interface ConfigurationNode
        Type Parameters:
        T - 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:
        ObjectMappingException - If the value fails to be converted to the requested type
      • getNode

        public @NonNull SimpleConfigurationNode getNode​(@NonNull Object @NonNull ... path)
        Description copied from interface: ConfigurationNode
        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 configration 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.

        Specified by:
        getNode in interface ConfigurationNode
        Parameters:
        path - The path to fetch the node at
        Returns:
        The node at the given path, possibly virtual
      • getNode

        public @NonNull SimpleConfigurationNode getNode​(@NonNull Iterable<?> path)
        Description copied from interface: ConfigurationNode
        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 iterable 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.

        Specified by:
        getNode in interface ConfigurationNode
        Parameters:
        path - The path to fetch the node at
        Returns:
        The node at the given path, possibly virtual
      • isVirtual

        public boolean isVirtual()
        Description copied from interface: ConfigurationNode
        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.

        Specified by:
        isVirtual in interface ConfigurationNode
        Returns:
        true if this node is virtual
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: ConfigurationNode
        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 distinct value from ConfigurationNode.isVirtual(). Emptiness refers to the value of this node itself, while virtuality refers to whether or not this node is attached to its parent and the rest of the configuration structure.
        Specified by:
        isEmpty in interface ConfigurationNode
        Returns:
        Whether this node is empty
      • getChild

        protected SimpleConfigurationNode getChild​(Object key,
                                                   boolean attach)
        Gets a child node, relative to this.
        Parameters:
        key - The key
        attach - If the resultant node should be automatically attached
        Returns:
        The child node
      • copy

        public @NonNull SimpleConfigurationNode copy()
        Description copied from interface: ConfigurationNode
        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).

        Specified by:
        copy in interface ConfigurationNode
        Returns:
        A copy of this node
      • clear

        protected void clear()
      • visit

        public <S,​T,​E extends Exception> T visit​(ConfigurationVisitor<S,​T,​E> visitor,
                                                             S state)
                                                      throws E extends Exception
        Description copied from interface: ConfigurationNode
        Visit this node hierarchy as described in ConfigurationVisitor
        Specified by:
        visit in interface ConfigurationNode
        Type Parameters:
        S - The state type
        T - The terminal type
        E - exception type that may be thrown
        Parameters:
        visitor - The visitor
        state - The state to start with
        Returns:
        The returned terminal from the visitor
        Throws:
        E - when throw by visitor implementation
        E extends Exception
      • visit

        public <S,​T> T visit​(ConfigurationVisitor.Safe<S,​T> visitor,
                                   S state)
        Description copied from interface: ConfigurationNode
        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.
        Specified by:
        visit in interface ConfigurationNode
        Type Parameters:
        S - The state type
        T - The terminal type
        Parameters:
        visitor - The visitor
        state - The state to start with
        Returns:
        The returned terminal from the visitor