Class AbstractImmutableNodeHandler
java.lang.Object
org.apache.commons.configuration2.tree.AbstractImmutableNodeHandler
- All Implemented Interfaces:
NodeHandler<ImmutableNode>
- Direct Known Subclasses:
TrackedNodeHandler
,TreeData
An abstract base class for a NodeHandler
implementation for ImmutableNode
objects.
This class already implements all methods which need no other information than the passed in node object. Functionality which requires additional state (e.g. querying the root node or a parent node) has to be added by concrete sub classes.
- Since:
- 2.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static boolean
Checks if the passed in node is defined.getAttributes
(ImmutableNode node) Gets an unmodifiable set with the names of all attributes of the specified node.getAttributeValue
(ImmutableNode node, String name) Gets the value of the specified attribute from the given node.getChild
(ImmutableNode node, int index) Gets the child with the given index of the specified node.getChildren
(ImmutableNode node) Gets an unmodifiable list with all children of the specified node.getChildren
(ImmutableNode node, String name) Gets an unmodifiable list of all children of the specified node with the given name.int
getChildrenCount
(ImmutableNode node, String name) Gets the number of children of the specified node with the given name.<C> List
<ImmutableNode> getMatchingChildren
(ImmutableNode node, NodeMatcher<C> matcher, C criterion) Gets an unmodifiable list of all children of the specified node which are matched by the passed inNodeMatcher
against the provided criterion.<C> int
getMatchingChildrenCount
(ImmutableNode node, NodeMatcher<C> matcher, C criterion) Gets the number of children of the specified node which are matched by the givenNodeMatcher
.getValue
(ImmutableNode node) Gets the value of the specified node.boolean
hasAttributes
(ImmutableNode node) Returns a flag whether the passed in node has any attributes.int
indexOfChild
(ImmutableNode parent, ImmutableNode child) Returns the index of the given child node in the list of children of its parent.boolean
isDefined
(ImmutableNode node) Checks whether the specified node is defined.nodeName
(ImmutableNode node) Returns the name of the specified nodeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.commons.configuration2.tree.NodeHandler
getParent, getRootNode
-
Constructor Details
-
AbstractImmutableNodeHandler
AbstractImmutableNodeHandler()
-
-
Method Details
-
checkIfNodeDefined
Checks if the passed in node is defined. Result is true if the node contains any data.- Parameters:
node
- the node in question- Returns:
- true if the node is defined, false otherwise
-
getAttributes
Description copied from interface:NodeHandler
Gets an unmodifiable set with the names of all attributes of the specified node.- Specified by:
getAttributes
in interfaceNodeHandler<ImmutableNode>
- Parameters:
node
- the node- Returns:
- a set with the names of all attributes of this node
-
getAttributeValue
Description copied from interface:NodeHandler
Gets the value of the specified attribute from the given node. If a concreteNodeHandler
supports attributes with multiple values, result might be a collection.- Specified by:
getAttributeValue
in interfaceNodeHandler<ImmutableNode>
- Parameters:
node
- the nodename
- the name of the attribute- Returns:
- the value of this attribute
-
getChild
Description copied from interface:NodeHandler
Gets the child with the given index of the specified node.- Specified by:
getChild
in interfaceNodeHandler<ImmutableNode>
- Parameters:
node
- the nodeindex
- the index (0-based)- Returns:
- the child with the given index
-
getChildren
Description copied from interface:NodeHandler
Gets an unmodifiable list with all children of the specified node.- Specified by:
getChildren
in interfaceNodeHandler<ImmutableNode>
- Parameters:
node
- the node- Returns:
- a list with the child nodes of this node
-
getChildren
Gets an unmodifiable list of all children of the specified node with the given name. This implementation returns an immutable list with all child nodes that have the specified name.- Specified by:
getChildren
in interfaceNodeHandler<ImmutableNode>
- Parameters:
node
- the nodename
- the name of the desired child nodes- Returns:
- a list with all children with the given name
-
getChildrenCount
Description copied from interface:NodeHandler
Gets the number of children of the specified node with the given name. This method exists for performance reasons: for some node implementations it may be by far more efficient to count the children than to query a list of all children and determine its size. A concrete implementation can choose the most efficient way to determine the number of children. If a child name is passed in, only the children with this name are taken into account. If the name null is passed, the total number of children must be returned.- Specified by:
getChildrenCount
in interfaceNodeHandler<ImmutableNode>
- Parameters:
node
- the nodename
- the name of the children in question (can be null for all children)- Returns:
- the number of the selected children
-
getMatchingChildren
public <C> List<ImmutableNode> getMatchingChildren(ImmutableNode node, NodeMatcher<C> matcher, C criterion) Gets an unmodifiable list of all children of the specified node which are matched by the passed inNodeMatcher
against the provided criterion. This method allows for advanced queries on a node's children. This implementation returns an immutable list with all child nodes accepted by the specified matcher.- Specified by:
getMatchingChildren
in interfaceNodeHandler<ImmutableNode>
- Type Parameters:
C
- the type of the criterion- Parameters:
node
- the nodematcher
- theNodeMatcher
defining filter criteriacriterion
- the criterion to be matched against; this object is passed to theNodeMatcher
- Returns:
- a list with all children matched by the matcher
-
getMatchingChildrenCount
Description copied from interface:NodeHandler
Gets the number of children of the specified node which are matched by the givenNodeMatcher
. This is a more generic version ofNodeHandler.getChildrenCount(Object, String)
. It allows checking for arbitrary filter conditions.- Specified by:
getMatchingChildrenCount
in interfaceNodeHandler<ImmutableNode>
- Type Parameters:
C
- the type of the criterion- Parameters:
node
- the nodematcher
- theNodeMatcher
criterion
- the criterion to be passed to theNodeMatcher
- Returns:
- the number of matched children
-
getValue
Description copied from interface:NodeHandler
Gets the value of the specified node.- Specified by:
getValue
in interfaceNodeHandler<ImmutableNode>
- Parameters:
node
- the node- Returns:
- the value of this node
-
hasAttributes
Description copied from interface:NodeHandler
Returns a flag whether the passed in node has any attributes.- Specified by:
hasAttributes
in interfaceNodeHandler<ImmutableNode>
- Parameters:
node
- the node- Returns:
- a flag whether this node has any attributes
-
indexOfChild
Description copied from interface:NodeHandler
Returns the index of the given child node in the list of children of its parent. This method is the opposite operation ofNodeHandler.getChild(Object, int)
. This method returns 0 if the given node is the first child node with this name, 1 for the second child node and so on. If the node has no parent node or if it is an attribute, -1 is returned.- Specified by:
indexOfChild
in interfaceNodeHandler<ImmutableNode>
- Parameters:
parent
- the parent nodechild
- a child node whose index is to be retrieved- Returns:
- the index of this child node
-
isDefined
Checks whether the specified node is defined. Nodes are "defined" if they contain any data, e.g. a value, or attributes, or defined children. This implementation assumes that a node is defined if it has a value or has children or has attributes.- Specified by:
isDefined
in interfaceNodeHandler<ImmutableNode>
- Parameters:
node
- the node to test- Returns:
- a flag whether the passed in node is defined
-
nodeName
Description copied from interface:NodeHandler
Returns the name of the specified node- Specified by:
nodeName
in interfaceNodeHandler<ImmutableNode>
- Parameters:
node
- the node- Returns:
- the name of this node
-