-
-
Notifications
You must be signed in to change notification settings - Fork 69
Node
ConfigurationNodes are the basic object of Configurate. A node represents any single point in a configuration tree, and can be used to navigate around the tree to extract values. This page aims to cover the most common points about nodes, but the javadocs present the most complete method-by-method documentation.
In most cases nodes are constructed by ConfigurationLoaders, either in the process of loading a configuration, or by calling the ConfigurationLoader#createEmptyNode(ConfigurationOptions)
method. These methods are guaranteed to return the most correct node implementation supported by a specific loader.
Options: The ConfigurationOptions object presents a set of options that control the functionality of a configuration node tree. Passing null
for options is not supported. Instead, use ConfigurationOptions.defaults()
to get a default options object.
Interface: BasicConfigurationNode
Construct: BasicConfigurationNode.root()
Interface: CommentedConfigurationNode
Construct: CommentedConfigurationNode.root()
key(): Return the key of the current node
path(): Return the full path of the current node. This one is kinda expensive because it has to create the array from parents
parent(): Gets the current parent. If the parent is not attached, this may not be the final parent once this node becomes attached
node(Object... path): Get a node at the given path. Each element in the path array is a single level. This method will create a new unattached node if none are present, meaning that it never returns null
node(Iterable<?> path): Get a node at the given path. Each element in the path Iterable
is a single level. This method will create a new unattached node if none are present, meaning that it never returns null
get(Class<T>)/get(Class<T>, T default)/get(TypeToken<T>)/get(TypeToken<T>, T default): Returns the raw value for the node. If the node is a compound value like a list or a map, this method will unwrap the child nodes (recursively) to give a List or Map return value.
Caution: A lot of projects have their own TypeToken
s which could be accidentally imported. We use only the io.leangen.geantyref.TypeToken
class in Configurate.
There exist methods to convert this object to values of different types: getString, Int, Float, etc. The getList(Function<Object,T> converter) method is a bit more interesting. It takes a function that is executed for each element in the list to get its final value.
set(Object value): Sets the value, wrapping compound values as necessary. A type serializer will be chosen based on the Class
of the provided objects. For values of parameterized types (Map<K, V>
, List<T>
, etc.) one of the TypeToken overloads must be used instead.
raw() and raw(Object): Work with the raw value of the node, bypassing any type serializers. These values must be types supported by the loaders being used.