com.talk2object.common.ListValueMap Maven / Gradle / Ivy
package com.talk2object.common;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class ListValueMap {
private Map> map;
public ListValueMap() {
map = new HashMap>();
}
public void add(K k, V v) {
List list = map.get(k);
if (list == null) {
list = new ArrayList();
map.put(k, list);
}
list.add(v);
}
public List get(K k) {
return map.get(k);
}
public V getFirstValue(K k) {
List list = map.get(k);
if (list != null && !list.isEmpty())
return list.get(0);
else
return null;
}
public void put(K k, V val) {
List list = new ArrayList();
list.add(val);
map.put(k, list);
}
public void put(K k, List list) {
map.put(k, list);
}
public Set keySet() {
return map.keySet();
}
public Map toSingleValueMap() {
Map result = new HashMap();
for (K k : keySet()) {
result.put(k, getFirstValue(k));
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy