00001
00005 package edu.mit.csail.sdg.squander.utils;
00006
00007 import java.util.Collection;
00008 import java.util.LinkedHashMap;
00009 import java.util.Map;
00010 import java.util.Set;
00011
00012 public class TwoWayMap<K, V> implements Map<K, V> {
00013 private Map<K, V> map = new LinkedHashMap<K, V>();
00014 private Map<V, K> inv = new LinkedHashMap<V, K>();
00015
00016 public void clear() {
00017 map.clear();
00018 inv.clear();
00019 }
00020
00021 public boolean containsKey(Object key) {
00022 return map.containsKey(key);
00023 }
00024
00025 public boolean containsValue(Object value) {
00026 return inv.containsKey(value);
00027 }
00028
00029 public Set<java.util.Map.Entry<K, V>> entrySet() {
00030 return map.entrySet();
00031 }
00032
00033 public boolean equals(Object o) {
00034 return map.equals(o);
00035 }
00036
00037 public V get(Object key) {
00038 return map.get(key);
00039 }
00040
00041 public K getKeyForValue(V value) {
00042 return inv.get(value);
00043 }
00044
00045 public int hashCode() {
00046 return map.hashCode();
00047 }
00048
00049 public boolean isEmpty() {
00050 return map.isEmpty();
00051 }
00052
00053 public Set<K> keySet() {
00054 return map.keySet();
00055 }
00056
00057 public V put(K key, V value) {
00058 V v = map.put(key, value);
00059 inv.put(value, key);
00060 return v;
00061 }
00062
00063 public void putAll(Map<? extends K, ? extends V> m) {
00064 for (Entry<? extends K, ? extends V> e : m.entrySet()) {
00065 put(e.getKey(), e.getValue());
00066 }
00067 }
00068
00069 public V remove(Object key) {
00070 V v = map.remove(key);
00071 if (v != null)
00072 inv.remove(v);
00073 return v;
00074 }
00075
00076 public int size() {
00077 return map.size();
00078 }
00079
00080 public Collection<V> values() {
00081 return map.values();
00082 }
00083
00084 }