public final class QueryBuilder extends Object
Class which is responsible for constructing the query which should be sent to the API.
Modifier and Type | Method and Description |
---|---|
static String |
build(Map<String,Collection<?>> inputMap)
Constructs a query which matches the format the API expects.
|
public static String build(Map<String,Collection<?>> inputMap)
Constructs a query which matches the format the API expects. This method performs two distinct steps:
If a key (such as region or year) is defined and it's value is either defined as null or as an empty list, it means that all data for this key should be fetched (such as fetching the data for all available years). By not sending this key at all to the API it recognizes that it should respond with all data corresponding to this key.
For every key in the input map, it creates an entry for this key. It then writes all of the values corresponding with this key (defined somewhere by using the put-method on the input map) into this entry. For example, if the input for the key Tid (Swedish for year) contains the years (values) 2011 and 2012, the resulting entry looks like this:
{ "code": "Tid", "selection": { "filter": "item", "values": [ "2011", "2012" ] } }
The method works on the principle of pasting all these blocks together in an orderly fashion to conform to the API specification.
inputMap
- the input map which contains the keys and the values for every keyCopyright © 2018. All rights reserved.