org.mockserver.model.KeyToMultiValue Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockserver-core Show documentation
Show all versions of mockserver-core Show documentation
Functionality used by all MockServer modules for matching and expectations
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 extends KeyToMultiValue> 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