Class SimpleConfigurationNode
- All Implemented Interfaces:
ConfigurationNode
- Direct Known Subclasses:
SimpleCommentedConfigurationNode
public class SimpleConfigurationNode extends Object implements ConfigurationNode
ConfigurationNode.-
Field Summary
-
Constructor Summary
Constructors Modifier Constructor Description protectedSimpleConfigurationNode(@Nullable Object key, @Nullable SimpleConfigurationNode parent, @NonNull ConfigurationOptions options)protectedSimpleConfigurationNode(@Nullable SimpleConfigurationNode parent, SimpleConfigurationNode copyOf) -
Method Summary
Modifier and Type Method Description protected SimpleConfigurationNodeattachChildIfAbsent(SimpleConfigurationNode child)protected voidattachIfNecessary()protected voidclear()@NonNull SimpleConfigurationNodecopy()Creates a deep copy of this node.protected @NonNull SimpleConfigurationNodecopy(@Nullable SimpleConfigurationNode parent)protected SimpleConfigurationNodecreateNode(Object path)booleanequals(Object o)@NonNull SimpleConfigurationNodegetAppendedNode()Deprecated.protected SimpleConfigurationNodegetChild(Object key, boolean attach)Gets a child node, relative to this.@NonNull List<? extends SimpleConfigurationNode>getChildrenList()Gets the "list children" attached to this node, if it has any.@NonNull Map<Object,? extends SimpleConfigurationNode>getChildrenMap()Gets the "map children" attached to this node, if it has any.@Nullable ObjectgetKey()Gets the "key" of this node.<T> List<T>getList(@NonNull TypeToken<T> type, @NonNull Supplier<List<T>> defSupplier)If this node has list values, this function unwraps them and converts them to an appropriate type based on the provided function.<T> List<T>getList(@NonNull TypeToken<T> type, List<T> def)If this node has list values, this function unwraps them and converts them to an appropriate type based on the provided function.<T> @NonNull List<T>getList(@NonNull Function<Object,T> transformer)If this node has list values, this function unwraps them and converts them to an appropriate type based on the provided function.<T> List<T>getList(@NonNull Function<Object,T> transformer, @NonNull Supplier<List<T>> defSupplier)If this node has list values, this function unwraps them and converts them to an appropriate type based on the provided function.<T> List<T>getList(@NonNull Function<Object,T> transformer, List<T> def)If this node has list values, this function unwraps them and converts them to an appropriate type based on the provided function.@NonNull SimpleConfigurationNodegetNode(@NonNull Iterable<?> path)Gets the node at the given (relative) path, possibly traversing multiple levels of nodes.@NonNull SimpleConfigurationNodegetNode(@NonNull Object @NonNull ... path)Gets the node at the given (relative) path, possibly traversing multiple levels of nodes.@NonNull ConfigurationOptionsgetOptions()Gets the options that currently apply to this node@Nullable SimpleConfigurationNodegetParent()Gets the parent of this node.@NonNull Object[]getPath()Gets the full path ofkeysfrom the root node to this node.<T> TgetValue(@NonNull TypeToken<T> type, @NonNull Supplier<T> defSupplier)Get the current value associated with this node.<T> TgetValue(@NonNull TypeToken<T> type, T def)Get the current value associated with this node.<T> TgetValue(@NonNull Function<Object,T> transformer, @NonNull Supplier<T> defSupplier)Gets the appropriately transformed typed version of this node's value from the provided transformation function.<T> TgetValue(@NonNull Function<Object,T> transformer, T def)Gets the appropriately transformed typed version of this node's value from the provided transformation function.ObjectgetValue(@NonNull Supplier<Object> defSupplier)Get the current value associated with this node.ObjectgetValue(Object def)Get the current value associated with this node.@NonNull ValueTypegetValueType()Gets the value type of this node.inthashCode()booleanisEmpty()Return true when this node has a null or empty value.booleanisVirtual()Gets if this node is virtual.@NonNull ConfigurationNodemergeValuesFrom(@NonNull ConfigurationNode other)Set all the values from the given node that are not present in this node to their values in the provided node.booleanremoveChild(@NonNull Object key)Removes a direct child of this nodestatic @NonNull SimpleConfigurationNoderoot()Deprecated.UseConfigurationNode.root()insteadstatic @NonNull SimpleConfigurationNoderoot(@NonNull ConfigurationOptions options)Deprecated.UseConfigurationNode.root(ConfigurationOptions)instead@NonNull SimpleConfigurationNodesetValue(@Nullable Object newValue)Set this node's value to the given value.StringtoString()<S, T> Tvisit(ConfigurationVisitor.Safe<S,T> visitor, S state)Visit this node hierarchy as described inConfigurationVisitorThis overload will remove the need for exception handling for visitors that do not have any checked exceptions.<S, T, E extends Exception>
Tvisit(ConfigurationVisitor<S,T,E> visitor, S state)Visit this node hierarchy as described inConfigurationVisitorMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface ninja.leaping.configurate.ConfigurationNode
act, appendListNode, getBoolean, getBoolean, getDouble, getDouble, getFloat, getFloat, getInt, getInt, getList, getLong, getLong, getString, getString, getValue, getValue, getValue, hasListChildren, hasMapChildren, isList, isMap, setValue, visit, visit
-
Constructor Details
-
SimpleConfigurationNode
protected SimpleConfigurationNode(@Nullable Object key, @Nullable SimpleConfigurationNode parent, @NonNull ConfigurationOptions options) -
SimpleConfigurationNode
protected SimpleConfigurationNode(@Nullable SimpleConfigurationNode parent, SimpleConfigurationNode copyOf)
-
-
Method Details
-
root
Deprecated.UseConfigurationNode.root()insteadCreate a new node with no parent anddefaultoptions- Returns:
- The newly created node
-
root
@Deprecated public static @NonNull SimpleConfigurationNode root(@NonNull ConfigurationOptions options)Deprecated.UseConfigurationNode.root(ConfigurationOptions)insteadCreate a new node with no parent and defined options- Parameters:
options- The options to use in this node.- Returns:
- The newly created node
-
getValue
Description copied from interface:ConfigurationNodeGet 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:
getValuein interfaceConfigurationNode- Parameters:
def- The default value to return if this node has no set value- Returns:
- This configuration's current value, or
defif there is none
-
getValue
Description copied from interface:ConfigurationNodeGet 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:
getValuein interfaceConfigurationNode- 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
defif there is none
-
getValue
Description copied from interface:ConfigurationNodeGets the appropriately transformed typed version of this node's value from the provided transformation function.- Specified by:
getValuein interfaceConfigurationNode- Type Parameters:
T- The expected type- Parameters:
transformer- The transformation functiondef- 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
defeither if no value is present or the value could not be converted
-
getValue
Description copied from interface:ConfigurationNodeGets the appropriately transformed typed version of this node's value from the provided transformation function.- Specified by:
getValuein interfaceConfigurationNode- Type Parameters:
T- The expected type- Parameters:
transformer- The transformation functiondefSupplier- 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
defeither if no value is present or the value could not be converted
-
getList
Description copied from interface:ConfigurationNodeIf 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:
getListin interfaceConfigurationNode- Type Parameters:
T- The expected type- Parameters:
transformer- The transformation function- Returns:
- An immutable copy of the values contained
-
getList
Description copied from interface:ConfigurationNodeIf 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:
getListin interfaceConfigurationNode- Type Parameters:
T- The expected type- Parameters:
transformer- The transformation functiondef- The default value if no appropriate value is set- Returns:
- An immutable copy of the values contained that could be successfully converted, or
defif 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:ConfigurationNodeIf 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:
getListin interfaceConfigurationNode- Type Parameters:
T- The expected type- Parameters:
transformer- The transformation functiondefSupplier- 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
defif no values could be converted
-
getList
Description copied from interface:ConfigurationNodeIf 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:
getListin interfaceConfigurationNode- Type Parameters:
T- The expected type- Parameters:
type- The expected typedef- The default value if no appropriate value is set- Returns:
- An immutable copy of the values contained that could be successfully converted, or
defif 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 ObjectMappingExceptionDescription copied from interface:ConfigurationNodeIf 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:
getListin interfaceConfigurationNode- Type Parameters:
T- The expected type- Parameters:
type- The expected typedefSupplier- 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
defif no values could be converted - Throws:
ObjectMappingException- If any value fails to be converted to the requested type
-
getValue
Description copied from interface:ConfigurationNodeGet 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:
getValuein interfaceConfigurationNode- Type Parameters:
T- the type to get- Parameters:
type- The type to deserialize todef- 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 ObjectMappingExceptionDescription copied from interface:ConfigurationNodeGet 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:
getValuein interfaceConfigurationNode- Type Parameters:
T- the type to get- Parameters:
type- The type to deserialize todefSupplier- 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
-
setValue
Description copied from interface:ConfigurationNodeSet this node's value to the given value.If the provided value is a
This method only accepts native types as values. If the type of a value is unknown at runtime,Collectionor aMap, it will be unwrapped into the appropriate configuration node structure.ConfigurationOptions.acceptsType(Class)will return whether or not it is a native type.- Specified by:
setValuein interfaceConfigurationNode- Parameters:
newValue- The value to set- Returns:
- this
- See Also:
to set a value with any type conversion necessary
-
mergeValuesFrom
Description copied from interface:ConfigurationNodeSet 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.
- Specified by:
mergeValuesFromin interfaceConfigurationNode- Parameters:
other- The node to merge values from- Returns:
- this
-
getNode
Description copied from interface:ConfigurationNodeGets 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
virtualnode will be returned which represents the position.- Specified by:
getNodein interfaceConfigurationNode- Parameters:
path- The path to fetch the node at- Returns:
- The node at the given path, possibly virtual
-
getNode
Description copied from interface:ConfigurationNodeGets 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
virtualnode will be returned which represents the position.- Specified by:
getNodein interfaceConfigurationNode- Parameters:
path- The path to fetch the node at- Returns:
- The node at the given path, possibly virtual
-
isVirtual
Description copied from interface:ConfigurationNodeGets 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:
isVirtualin interfaceConfigurationNode- Returns:
- true if this node is virtual
-
getValueType
Description copied from interface:ConfigurationNodeGets the value type of this node.- Specified by:
getValueTypein interfaceConfigurationNode- Returns:
- The value type
-
getChildrenList
Description copied from interface:ConfigurationNodeGets the "list children" attached to this node, if it has any.If this node does not
have list children, an empty list is returned. For example, if the value of this node is a map, this will return an empty result.- Specified by:
getChildrenListin interfaceConfigurationNode- Returns:
- The list children currently attached to this node
-
getChildrenMap
Description copied from interface:ConfigurationNodeGets the "map children" attached to this node, if it has any.If this node does not
have map children, an empty map returned.- Specified by:
getChildrenMapin interfaceConfigurationNode- Returns:
- The map children currently attached to this node
-
isEmpty
Description copied from interface:ConfigurationNodeReturn 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
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:
isEmptyin interfaceConfigurationNode- Returns:
- Whether this node is empty
-
getChild
Gets a child node, relative to this.- Parameters:
key- The keyattach- If the resultant node should be automatically attached- Returns:
- The child node
-
removeChild
Description copied from interface:ConfigurationNodeRemoves a direct child of this node- Specified by:
removeChildin interfaceConfigurationNode- Parameters:
key- The key of the node to remove- Returns:
- If a node was removed
-
getAppendedNode
Deprecated.Description copied from interface:ConfigurationNodeGets a new child node created as the next entry in the list.- Specified by:
getAppendedNodein interfaceConfigurationNode- Returns:
- A new child created as the next entry in the list when it is attached
-
getKey
Description copied from interface:ConfigurationNodeGets 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
ConfigurationNode.getPath()for that.The
ConfigurationNodes returned as values fromConfigurationNode.getChildrenMap()will have keys derived from their pairing in the map node.The
ConfigurationNodes returned fromConfigurationNode.getChildrenList()will have keys derived from their position (index) in the list node.- Specified by:
getKeyin interfaceConfigurationNode- Returns:
- The key of this node
-
getPath
Description copied from interface:ConfigurationNodeGets the full path ofkeysfrom 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
- Specified by:
getPathin interfaceConfigurationNode- Returns:
- An array compiled from the keys for each node up the hierarchy
- See Also:
for this node's key relative to its direct parent
-
getParent
Description copied from interface:ConfigurationNodeGets the parent of this node.If this node is currently
virtual, this method's result may be inaccurate.- Specified by:
getParentin interfaceConfigurationNode- Returns:
- The nodes parent
-
getOptions
Description copied from interface:ConfigurationNodeGets the options that currently apply to this node- Specified by:
getOptionsin interfaceConfigurationNode- Returns:
- The ConfigurationOptions instance that governs the functionality of this node
-
copy
Description copied from interface:ConfigurationNodeCreates 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:
copyin interfaceConfigurationNode- Returns:
- A copy of this node
-
copy
-
attachIfNecessary
-
createNode
-
attachChildIfAbsent
-
clear
-
visit
public <S, T, E extends Exception> T visit(ConfigurationVisitor<S,T,E> visitor, S state) throws E extends ExceptionDescription copied from interface:ConfigurationNodeVisit this node hierarchy as described inConfigurationVisitor- Specified by:
visitin interfaceConfigurationNode- Type Parameters:
S- The state typeT- The terminal typeE- exception type that may be thrown- Parameters:
visitor- The visitorstate- The state to start with- Returns:
- The returned terminal from the visitor
- Throws:
E- when throw by visitor implementation
-
visit
Description copied from interface:ConfigurationNodeVisit this node hierarchy as described inConfigurationVisitorThis overload will remove the need for exception handling for visitors that do not have any checked exceptions.- Specified by:
visitin interfaceConfigurationNode- Type Parameters:
S- The state typeT- The terminal type- Parameters:
visitor- The visitorstate- The state to start with- Returns:
- The returned terminal from the visitor
-
equals
-
hashCode
-
toString
-