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 ofExpressionEnginethe 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 ofExpressionEngineall 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, String attrName)Creates aQueryResultinstance representing an attribute result.static <T> QueryResult<T>createNodeResult(T resultNode)Creates aQueryResultinstance representing the specified result node.booleanequals(Object obj)Compares this object with another one.StringgetAttributeName()Gets the name of the attribute.ObjectgetAttributeValue(NodeHandler<T> handler)Gets the attribute value if this is an attribute result.TgetNode()Gets the node referenced by this object.inthashCode()booleanisAttributeResult()Returns a flag whether this is a result of type attribute.StringtoString()Returns a string representation of this object.
-
-
-
Method Detail
-
createNodeResult
public static <T> QueryResult<T> createNodeResult(T resultNode)
Creates aQueryResultinstance 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 aQueryResultinstance 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()
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- theNodeHandler- Returns:
- the attribute value
- Throws:
IllegalStateException- if this is not an attribute result
-
equals
public boolean equals(Object obj)
Compares this object with another one. Two instances ofQueryResultare considered equal if they are of the same result type and have the same properties.
-
-