public class QueryBuilder extends Object
Modifier and Type | Method and Description |
---|---|
String |
build(Map<String,Collection<?>> inputMap)
Constructs a query which matches the format the SCB API expects.
|
static QueryBuilder |
getInstance()
Get the instance of this class.
|
public static QueryBuilder getInstance()
public String build(Map<String,Collection<?>> inputMap)
Constructs a query which matches the format the SCB API expects. This method performs two distinct steps:
If a key (such as region or year) is defined and all of this key's values are defined as null 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 SCB 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 SCB API specification.
inputMap
- the input map which contains the keys and the values for every keyCopyright © 2016. All rights reserved.