Package com.globalmentor.collections
Interface CollectionMap<K,V,C extends java.util.Collection<V>>
-
- Type Parameters:
K
- The type of key used in the map.V
- The type of value stored in each collection in the map.C
- The type of collection in which to store values in the map.
- All Superinterfaces:
java.util.Map<K,C>
- All Known Subinterfaces:
ReadWriteLockCollectionMap<K,V,C>
- All Known Implementing Classes:
AbstractDecoratorCollectionMap
,ArrayListHashMap
,ArrayListMap
,CopyOnWriteArrayListConcurrentHashMap
,DecoratorReadWriteLockCollectionMap
,HashSetHashMap
,IdentityHashSetMap
,SynchronizedCollectionMapDecorator
,TreeSetMap
public interface CollectionMap<K,V,C extends java.util.Collection<V>> extends java.util.Map<K,C>
A map that stores a collection of values for each key, using a pair of read and write locks to access its data, with special methods for retrieving single values.- Author:
- Garret Wilson
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addItem(K key, V value)
Adds a value to the collection of values associated with the key.C
createCollection()
Creates a collection in which to store values.C
getCollection(K key)
Retrieves the collection of values associated with the given key.V
getItem(K 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.java.lang.Iterable<V>
getItems(K key)
Retrieves iterable access to all items, if any, associated with the given keyboolean
hasItems(K key)
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.
-
-
-
Method Detail
-
getCollection
C getCollection(K key)
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.- Parameters:
key
- The key in the map.- Returns:
- The collection associated with the given key
- See Also:
createCollection()
-
createCollection
C createCollection()
Creates a collection in which to store values.- Returns:
- The collections with the values stored.
-
hasItems
boolean hasItems(K key)
Retrieves whether there are items in a collection associated with the key.- Parameters:
key
- The key in the map.- Returns:
true
if there is at least one item associated with the key.
-
getItemCount
int getItemCount(K key)
Retrieves the number of values in the collection, if any, associated with the key.- Parameters:
key
- The key in the map.- Returns:
- The number of items associated with the key.
-
addItem
void addItem(K key, V value)
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.- Parameters:
key
- The key in the map.value
- The value to store in the collection.
-
getItem
V getItem(K key)
Retrieves the first value from the collection of values, if any, associated with the key.- 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:
getCollection(Object)
-
getItems
java.lang.Iterable<V> getItems(K key)
Retrieves iterable access to all items, if any, associated with the given key- Parameters:
key
- The key in the map.- Returns:
- An object that will iterate all items, if any, associated with the given key.
-
removeItem
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. If all items from the collection are removed, the collection itself is removed from the map.- 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.
-
-