Class Query
java.lang.Object
org.libxmq.Query
- Direct Known Subclasses:
QueryNetwork,QueryScientific
The Query class implemets the basic querying methods.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionFetches a single element from the xpath.voidexpect(String xpath, NodeCallback cb) Perform a single callback for a single node matching the xpath expression.intforEach(String xpath, NodeCallback cb) Perform a callback for each node matching the xpath expression.booleangetBoolean(String xpath) Get a boolean from an xpath location.doubleGet a 64 bit IEEE double floating point value from an xpath location and check that it complies with the restrictions.floatGet a 32 bit IEEE double floating point value from an xpath location and check that it complies with the restrictions.intGet a 32 bit signed integer from an xpath location and check that it complies with the restriction.longGet a 64 bit signed integer from an xpath location that complies with any restriction.getOptionalBoolean(String xpath) Get an optional boolean from an xpath location.getOptionalDouble(String xpath, String restriction) Get an optional 64 bit IEEE double floating point value from an xpath location and check that it complies with the restrictions.getOptionalFloat(String xpath, String restriction) Get an optional 32 bit IEEE double floating point value from an xpath location and check that it complies with the restrictions.getOptionalInt(String xpath, String restriction) Get an optional 32 bit signed integer from an xpath location and check that it complies with the restriction.getOptionalLong(String xpath, String restriction) Get an optional 64 bit signed integer from an xpath location that complies with any restriction.getOptionalString(String xpath, String restriction) Get an optional string from an xpath location that complies with a restriction.Get a string from an xpath location that complies with a restriction.protected XPathExpressiongetXPathExpression(String xpath) Fetch a potentially cached xpath expression.node()Return the node from which the query starts.optionalElement(String xpath) Fetches a single optional element from the xpath.Fetches a single element and wraps it inside a query from the xpath.
-
Constructor Details
-
Query
Build a new query from a DOM node.- Parameters:
node- The DOM node from which the paths start when querying.
-
-
Method Details
-
node
-
getXPathExpression
Fetch a potentially cached xpath expression.- Parameters:
xpath- The xpath to retrieve as an expression.- Returns:
- The compiled xpath expression.
- Throws:
XPathExpressionException- if the xpath is invalid.
-
forEach
Perform a callback for each node matching the xpath expression.- Parameters:
xpath- An xpath, for example: //bookcb- The callback function.- Returns:
- The number of nodes matched.
-
expect
Perform a single callback for a single node matching the xpath expression.- Parameters:
xpath- An xpath that is assumed to match only a single , for example: /librarycb- The callback function.- Throws:
NotFoundException- if the expected xpath was not found.
-
element
Fetches a single element from the xpath.- Parameters:
xpath- An xpath that is assumed to match only a single , for example: /library- Returns:
- The found element.
- Throws:
NotFoundException- if the expected xpath was not found.TooManyException- if more than one element matched the xpath.
-
optionalElement
Fetches a single optional element from the xpath.- Parameters:
xpath- An xpath that is assumed to match only a single , for example: /library- Returns:
- The found element.
- Throws:
TooManyException- if more than one element matched the xpath.
-
getBoolean
public boolean getBoolean(String xpath) throws DecodingException, NotFoundException, TooManyException Get a boolean from an xpath location. Two strings are valid 'true' and 'false'. Anything else will throw a DecodingException.- Parameters:
xpath- An xpath that is used to find the boolean.- Returns:
- The boolean.
- Throws:
NotFoundException- if the expected xpath was not found.DecodingException- if the value was not 'true' or 'false'.TooManyException- if more than one element matched the xpath.
-
getOptionalBoolean
public Optional<Boolean> getOptionalBoolean(String xpath) throws DecodingException, TooManyException Get an optional boolean from an xpath location. Two strings are valid 'true' and 'false'. Anything else will throw a DecodingException.- Parameters:
xpath- An xpath that finds the desired boolean.- Returns:
- The optional boolean.
- Throws:
DecodingException- if the value was not 'true' or 'false'.TooManyException- if more than one element matched the xpath.
-
getDouble
public double getDouble(String xpath, String restriction) throws DecodingException, NotFoundException, TooManyException Get a 64 bit IEEE double floating point value from an xpath location and check that it complies with the restrictions.- Parameters:
xpath- Fetch the value found using this xpath.restriction- The float can for example be restricted in range.- Returns:
- A double value.
- Throws:
NotFoundException- if the expected xpath was not found.DecodingException- if the value was not an integer or if it failed the restriction.TooManyException- if more than one element matched the xpath.
-
getOptionalDouble
public Optional<Double> getOptionalDouble(String xpath, String restriction) throws DecodingException, TooManyException Get an optional 64 bit IEEE double floating point value from an xpath location and check that it complies with the restrictions.- Parameters:
xpath- Fetch the value found using this xpath.restriction- The float can for example be restricted in range.- Returns:
- A double value.
- Throws:
DecodingException- if the value was not an integer or if it failed the restriction.TooManyException- if more than one element matched the xpath.
-
getFloat
public float getFloat(String xpath, String restriction) throws DecodingException, NotFoundException, TooManyException Get a 32 bit IEEE double floating point value from an xpath location and check that it complies with the restrictions.- Parameters:
xpath- Fetch the value found using this xpath.restriction- The float can for example be restricted in range.- Returns:
- The float found.
- Throws:
NotFoundException- if the expected xpath was not found.DecodingException- if the value was not an integer or if it failed the restriction.TooManyException- if more than one element matched the xpath.
-
getOptionalFloat
public Optional<Float> getOptionalFloat(String xpath, String restriction) throws DecodingException, TooManyException Get an optional 32 bit IEEE double floating point value from an xpath location and check that it complies with the restrictions.- Parameters:
xpath- Fetch the value found using this xpath.restriction- The float can for example be restricted in range.- Returns:
- The float found.
- Throws:
DecodingException- if the value was not an integer or if it failed the restriction.TooManyException- if more than one element matched the xpath.
-
getInt
public int getInt(String xpath, String restriction) throws DecodingException, NotFoundException, TooManyException Get a 32 bit signed integer from an xpath location and check that it complies with the restriction.- Parameters:
xpath- Fetch the value found using this xpath.restriction- The float can for example be restricted in range.- Returns:
- The integer.
- Throws:
NotFoundException- if the expected xpath was not found.DecodingException- if the value was not an integer or if it failed the restriction.TooManyException- if more than one element matched the xpath.
-
getOptionalInt
public Optional<Integer> getOptionalInt(String xpath, String restriction) throws DecodingException, TooManyException Get an optional 32 bit signed integer from an xpath location and check that it complies with the restriction.- Parameters:
xpath- Fetch the value found using this xpath.restriction- The float can for example be restricted in range.- Returns:
- The integer.
- Throws:
DecodingException- if the value was not an integer or if it failed the restriction.TooManyException- if more than one element matched the xpath.
-
getLong
public long getLong(String xpath, String restriction) throws DecodingException, NotFoundException, TooManyException Get a 64 bit signed integer from an xpath location that complies with any restriction.- Parameters:
xpath- Fetch the value found using this xpath.restriction- The float can for example be restricted in range.- Returns:
- The found long.
- Throws:
NotFoundException- if the expected xpath was not found.DecodingException- if the value was not a long integer or if it failed the restriction.TooManyException- if more than one element matched the xpath.
-
getOptionalLong
public Optional<Long> getOptionalLong(String xpath, String restriction) throws DecodingException, TooManyException Get an optional 64 bit signed integer from an xpath location that complies with any restriction.- Parameters:
xpath- Fetch the value found using this xpath.restriction- The float can for example be restricted in range.- Returns:
- The found long.
- Throws:
DecodingException- if the value was not a long integer or if it failed the restriction.TooManyException- if more than one element matched the xpath.
-
getString
public String getString(String xpath, String restriction) throws DecodingException, NotFoundException, TooManyException Get a string from an xpath location that complies with a restriction.- Parameters:
xpath- Fetch the value found using this xpath.restriction- The float can for example be restricted in range.- Returns:
- The found string.
- Throws:
NotFoundException- if the expected xpath was not found.DecodingException- if the value failed the restriction.TooManyException- if more than one element matched the xpath.
-
getOptionalString
public Optional<String> getOptionalString(String xpath, String restriction) throws DecodingException, TooManyException Get an optional string from an xpath location that complies with a restriction.- Parameters:
xpath- Fetch the value found using this xpath.restriction- The float can for example be restricted in range.- Returns:
- The found string.
- Throws:
DecodingException- if the value failed the restriction.TooManyException- if more than one element matched the xpath.
-
query
Fetches a single element and wraps it inside a query from the xpath.- Parameters:
xpath- An xpath that is assumed to match only a single , for example: /library- Returns:
- Query element.
- Throws:
NotFoundException- if the expected xpath was not found.TooManyException- if more than one element matched the xpath.
-