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

- - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and 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()` Returns the name of the attribute.
    `Object` | `getAttributeValue(NodeHandler<T> handler)` Returns the attribute value if this is an attribute result.
    `T` | `getNode()` Returns 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 Detail

    - #### 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()

      Returns 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()

      Returns 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)

      Returns 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

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