io.sphere.sdk.http.NameValuePair Maven / Gradle / Ivy
package io.sphere.sdk.http;
import java.util.*;
public interface NameValuePair {
String getName();
String getValue();
static NameValuePair of(final String name, final String value) {
return new NameValuePairImpl(name, value);
}
static List convertStringMapToList(final Map data) {
final List list = new ArrayList<>(data.size());
data.forEach((key, value) -> list.add(NameValuePair.of(key, value)));
return Collections.unmodifiableList(list);
}
static List convertStringListMapToList(final Map> data) {
final List list = new LinkedList<>();
data.forEach((key, entriesList) -> {
entriesList.forEach(value -> {
list.add(NameValuePair.of(key, value));
});
});
return Collections.unmodifiableList(list);
}
static Map convertToStringMap(final List data) {
final Map map = new HashMap<>();
data.forEach(pair -> map.put(pair.getName(), pair.getValue()));
return Collections.unmodifiableMap(map);
}
static Map> convertToStringListMap(final List data) {
final Map> map = new HashMap<>();
data.forEach(pair -> {
final List headersForKey = map.computeIfAbsent(pair.getName(), name -> new LinkedList<>());
headersForKey.add(pair.getValue());
});
return Collections.unmodifiableMap(map);
}
}