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

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

There is a newer version: 2.16.0
Show newest version
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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy