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 java.lang.Object
A data class representing a single query result produced by an
ExpressionEngine
.When passing a key to the
query()
method ofExpressionEngine
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 ofExpressionEngine
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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> QueryResult<T>
createAttributeResult(T parentNode, java.lang.String attrName)
Creates aQueryResult
instance representing an attribute result.static <T> QueryResult<T>
createNodeResult(T resultNode)
Creates aQueryResult
instance representing the specified result node.boolean
equals(java.lang.Object obj)
Compares this object with another one.java.lang.String
getAttributeName()
Returns the name of the attribute.java.lang.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.java.lang.String
toString()
Returns a string representation of this object.
-
-
-
Method Detail
-
createNodeResult
public static <T> QueryResult<T> createNodeResult(T resultNode)
Creates aQueryResult
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, java.lang.String attrName)
Creates aQueryResult
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 attributeattrName
- 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 java.lang.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 java.lang.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
- theNodeHandler
- Returns:
- the attribute value
- Throws:
java.lang.IllegalStateException
- if this is not an attribute result
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
Compares this object with another one. Two instances ofQueryResult
are considered equal if they are of the same result type and have the same properties.- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- the object to compare to- Returns:
- a flag whether these objects are equal
-
toString
public java.lang.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 classjava.lang.Object
- Returns:
- a string for this object
-
-