All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.swisspush.reststorage.util.HttpRequestParam Maven / Gradle / Ivy

There is a newer version: 3.1.8
Show newest version
package org.swisspush.reststorage.util;

import io.vertx.core.MultiMap;

/**
 * Enum for HTTP request params used in vertx-rest-storage
 *
 * @author https://github.com/mcweba [Marc-Andre Weber]
 */
public enum HttpRequestParam {

    RECURSIVE_PARAMETER("recursive"),
    STORAGE_EXPAND_PARAMETER("storageExpand"),
    LIMIT_PARAMETER("limit"),
    OFFSET_PARAMETER("offset");

    private final String name;

    HttpRequestParam(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public static boolean containsParam(MultiMap params, HttpRequestParam httpRequestParam){
        if(params == null){
            return false;
        }
        return params.contains(httpRequestParam.getName());
    }

    /**
     * Get the value of the provided {@link HttpRequestParam} as String.
     * 

Returns null in the following cases:

* *
    *
  • params are null
  • *
  • params does not contain httpRequestParam
  • *
* * @param params the http request params * @param httpRequestParam the http request param to get the value from * @return a String representing the value of the httpRequestParam or null */ public static String getString(MultiMap params, HttpRequestParam httpRequestParam) { if(params == null) { return null; } return params.get(httpRequestParam.getName()); } /** * Get the value of the provided {@link HttpRequestParam} as boolean. *

Returns false in the following cases:

* *
    *
  • params are null
  • *
  • params does not contain httpRequestParam
  • *
  • value of httpRequestParam does not equal "true" ignoring the case
  • *
* * @param params the http request params * @param httpRequestParam the http request param to get the value from * @return a boolean representing the value of the httpRequestParam */ public static boolean getBoolean(MultiMap params, HttpRequestParam httpRequestParam) { if(params == null) { return false; } String paramValue = params.get(httpRequestParam.getName()); return "true".equalsIgnoreCase(paramValue); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy