org.apache.commons.configuration2.tree

## Class NodeHandlerDecorator<T>

- java.lang.Object
- - org.apache.commons.configuration2.tree.NodeHandlerDecorator<T>

- Type Parameters:
    `T` - the type of the nodes supported by this handler
  All Implemented Interfaces:
    NodeHandler<T>

      public abstract class NodeHandlerDecorator<T>
      extends Object
      implements NodeHandler<T>

  An abstract base class for decorators of a `NodeHandler`.

  This class implements all methods of the `NodeHandler` interface by delegating to another instance. This is convenient if specific functionality of a `NodeHandler` is to be adapted for a special use case. Concrete sub classes have to implement the `getDecoratedNodeHandler()` method to provide the underlying handler.

  Since:
    2.0

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `NodeHandlerDecorator()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Set<String>` | `getAttributes(T node)` Returns an unmodifiable set with the names of all attributes of the specified node.
    `Object` | `getAttributeValue(T node, String name)` Returns the value of the specified attribute from the given node.
    `T` | `getChild(T node, int index)` Returns the child with the given index of the specified node.
    `List<T>` | `getChildren(T node)` Returns an unmodifiable list with all children of the specified node.
    `List<T>` | `getChildren(T node, String name)` Returns an unmodifiable list of all children of the specified node with the given name.
    `int` | `getChildrenCount(T node, String name)` Returns the number of children of the specified node with the given name.
    `protected abstract NodeHandler<T>` | `getDecoratedNodeHandler()` Returns the `NodeHandler` object that is decorated by this instance.
    `<C> List<T>` | `getMatchingChildren(T node, NodeMatcher<C> matcher, C criterion)` Returns an unmodifiable list of all children of the specified node which are matched by the passed in `NodeMatcher` against the provided criterion.
    `<C> int` | `getMatchingChildrenCount(T node, NodeMatcher<C> matcher, C criterion)` Returns the number of children of the specified node which are matched by the given `NodeMatcher`.
    `T` | `getParent(T node)` Returns the parent of the specified node.
    `T` | `getRootNode()` Returns the root node of the underlying hierarchy.
    `Object` | `getValue(T node)` Returns the value of the specified node.
    `boolean` | `hasAttributes(T node)` Returns a flag whether the passed in node has any attributes.
    `int` | `indexOfChild(T parent, T child)` Returns the index of the given child node in the list of children of its parent.
    `boolean` | `isDefined(T node)` Checks whether the specified node is defined.
    `String` | `nodeName(T node)` Returns the name of the specified node

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### NodeHandlerDecorator

          public NodeHandlerDecorator()

  - ### Method Detail

    - #### nodeName

          public String nodeName(T node)

      Description copied from interface: `NodeHandler`
      Returns the name of the specified node
      Specified by:
        `nodeName` in interface `NodeHandler<T>`
      Parameters:
        `node` - the node
      Returns:
        the name of this node

    - #### getValue

          public Object getValue(T node)

      Description copied from interface: `NodeHandler`
      Returns the value of the specified node.
      Specified by:
        `getValue` in interface `NodeHandler<T>`
      Parameters:
        `node` - the node
      Returns:
        the value of this node

    - #### getParent

          public T getParent(T node)

      Description copied from interface: `NodeHandler`
      Returns the parent of the specified node.
      Specified by:
        `getParent` in interface `NodeHandler<T>`
      Parameters:
        `node` - the node
      Returns:
        the parent node

    - #### getChildren

          public List<T> getChildren(T node)

      Description copied from interface: `NodeHandler`
      Returns an unmodifiable list with all children of the specified node.
      Specified by:
        `getChildren` in interface `NodeHandler<T>`
      Parameters:
        `node` - the node
      Returns:
        a list with the child nodes of this node

    - #### getMatchingChildren

          public <C> List<T> getMatchingChildren(T node,
                                                 NodeMatcher<C> matcher,
                                                 C criterion)

      Description copied from interface: `NodeHandler`
      Returns 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.
      Specified by:
        `getMatchingChildren` in interface `NodeHandler<T>`
      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

    - #### getMatchingChildrenCount

          public <C> int getMatchingChildrenCount(T node,
                                                  NodeMatcher<C> matcher,
                                                  C criterion)

      Description copied from interface: `NodeHandler`
      Returns 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<T>`
      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

    - #### getChildren

          public List<T> getChildren(T node,
                                     String name)

      Description copied from interface: `NodeHandler`
      Returns an unmodifiable list of all children of the specified node with the given name.
      Specified by:
        `getChildren` in interface `NodeHandler<T>`
      Parameters:
        `node` - the node
        `name` - the name of the desired child nodes
      Returns:
        a list with all children with the given name

    - #### getChild

          public T getChild(T node,
                            int index)

      Description copied from interface: `NodeHandler`
      Returns the child with the given index of the specified node.
      Specified by:
        `getChild` in interface `NodeHandler<T>`
      Parameters:
        `node` - the node
        `index` - the index (0-based)
      Returns:
        the child with the given index

    - #### indexOfChild

          public int indexOfChild(T parent,
                                  T 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<T>`
      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(T node,
                                      String name)

      Description copied from interface: `NodeHandler`
      Returns 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<T>`
      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(T node)

      Description copied from interface: `NodeHandler`
      Returns an unmodifiable set with the names of all attributes of the specified node.
      Specified by:
        `getAttributes` in interface `NodeHandler<T>`
      Parameters:
        `node` - the node
      Returns:
        a set with the names of all attributes of this node

    - #### hasAttributes

          public boolean hasAttributes(T node)

      Description copied from interface: `NodeHandler`
      Returns a flag whether the passed in node has any attributes.
      Specified by:
        `hasAttributes` in interface `NodeHandler<T>`
      Parameters:
        `node` - the node
      Returns:
        a flag whether this node has any attributes

    - #### getAttributeValue

          public Object getAttributeValue(T node,
                                          String name)

      Description copied from interface: `NodeHandler`
      Returns 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<T>`
      Parameters:
        `node` - the node
        `name` - the name of the attribute
      Returns:
        the value of this attribute

    - #### isDefined

          public boolean isDefined(T node)

      Description copied from interface: `NodeHandler`
      Checks whether the specified node is defined. Nodes are "defined" if they contain any data, e.g. a value, or attributes, or defined children.
      Specified by:
        `isDefined` in interface `NodeHandler<T>`
      Parameters:
        `node` - the node to test
      Returns:
        a flag whether the passed in node is defined

    - #### getRootNode

          public T getRootNode()

      Description copied from interface: `NodeHandler`
      Returns the root node of the underlying hierarchy.
      Specified by:
        `getRootNode` in interface `NodeHandler<T>`
      Returns:
        the current root node

    - #### getDecoratedNodeHandler

          protected abstract NodeHandler<T> getDecoratedNodeHandler()

      Returns the `NodeHandler` object that is decorated by this instance. All method calls are delegated to this object.
      Returns:
        the decorated `NodeHandler`

Copyright © 2001–2022 The Apache Software Foundation. All rights reserved.