Class NodeSelector
java.lang.Object
org.apache.commons.configuration2.tree.NodeSelector
A class for selecting a specific node based on a key or a set of keys.
An instance of this class is initialized with the key of a node. It is also possible to concatenate multiple keys -
e.g. if a sub key is to be constructed from another sub key. NodeSelector provides the select()
method which evaluates the wrapped keys on a specified root node and returns the resulting unique target node. The
class expects that the key(s) stored in an instance select exactly one target node. If this is not the case, result
is null indicating that the selection criteria are not sufficient.
Implementation node: Instances of this class are immutable. They can be shared between arbitrary components.
- Since:
- 2.0
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionNodeSelector(String key) Creates a new instance ofNodeSelectorand initializes it with the key to the target node.privateNodeSelector(List<String> keys) Creates a new instance ofNodeSelectorand initializes it with the list of keys to be used as selection criteria. -
Method Summary
Modifier and TypeMethodDescriptionbooleanCompares this object with another one.private voidgetFilteredResults(ImmutableNode root, NodeKeyResolver<ImmutableNode> resolver, NodeHandler<ImmutableNode> handler, String key, List<ImmutableNode> nodes) Executes a query for a given key and filters the results for nodes only.inthashCode()Returns a hash code for this object.select(ImmutableNode root, NodeKeyResolver<ImmutableNode> resolver, NodeHandler<ImmutableNode> handler) Applies thisNodeSelectoron the specified root node.subSelector(String subKey) Creates a subNodeSelectorobject which uses the key(s) of this selector plus the specified key as selection criteria.toString()Returns a string representation for this object.
-
Field Details
-
nodeKeys
Stores the wrapped keys.
-
-
Constructor Details
-
NodeSelector
Creates a new instance ofNodeSelectorand initializes it with the list of keys to be used as selection criteria.- Parameters:
keys- the keys for selecting nodes
-
NodeSelector
Creates a new instance ofNodeSelectorand initializes it with the key to the target node.- Parameters:
key- the key
-
-
Method Details
-
equals
Compares this object with another one. Two instances ofNodeSelectorare considered equal if they have the same keys as selection criteria. -
getFilteredResults
private void getFilteredResults(ImmutableNode root, NodeKeyResolver<ImmutableNode> resolver, NodeHandler<ImmutableNode> handler, String key, List<ImmutableNode> nodes) Executes a query for a given key and filters the results for nodes only.- Parameters:
root- the root node for the queryresolver- theNodeKeyResolverhandler- theNodeHandlerkey- the keynodes- here the results are stored
-
hashCode
public int hashCode()Returns a hash code for this object. -
select
public ImmutableNode select(ImmutableNode root, NodeKeyResolver<ImmutableNode> resolver, NodeHandler<ImmutableNode> handler) Applies thisNodeSelectoron the specified root node. This method applies the selection criteria stored in this object and tries to determine a single target node. If this is successful, the target node is returned. Otherwise, result is null.- Parameters:
root- the root node on which to apply this selectorresolver- theNodeKeyResolverhandler- theNodeHandler- Returns:
- the selected target node or null
-
subSelector
Creates a subNodeSelectorobject which uses the key(s) of this selector plus the specified key as selection criteria. This is useful when another selection is to be performed on the results of a first selector.- Parameters:
subKey- the additional key for the sub selector- Returns:
- the sub
NodeSelectorinstance
-
toString
Returns a string representation for this object. This string contains the keys to be used as selection criteria.
-