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

io.sphere.sdk.http.FormUrlEncodedHttpRequestBody Maven / Gradle / Ivy

There is a newer version: 1.0.0-M26
Show newest version
package io.sphere.sdk.http;

import java.util.*;

import static java.util.Collections.unmodifiableList;

public class FormUrlEncodedHttpRequestBody extends Base implements HttpRequestBody {
    private final List data;

    private FormUrlEncodedHttpRequestBody(final List data) {
        this.data = unmodifiableList(new ArrayList<>(data));
    }

    public static FormUrlEncodedHttpRequestBody of(final List data) {
        return new FormUrlEncodedHttpRequestBody(data);
    }

    /**
     * Creator if the order does not matter and there are no duplicates.
     * @param data name value pairs for the body
     * @return FormUrlEncodedHttpRequestBody
     */
    public static FormUrlEncodedHttpRequestBody of(final Map data) {
        final List list = new ArrayList<>(data.size());
        data.forEach((key, value) -> list.add(NameValuePair.of(key, value)));
        return of(list);
    }

    /**
     * @return the unordered data without duplicate names
     * @deprecated use {@link #getParameters()} instead
     */
    @Deprecated
    public Map getData() {
        final Map map = new HashMap<>();
        getParameters().forEach(pair -> map.put(pair.getName(), pair.getValue()));
        return map;
    }

    public List getParameters() {
        return data;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy