@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; }
/** * Creates a new CollectionValuedMap. * * @param mf A MapFactory which will be used to generate the underlying Map * @param cf A CollectionFactory which will be used to generate the Collections * in each mapping * @param treatCollectionsAsImmutable If true, forces this Map to create new a Collection every time a * new value is added to or deleted from the Collection a mapping. * @param map An existing map to use rather than initializing one with mf. If this is non-null it is * used to initialize the map rather than mf. */ private CollectionValuedMap(MapFactory<K, Collection<V>> mf, CollectionFactory<V> cf, boolean treatCollectionsAsImmutable, Map<K, Collection<V>> map) { if (cf == null) { throw new IllegalArgumentException(); } if (mf == null && map == null) { throw new IllegalArgumentException(); } this.mf = mf; this.cf = cf; this.treatCollectionsAsImmutable = treatCollectionsAsImmutable; this.emptyValue = cf.newEmptyCollection(); if (map != null) { this.map = map; } else { this.map = Collections.synchronizedMap(mf.newMap()); } }
@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 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; }
/** * Creates a new empty CollectionValuedMap. * @param mf a MapFactory which will be used to generate the underlying Map * @param cf a CollectionFactory which will be used to generate the Collections in each mapping * @param treatCollectionsAsImmutable if true, forces this Map to create new a Collection everytime * a new value is added to or deleted from the Collection a mapping. */ public CollectionValuedMap(MapFactory<K, Collection<V>> mf, CollectionFactory<V> cf, boolean treatCollectionsAsImmutable) { this.mf = mf; this.cf = cf; this.treatCollectionsAsImmutable = treatCollectionsAsImmutable; this.emptyValue = cf.newEmptyCollection(); if (mf != null) { map = Collections.synchronizedMap(mf.newMap()); } }
/** * Creates a new empty CollectionValuedMap. * * @param mf * a MapFactory which will be used to generate the underlying Map * @param cf * a CollectionFactory which will be used to generate the Collections * in each mapping * @param treatCollectionsAsImmutable * if true, forces this Map to create new a Collection everytime a * new value is added to or deleted from the Collection a mapping. */ public CollectionValuedMap(MapFactory<K, Collection<V>> mf, CollectionFactory<V> cf, boolean treatCollectionsAsImmutable) { this.mf = mf; this.cf = cf; this.treatCollectionsAsImmutable = treatCollectionsAsImmutable; this.emptyValue = cf.newEmptyCollection(); if (mf != null) { map = Collections.synchronizedMap(mf.newMap()); } }
/** * Creates a new CollectionValuedMap. * * @param mf A MapFactory which will be used to generate the underlying Map * @param cf A CollectionFactory which will be used to generate the Collections * in each mapping * @param treatCollectionsAsImmutable If true, forces this Map to create new a Collection every time a * new value is added to or deleted from the Collection a mapping. * @param map An existing map to use rather than initializing one with mf. If this is non-null it is * used to initialize the map rather than mf. */ private CollectionValuedMap(MapFactory<K, Collection<V>> mf, CollectionFactory<V> cf, boolean treatCollectionsAsImmutable, Map<K, Collection<V>> map) { if (cf == null) { throw new IllegalArgumentException(); } if (mf == null && map == null) { throw new IllegalArgumentException(); } this.mf = mf; this.cf = cf; this.treatCollectionsAsImmutable = treatCollectionsAsImmutable; this.emptyValue = cf.newEmptyCollection(); if (map != null) { this.map = map; } else { this.map = Collections.synchronizedMap(mf.newMap()); } }
/** * Creates a new CollectionValuedMap. * * @param mf A MapFactory which will be used to generate the underlying Map * @param cf A CollectionFactory which will be used to generate the Collections * in each mapping * @param treatCollectionsAsImmutable If true, forces this Map to create new a Collection every time a * new value is added to or deleted from the Collection a mapping. * @param map An existing map to use rather than initializing one with mf. If this is non-null it is * used to initialize the map rather than mf. */ private CollectionValuedMap(MapFactory<K, Collection<V>> mf, CollectionFactory<V> cf, boolean treatCollectionsAsImmutable, Map<K, Collection<V>> map) { if (cf == null) { throw new IllegalArgumentException(); } if (mf == null && map == null) { throw new IllegalArgumentException(); } this.mf = mf; this.cf = cf; this.treatCollectionsAsImmutable = treatCollectionsAsImmutable; this.emptyValue = cf.newEmptyCollection(); if (map != null) { this.map = map; } else { this.map = Collections.synchronizedMap(mf.newMap()); } }