public interface Query
Defines a Query for an API access fetch operation.
Typically, when accessing a data API, you send along some kind of query which contains a set of conditions or criteria for the stuff you want to fetch.
For instance, anApiAccess
object in this library has a fetch method
which accepts a Query as the sole argument.
A Query object is a holder of a set of parameters (Param objects).
Conequently, there is an addParam
method for Query objects
which you use while building up your Query in increments (stepwise).
The ApiAccess, for instance, will make use of the
method found in this interface, which will return a String representation of
the query and all its parameters. It's up to the implementing class to produce
a correct query string. A query string can be the GET parameters of a URL or
the WHERE clause of an SQL query SELECT, for instance.
toQueryString()
For convenience, this interface also declares a get(String key)
method
which will return the value of any parameter whose key matches the key parameter,
or null
if no such key is available in any of the Query's parameters.
It is up to the implementing class to implement this method in an efficient manner,
but one obvious way would be to hold a private Map of some sort for quick access
of the values from any parameter key. Note that a Map would only permit unique
keys, and if multiple keys are to be permitted (if the query would allow more than
one paramter to use the same key), a Map won't solve this, unless you use a Map
of String keys and values that are always a list.
Modifier and Type | Method and Description |
---|---|
void |
addParam(Param param)
Adds a
Param object to this Query. |
String |
get(String key)
Returns the value (as a
String ) of the parameter whose key is the key
provided by the key argument. |
String |
toQueryString()
|
void addParam(Param param)
Param
object to this Query.param
- The Param object to be addedString toQueryString()
String get(String key)
String
) of the parameter whose key is the key
provided by the key argument.key
- The key to the parameter whose value is requestednull
if no parameter has a matching key