Class QueryBuilder


  • public final class QueryBuilder
    extends Object

    Class which is responsible for constructing the query which should be sent to the API.

    Since:
    0.0.1
    • Method Detail

      • build

        public static String build​(Map<String,​Collection<?>> inputMap)

        Constructs a query which matches the format the API expects. This method performs two distinct steps:

        1. Filter out the null keys and values

        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.

        2. Construct the query

        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.

        Parameters:
        inputMap - the input map which contains the keys and the values for every key
        Returns:
        a string which can be sent as the payload to the API