Package org.apache.commons.configuration2.tree

# Class QueryResult<T>

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

Type Parameters:
  `T` - the type of the result nodes

public final class QueryResult<T> extends Object

A data class representing a single query result produced by an `ExpressionEngine`.

When passing a key to the `query()` method of `ExpressionEngine` the result can be a set of nodes or attributes - depending on the key. This class can represent both types of results. The aim is to give a user of `ExpressionEngine` all information needed for evaluating the results returned.

Implementation note: Instances are immutable. They are created using the static factory methods.

Since:
  2.0

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static <T> QueryResult<T>`
  `createAttributeResult(T parentNode, String attrName)`
  Creates a `QueryResult` instance representing an attribute result.
  `static <T> QueryResult<T>`
  `createNodeResult(T resultNode)`
  Creates a `QueryResult` instance representing the specified result node.
  `boolean`
  `equals(Object obj)`
  Compares this object with another one.
  `String`
  `getAttributeName()`
  Gets the name of the attribute.
  `Object`
  `getAttributeValue(NodeHandler<T> handler)`
  Gets the attribute value if this is an attribute result.
  `T`
  `getNode()`
  Gets the node referenced by this object.
  `int`
  `hashCode()`
  `boolean`
  `isAttributeResult()`
  Returns a flag whether this is a result of type attribute.
  `String`
  `toString()`
  Returns a string representation of this object.

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

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

- ## Method Details

  - ### createNodeResult

    public static <T> QueryResult<T> createNodeResult(T resultNode)
    Creates a `QueryResult` instance representing the specified result node.
    Type Parameters:
      `T` - the type of the result node
    Parameters:
      `resultNode` - the result node
    Returns:
      the newly created instance

  - ### createAttributeResult

    public static <T> QueryResult<T> createAttributeResult(T parentNode, String attrName)
    Creates a `QueryResult` instance representing an attribute result. An attribute result consists of the node the attribute belongs to and the attribute name. (The value can be obtained based on this information.)
    Type Parameters:
      `T` - the type of the parent node
    Parameters:
      `parentNode` - the node which owns the attribute
      `attrName` - the attribute name
    Returns:
      the newly created instance

  - ### getNode

    public T getNode()
    Gets the node referenced by this object. Depending on the result type, this is either the result node or the parent node of the represented attribute.
    Returns:
      the referenced node

  - ### getAttributeName

    public String getAttributeName()
    Gets the name of the attribute. This method is defined only for results of type attribute.
    Returns:
      the attribute name

  - ### isAttributeResult

    public boolean isAttributeResult()
    Returns a flag whether this is a result of type attribute. If result is true, the attribute name and value can be queried. Otherwise, only the result node is available.
    Returns:
      true for an attribute result, false otherwise

  - ### getAttributeValue

    public Object getAttributeValue(NodeHandler<T> handler)
    Gets the attribute value if this is an attribute result. If this is not an attribute result, an exception is thrown.
    Parameters:
      `handler` - the `NodeHandler`
    Returns:
      the attribute value
    Throws:
      `IllegalStateException` - if this is not an attribute result

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### equals

    public boolean equals(Object obj)
    Compares this object with another one. Two instances of `QueryResult` are considered equal if they are of the same result type and have the same properties.
    Overrides:
      `equals` in class `Object`
    Parameters:
      `obj` - the object to compare to
    Returns:
      a flag whether these objects are equal

  - ### toString

    public String toString()
    Returns a string representation of this object. Depending on the result type either the result node or the parent node and the attribute name are contained in this string.
    Overrides:
      `toString` in class `Object`
    Returns:
      a string for this object