diff options
Diffstat (limited to 'src/com/android/camera/util/MultiMap.java')
-rw-r--r-- | src/com/android/camera/util/MultiMap.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/com/android/camera/util/MultiMap.java b/src/com/android/camera/util/MultiMap.java new file mode 100644 index 000000000..b2e9003fe --- /dev/null +++ b/src/com/android/camera/util/MultiMap.java @@ -0,0 +1,45 @@ +package com.android.camera.util; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class MultiMap<K,V> { + Map<K,List<V>> map = new HashMap<K,List<V>>(); + + public void put(K key, V value) { + List<V> l = map.get(key); + if(l == null) { + l = new ArrayList<V>(); + map.put(key, l); + } + l.add(value); + } + + public List<V> get(K key) { + List<V> l = map.get(key); + if(l == null) { return Collections.emptyList(); } + else return l; + } + + public List<V> remove(K key) { + List<V> l = map.remove(key); + if(l == null) { return Collections.emptyList(); } + else return l; + } + + public Set<K> keySet() { return map.keySet(); } + + public int size() { + int total = 0; + for(List<V> l : map.values()) { + total += l.size(); + } + return total; + } + + public boolean isEmpty() { return map.isEmpty(); } +}
\ No newline at end of file |