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

org.mockserver.model.KeyToMultiValue Maven / Gradle / Ivy

There is a newer version: 5.15.0
Show newest version
package org.mockserver.model;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author jamesdbloom
 */
public class KeyToMultiValue extends ModelObject {
    private final String name;
    private final List values;

    public KeyToMultiValue(String name, String... values) {
        this(name, Arrays.asList(values));
    }

    public KeyToMultiValue(String name, List values) {
        this.name = name;
        if (values != null) {
            this.values = values;
        } else {
            this.values = new ArrayList();
        }
    }

    public static Multimap toMultiMap(List keyToMultiValues) {
        Multimap headersMap = HashMultimap.create();
        for (KeyToMultiValue keyToMultiValue : keyToMultiValues) {
            for (String value : keyToMultiValue.getValues()) {
                headersMap.put(keyToMultiValue.getName(), value);
            }
        }
        return headersMap;
    }

    public static Multimap toMultiMap(KeyToMultiValue... keyToMultiValues) {
        return toMultiMap(Arrays.asList(keyToMultiValues));
    }

    public String getName() {
        return name;
    }

    public List getValues() {
        return values;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy