T - the type of queried tree nodespublic final class ConfigQuery<T extends ConfigNode>
extends java.lang.Object
A ConfigQuery follows a path in the tree, represented by a list of strings.
It can notably be used to retrieve nodes from various config trees with a similar structure.
| Modifier and Type | Method and Description |
|---|---|
static ConfigQuery<ConfigBranch> |
branch(java.lang.String first,
java.lang.String... more)
Creates a
ConfigQuery for a branch with a specific path. |
static <V> ConfigQuery<ConfigLeaf<V>> |
leaf(java.lang.Class<? super V> propertyType,
java.lang.String first,
java.lang.String... more)
Creates a
ConfigQuery for a property with a specific path and value type. |
T |
run(ConfigTree cfg)
Runs this query on a config tree.
|
java.util.Optional<T> |
search(ConfigTree cfg)
Searches a config tree for a node satisfying this query.
|
java.lang.String |
toString()
Returns a string representation of this query.
|
public static ConfigQuery<ConfigBranch> branch(java.lang.String first, java.lang.String... more)
ConfigQuery for a branch with a specific path.
Each part of the path must correspond to a single node name.
The first part matches a direct child node of the root supplied to
the search(ConfigTree) and run(ConfigTree) methods.
Each additional name matches a node such that the nth name
matches a node at depth n, starting from the supplied tree.
The last name should be the name of the branch to retrieve.
first - the first name in the config pathmore - additional node names forming the config pathpublic static <V> ConfigQuery<ConfigLeaf<V>> leaf(java.lang.Class<? super V> propertyType, java.lang.String first, java.lang.String... more)
ConfigQuery for a property with a specific path and value type.
Each part of the path must correspond to a single node name.
The first part matches a direct child node of the root supplied to
the search(ConfigTree) and run(ConfigTree) methods.
Each additional name matches a node such that the nth name
matches a node at depth n, starting from the supplied tree.
The last name should be the name of the leaf to retrieve.
The returned query will only match a leaf with a property type
that is identical to the given propertyType.
propertyType - a class object representing the type of values held by queried propertiesfirst - the first name in the config pathmore - additional node names forming the config pathpublic java.util.Optional<T> search(ConfigTree cfg)
Optional.empty() is returned.cfg - the config tree to search inOptional describing the queried node,
or Optional.empty().run(ConfigTree)@Nonnull public T run(ConfigTree cfg) throws FiberQueryException
If this query's parameters do not match the config's structure,
a FiberQueryException carrying error details is thrown.
The exception's information can be used for further handling of the erroring config.
cfg - the config tree to run the query onFiberQueryException - if this query's parameters do not match the config's structureFiberQueryException.MissingChild,
FiberQueryException.WrongType,
search(ConfigTree)public java.lang.String toString()
The string representation consists of the expected node type, followed by the expected value type, if any, followed by a representation of this query's path where individual node names are joined by dots.
toString in class java.lang.Object