Package com.globalmentor.collections
Class AbstractDecoratorCollectionMap<K,V,C extends Collection<V>>
java.lang.Object
com.globalmentor.collections.MapDecorator<K,C>
com.globalmentor.collections.AbstractDecoratorCollectionMap<K,V,C>
- Type Parameters:
K
- The type of map key.V
- The type of map value.C
- The type of collection in which to store values in the map.
- All Implemented Interfaces:
CollectionMap<K,
,V, C> Map<K,
C>
- Direct Known Subclasses:
ArrayListMap
,CopyOnWriteArrayListConcurrentHashMap
,HashSetHashMap
,IdentityHashSetMap
,TreeSetMap
public abstract class AbstractDecoratorCollectionMap<K,V,C extends Collection<V>>
extends MapDecorator<K,C>
implements CollectionMap<K,V,C>
An abstract collection map that decorates an existing map.
- Author:
- Garret Wilson
- API Note:
- Child classes must implements
CollectionMap.createCollection()
and return the appropriate type of collection.
-
Nested Class Summary
-
Field Summary
Fields inherited from class com.globalmentor.collections.MapDecorator
map
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a value to the collection of values associated with the key.getCollection
(K key) Retrieves the collection of values associated with the given key.Retrieves the first value from the collection of values, if any, associated with the key.int
getItemCount
(K key) Retrieves the number of values in the collection, if any, associated with the key.Retrieves iterable access to all items, if any, associated with the given keyboolean
Retrieves whether there are items in a collection associated with the key.boolean
removeItem
(K key, V value) Removes the first occurence of the given value from the collection of values, if any, associated with the key.Methods inherited from class com.globalmentor.collections.MapDecorator
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.globalmentor.collections.CollectionMap
createCollection
Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Constructor Details
-
AbstractDecoratorCollectionMap
Map constructor.- Parameters:
map
- The map this map should decorate.- Throws:
NullPointerException
- if the provided map isnull
.
-
-
Method Details
-
getCollection
Description copied from interface:CollectionMap
Retrieves the collection of values associated with the given key. If no collection of values is associated with the key, one will be created and added to the map.- Specified by:
getCollection
in interfaceCollectionMap<K,
V, C extends Collection<V>> - Parameters:
key
- The key in the map.- Returns:
- The collection associated with the given key
- See Also:
-
hasItems
Description copied from interface:CollectionMap
Retrieves whether there are items in a collection associated with the key.- Specified by:
hasItems
in interfaceCollectionMap<K,
V, C extends Collection<V>> - Parameters:
key
- The key in the map.- Returns:
true
if there is at least one item associated with the key.
-
getItemCount
Description copied from interface:CollectionMap
Retrieves the number of values in the collection, if any, associated with the key.- Specified by:
getItemCount
in interfaceCollectionMap<K,
V, C extends Collection<V>> - Parameters:
key
- The key in the map.- Returns:
- The number of items associated with the key.
-
addItem
Description copied from interface:CollectionMap
Adds a value to the collection of values associated with the key. If no collection of values is associated with the key, one will be created and added to the map.- Specified by:
addItem
in interfaceCollectionMap<K,
V, C extends Collection<V>> - Parameters:
key
- The key in the map.value
- The value to store in the collection.
-
getItem
Description copied from interface:CollectionMap
Retrieves the first value from the collection of values, if any, associated with the key.- Specified by:
getItem
in interfaceCollectionMap<K,
V, C extends Collection<V>> - Parameters:
key
- The key in the map.- Returns:
- The first value in the collection, or
null
if there is no collection associated with the key or no values in the collection. - See Also:
-
getItems
Description copied from interface:CollectionMap
Retrieves iterable access to all items, if any, associated with the given key- Specified by:
getItems
in interfaceCollectionMap<K,
V, C extends Collection<V>> - Parameters:
key
- The key in the map.- Returns:
- An object that will iterate all items, if any, associated with the given key.
-
removeItem
Description copied from interface:CollectionMap
Removes the first occurence of the given value from the collection of values, if any, associated with the key. If all items from the collection are removed, the collection itself is removed from the map.- Specified by:
removeItem
in interfaceCollectionMap<K,
V, C extends Collection<V>> - Parameters:
key
- The key in the map.value
- The item to be removed from the collection, if present.- Returns:
true
if an item was removed as a result of this call.
-