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 org.mockserver.collections.CaseInsensitiveRegexMultiMap;

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

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

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

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

    public static CaseInsensitiveRegexMultiMap toMultiMap(List keyToMultiValues) {
        CaseInsensitiveRegexMultiMap caseInsensitiveRegexMultiMap = new CaseInsensitiveRegexMultiMap();
        if (keyToMultiValues != null) {
            for (KeyToMultiValue keyToMultiValue : keyToMultiValues) {
                for (String value : keyToMultiValue.getValues()) {
                    caseInsensitiveRegexMultiMap.put(keyToMultiValue.getName(), value);
                }
            }
        }
        return caseInsensitiveRegexMultiMap;
    }

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

    public String getName() {
        return name;
    }

    public List getValues() {
        return values;
    }

    public void addValue(String value) {
        if (values != null && !values.contains(value)) {
            values.add(value);
        }
    }

    public void addValues(List values) {
        if (this.values != null) {
            this.values.addAll(values);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy