Class AbstractImmutableNodeHandler

java.lang.Object
org.apache.commons.configuration2.tree.AbstractImmutableNodeHandler
All Implemented Interfaces:
NodeHandler<ImmutableNode>
Direct Known Subclasses:
TrackedNodeHandler, TreeData

abstract class AbstractImmutableNodeHandler extends Object implements NodeHandler<ImmutableNode>

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 Details

    • AbstractImmutableNodeHandler

      AbstractImmutableNodeHandler()
  • Method Details

    • nodeName

      public String nodeName(ImmutableNode node)
      Description copied from interface: NodeHandler
      Returns the name of the specified node
      Specified by:
      nodeName in interface NodeHandler<ImmutableNode>
      Parameters:
      node - the node
      Returns:
      the name of this node
    • getValue

      public Object getValue(ImmutableNode node)
      Description copied from interface: NodeHandler
      Gets the value of the specified node.
      Specified by:
      getValue in interface NodeHandler<ImmutableNode>
      Parameters:
      node - the node
      Returns:
      the value of this node
    • getChildren

      public List<ImmutableNode> getChildren(ImmutableNode node)
      Description copied from interface: NodeHandler
      Gets an unmodifiable list with all children of the specified node.
      Specified by:
      getChildren in interface NodeHandler<ImmutableNode>
      Parameters:
      node - the node
      Returns:
      a list with the child nodes of this node
    • getMatchingChildrenCount

      public <C> int getMatchingChildrenCount(ImmutableNode node, NodeMatcher<C> matcher, C criterion)
      Description copied from interface: NodeHandler
      Gets the number of children of the specified node which are matched by the given NodeMatcher. This is a more generic version of NodeHandler.getChildrenCount(Object, String). It allows checking for arbitrary filter conditions.
      Specified by:
      getMatchingChildrenCount in interface NodeHandler<ImmutableNode>
      Type Parameters:
      C - the type of the criterion
      Parameters:
      node - the node
      matcher - the NodeMatcher
      criterion - the criterion to be passed to the NodeMatcher
      Returns:
      the number of matched 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 in NodeMatcher 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 interface NodeHandler<ImmutableNode>
      Type Parameters:
      C - the type of the criterion
      Parameters:
      node - the node
      matcher - the NodeMatcher defining filter criteria
      criterion - the criterion to be matched against; this object is passed to the NodeMatcher
      Returns:
      a list with all children matched by the matcher
    • getChildren

      public List<ImmutableNode> getChildren(ImmutableNode node, String name)
      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 interface NodeHandler<ImmutableNode>
      Parameters:
      node - the node
      name - the name of the desired child nodes
      Returns:
      a list with all children with the given name
    • getChild

      public ImmutableNode getChild(ImmutableNode node, int index)
      Description copied from interface: NodeHandler
      Gets the child with the given index of the specified node.
      Specified by:
      getChild in interface NodeHandler<ImmutableNode>
      Parameters:
      node - the node
      index - the index (0-based)
      Returns:
      the child with the given index
    • indexOfChild

      public int indexOfChild(ImmutableNode parent, ImmutableNode child)
      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 of NodeHandler.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 interface NodeHandler<ImmutableNode>
      Parameters:
      parent - the parent node
      child - a child node whose index is to be retrieved
      Returns:
      the index of this child node
    • getChildrenCount

      public int getChildrenCount(ImmutableNode node, String name)
      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 interface NodeHandler<ImmutableNode>
      Parameters:
      node - the node
      name - the name of the children in question (can be null for all children)
      Returns:
      the number of the selected children
    • getAttributes

      public Set<String> getAttributes(ImmutableNode node)
      Description copied from interface: NodeHandler
      Gets an unmodifiable set with the names of all attributes of the specified node.
      Specified by:
      getAttributes in interface NodeHandler<ImmutableNode>
      Parameters:
      node - the node
      Returns:
      a set with the names of all attributes of this node
    • hasAttributes

      public boolean hasAttributes(ImmutableNode node)
      Description copied from interface: NodeHandler
      Returns a flag whether the passed in node has any attributes.
      Specified by:
      hasAttributes in interface NodeHandler<ImmutableNode>
      Parameters:
      node - the node
      Returns:
      a flag whether this node has any attributes
    • getAttributeValue

      public Object getAttributeValue(ImmutableNode node, String name)
      Description copied from interface: NodeHandler
      Gets the value of the specified attribute from the given node. If a concrete NodeHandler supports attributes with multiple values, result might be a collection.
      Specified by:
      getAttributeValue in interface NodeHandler<ImmutableNode>
      Parameters:
      node - the node
      name - the name of the attribute
      Returns:
      the value of this attribute
    • isDefined

      public boolean isDefined(ImmutableNode node)
      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 interface NodeHandler<ImmutableNode>
      Parameters:
      node - the node to test
      Returns:
      a flag whether the passed in node is defined
    • checkIfNodeDefined

      static boolean checkIfNodeDefined(ImmutableNode node)
      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