io.sphere.sdk.http.FormUrlEncodedHttpRequestBody Maven / Gradle / Ivy
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;
}
}