![JAR search and dependency download from the Maven repository](/logo.png)
org.openfact.common.util.MultivaluedHashMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openfact-common Show documentation
Show all versions of openfact-common Show documentation
Common library and dependencies shared with server and all adapters
The newest version!
package org.openfact.common.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
public class MultivaluedHashMap extends HashMap>
{
public MultivaluedHashMap() {
}
public MultivaluedHashMap(MultivaluedHashMap config) {
addAll(config);
}
public void putSingle(K key, V value)
{
List list = new ArrayList();
list.add(value);
put(key, list);
}
public void addAll(K key, V... newValues)
{
for (V value : newValues)
{
add(key, value);
}
}
public void addAll(K key, List valueList)
{
for (V value : valueList)
{
add(key, value);
}
}
public void addFirst(K key, V value)
{
List list = get(key);
if (list == null)
{
add(key, value);
}
else
{
list.add(0, value);
}
}
public final void add(K key, V value)
{
getList(key).add(value);
}
public final void addMultiple(K key, Collection values)
{
getList(key).addAll(values);
}
public V getFirst(K key)
{
List list = get(key);
return list == null ? null : list.get(0);
}
public final List getList(K key)
{
List list = get(key);
if (list == null)
put(key, list = new ArrayList());
return list;
}
public void addAll(MultivaluedHashMap other)
{
for (Entry> entry : other.entrySet())
{
getList(entry.getKey()).addAll(entry.getValue());
}
}
public boolean equalsIgnoreValueOrder(MultivaluedHashMap omap) {
if (this == omap) {
return true;
}
if (!keySet().equals(omap.keySet())) {
return false;
}
for (Entry> e : entrySet()) {
List olist = omap.get(e.getKey());
if (e.getValue().size() != olist.size()) {
return false;
}
for (V v : e.getValue()) {
if (!olist.contains(v)) {
return false;
}
}
}
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy