org.apache.commons.configuration2.tree

## Class NodeSelector

- java.lang.Object
- - org.apache.commons.configuration2.tree.NodeSelector

-     public class NodeSelector
      extends Object

  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
  Version:
    $Id: NodeSelector.java 1624601 2014-09-12 18:04:36Z oheger $

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `NodeSelector(String key)` Creates a new instance of `NodeSelector` and initializes it with the key to the target node.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `equals(Object obj)` Compares this object with another one.
    `int` | `hashCode()` Returns a hash code for this object.
    `ImmutableNode` | `select(ImmutableNode root, NodeKeyResolver<ImmutableNode> resolver, NodeHandler<ImmutableNode> handler)` Applies this `NodeSelector` on the specified root node.
    `NodeSelector` | `subSelector(String subKey)` Creates a sub `NodeSelector` object which uses the key(s) of this selector plus the specified key as selection criteria.
    `String` | `toString()` Returns a string representation for this object.

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

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### NodeSelector

          public NodeSelector(String key)

      Creates a new instance of `NodeSelector` and initializes it with the key to the target node.
      Parameters:
        `key` - the key

  - ### Method Detail

    - #### select

          public ImmutableNode select(ImmutableNode root,
                                      NodeKeyResolver<ImmutableNode> resolver,
                                      NodeHandler<ImmutableNode> handler)

      Applies this `NodeSelector` on 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 selector
        `resolver` - the `NodeKeyResolver`
        `handler` - the `NodeHandler`
      Returns:
        the selected target node or null

    - #### subSelector

          public NodeSelector subSelector(String subKey)

      Creates a sub `NodeSelector` object 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 `NodeSelector` instance

    - #### equals

          public boolean equals(Object obj)

      Compares this object with another one. Two instances of `NodeSelector` are considered equal if they have the same keys as selection criteria.
      Overrides:
        `equals` in class `Object`
      Parameters:
        `obj` - the object to be compared
      Returns:
        a flag whether these objects are equal

    - #### hashCode

          public int hashCode()

      Returns a hash code for this object.
      Overrides:
        `hashCode` in class `Object`
      Returns:
        a hash code

    - #### toString

          public String toString()

      Returns a string representation for this object. This string contains the keys to be used as selection criteria.
      Overrides:
        `toString` in class `Object`
      Returns:
        a string for this object

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