@Override public void add(K key, V value) { Collection<V> deltaC = deltaMap.get(key); if (deltaC == null) { deltaC = cf.newCollection(); Collection<V> originalC = originalMap.get(key); if (originalC != null) { deltaC.addAll(originalC); } deltaMap.put(key, deltaC); } deltaC.add(value); }
@Override public Collection<V> get(Object key) { // key could be not in original or in deltaMap // key could be not in original but in deltaMap // key could be in original but removed from deltaMap // key could be in original but mapped to something else in deltaMap Collection<V> deltaResult = deltaMap.get(key); if (deltaResult == null) { return originalMap.get(key); } if (deltaResult == removedValue) { return cf.newEmptyCollection(); } return deltaResult; }
@Override public void removeMapping(K key, V value) { Collection<V> deltaC = deltaMap.get(key); if (deltaC == null) { Collection<V> originalC = originalMap.get(key); if (originalC != null && originalC.contains(value)) { deltaC = cf.newCollection(); deltaC.addAll(originalC); deltaMap.put(key, deltaC); } } if (deltaC != null) { deltaC.remove(value); } }