package edu.kit.ipd.crowdcontrol.objectservice.rest;

import edu.kit.ipd.crowdcontrol.objectservice.rest.exceptions.BadRequestException;
import edu.kit.ipd.crowdcontrol.objectservice.rest.exceptions.InternalServerErrorException;
import spark.Request;

public class RequestUtil {
    private RequestUtil() {
        // utility class
    }

    public static int getParamInt(Request request, String param) {
        String paramValue = request.params(param);

        if (paramValue == null) {
            throw new InternalServerErrorException("Expected parameter '%s' not present.", param);
        }

        try {
            return Integer.parseInt(paramValue);
        } catch (NumberFormatException e) {
            throw new BadRequestException("Parameter '%s' must be a valid integer, '%s' given.", param, paramValue);
        }
    }

    public static int getQueryInt(Request request, String param, int defaultValue) {
        String paramValue = request.queryParams(param);

        if (paramValue == null) {
            return defaultValue;
        }

        try {
            return Integer.parseInt(paramValue);
        } catch (NumberFormatException e) {
            throw new BadRequestException("Query parameter '%s' must be a valid integer, '%s' given.", param, paramValue);
        }
    }

    public static boolean getQueryBool(Request request, String param, boolean defaultValue) {
        String paramValue = request.queryParams(param);

        if (paramValue == null) {
            return defaultValue;
        }

        switch(paramValue.toLowerCase()) {
            case "1":
            case "true":
                return true;
            case "0":
            case "false":
                return false;
            default:
                throw new BadRequestException("Query parameter '%s' must be a valid boolean, '%s' given. Use true / 1 / false / 0.", param, paramValue);
        }
    }
}

@@ -324,32 +324,534 @@
 ty class%0A    %7D%0A%0A
+    /**%0A     * Parses a parameter from the URL to an integer.%0A     *%0A     * @param request request provided by Spark%0A     * @param param   parameter name%0A     *%0A     * @return Parameter value as an integer.%0A     *%0A     * @throws InternalServerErrorException If the specified parameter was not contained in the URL.%0A     *                                      This is always an implementation error.%0A     * @throws BadRequestException          If the parameter can't be converted to an integer.%0A     */%0A
     public stati
@@ -1346,470 +1346,1405 @@
     
-public static int getQueryInt(Request request, String param, int defaultValue) %7B%0A        String paramValue = request.queryParams(param);%0A%0A        if (paramValue == null) %7B%0A            return defaultValue;%0A        %7D%0A%0A        try %7B%0A            return Integer.parseInt(paramValue);%0A        %7D catch (NumberFormatException e) %7B%0A            throw new BadRequestException(%22Query parameter '%25s' must be a valid integer, '%25s' given.%22, param, paramValue);%0A        %7D%0A    %7D%0A
+/**%0A     * Parses a query string parameter to an integer or uses the default value if the parameter is%0A     * not provided.%0A     *%0A     * @param request      request provided by Spark%0A     * @param param        query parameter name%0A     * @param defaultValue default value to use when parameter is not present%0A     *%0A     * @return Parsed integer or default value.%0A     *%0A     * @throws BadRequestException If parameter is present but not a valid integer.%0A     */%0A    public static int getQueryInt(Request request, String param, int defaultValue) %7B%0A        String paramValue = request.queryParams(param);%0A%0A        if (paramValue == null) %7B%0A            return defaultValue;%0A        %7D%0A%0A        try %7B%0A            return Integer.parseInt(paramValue);%0A        %7D catch (NumberFormatException e) %7B%0A            throw new BadRequestException(%22Query parameter '%25s' must be a valid integer, '%25s' given.%22, param, paramValue);%0A        %7D%0A    %7D%0A%0A    /**%0A     * Parses a query string parameter to a boolean or uses the default value if the parameter is%0A     * not provided.%0A     *%0A     * @param request      request provided by Spark%0A     * @param param        query parameter name%0A     * @param defaultValue default value to use when parameter is not present%0A     *%0A     * @return Parsed boolean or default value.%0A     *%0A     * @throws BadRequestException If parameter is present but not a valid boolean.%0A     */
 %0A   
@@ -2983,16 +2983,17 @@
   switch
+ 
 (paramVa
@@ -3035,16 +3035,45 @@
 se %221%22:%0A
+                return true;%0A
         
@@ -3140,16 +3140,46 @@
 se %220%22:%0A
+                return false;%0A
         

Add documentation for RequestUtil, duplicate entries in switch