Package org.jppf.utils.collections
Class AbstractCollectionMap<K,V>
java.lang.Object
org.jppf.utils.collections.AbstractCollectionMap<K,V>
- Type Parameters:
K- the type of keys in the map.V- the type of values in the collections mapped to the keys.
- All Implemented Interfaces:
Serializable,Iterable<V>,CollectionMap<K,V>
- Direct Known Subclasses:
AbstractCollectionConcurrentMap,AbstractCollectionHashtable,AbstractCollectionSortedMap,ArrayListHashMap,EnumSetEnumMap,LinkedListHashMap,SetHashMap,SetIdentityMap
A map whose values are collections of a given component type.
- Author:
- Laurent Cohen
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Map<K,Collection<V>> The underlying map to which operations are delegated. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddValues(K key, Collection<V> values) Add the specified values to the specified key.voidAdd the specified values to the specified key.Get a collection of all the values for all keys.voidclear()Clear the map.booleancontainsKey(K key) Determine whether this map contains the specified key.booleancontainsValue(K key, V value) Determine whether the collection mapped to the specified key contains the specified value.booleancontainsValue(V value) Determine whether at least one of the collections in the map contains the specified value.protected abstract Map<K,Collection<V>> Create a new map.protected Collection<V>createOrGetCollection(K key) Get an exisitng collection for the specified key, or create it if it doesn't exist.protected Collection<V>Get an exisitng collection for the specified key, or create it if it doesn't exist.Set<Map.Entry<K,Collection<V>>> entrySet()Get the set map entries.Get the collection of values maped to the specified key.booleanisEmpty()Determine whether this map is empty.iterator()Get an iterator which uses the specified lock.keySet()Get the set of keys in the map.protected abstract Collection<V>Create a new collection of values for insertion into the map.voidAdd a value for the specified key.Remove the specified key from this map.booleanremoveValue(K key, V value) Remove a value from the specified key.intremoveValues(K key, V... values) Remove the specified values from the specified key.intsize()Get the total number of elements in this collection map.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jppf.utils.collections.CollectionMap
forEachMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
map
The underlying map to which operations are delegated.
-
-
Constructor Details
-
AbstractCollectionMap
public AbstractCollectionMap()Default constructor.
-
-
Method Details
-
putValue
Description copied from interface:CollectionMapAdd a value for the specified key.- Specified by:
putValuein interfaceCollectionMap<K,V> - Parameters:
key- the key for which to add a value.value- the value to add.
-
removeValue
Description copied from interface:CollectionMapRemove a value from the specified key.- Specified by:
removeValuein interfaceCollectionMap<K,V> - Parameters:
key- the key from which to remove a value.value- the value to remove.- Returns:
trueif an element was removed,falseotherwise.
-
addValues
Description copied from interface:CollectionMapAdd the specified values to the specified key. This is a bulk operation.- Specified by:
addValuesin interfaceCollectionMap<K,V> - Parameters:
key- the key to which to add the values.values- the values to add to the key.
-
addValues
Description copied from interface:CollectionMapAdd the specified values to the specified key. This is a bulk operation.- Specified by:
addValuesin interfaceCollectionMap<K,V> - Parameters:
key- the key to which to add the values.values- the values to add to the key.
-
removeValues
Description copied from interface:CollectionMapRemove the specified values from the specified key. This is a bulk operation.- Specified by:
removeValuesin interfaceCollectionMap<K,V> - Parameters:
key- the key for which to rmeove the values.values- the values to remove.- Returns:
- the number of values that were actually removed, possibly zero.
-
removeKey
Description copied from interface:CollectionMapRemove the specified key from this map.- Specified by:
removeKeyin interfaceCollectionMap<K,V> - Parameters:
key- the key to remove.- Returns:
- collection of values that were removed, possibly
null.
-
getValues
Description copied from interface:CollectionMapGet the collection of values maped to the specified key.- Specified by:
getValuesin interfaceCollectionMap<K,V> - Parameters:
key- the key to lookup.- Returns:
- a collection of values that mapped to the key, or
nullif no mapping exists for the key.
-
size
public int size()Description copied from interface:CollectionMapGet the total number of elements in this collection map. Note that the cost of thesize()operation will be in O(n).- Specified by:
sizein interfaceCollectionMap<K,V> - Returns:
- the number of elements as an int value.
-
isEmpty
public boolean isEmpty()Description copied from interface:CollectionMapDetermine whether this map is empty.- Specified by:
isEmptyin interfaceCollectionMap<K,V> - Returns:
trueif the map is empty,falseotherwise.
-
containsKey
Description copied from interface:CollectionMapDetermine whether this map contains the specified key.- Specified by:
containsKeyin interfaceCollectionMap<K,V> - Parameters:
key- the key to lookup.- Returns:
trueif there is a mapping for the key,falseotherwise.
-
containsValue
Description copied from interface:CollectionMapDetermine whether the collection mapped to the specified key contains the specified value.- Specified by:
containsValuein interfaceCollectionMap<K,V> - Parameters:
key- the key whose mapped collection is looked up^.value- the value to look in the collection.- Returns:
trueif the map contains the key and the corresponding collection contains the value,falseotehrwise.
-
containsValue
Description copied from interface:CollectionMapDetermine whether at least one of the collections in the map contains the specified value.- Specified by:
containsValuein interfaceCollectionMap<K,V> - Parameters:
value- the value to look up in the entire map.- Returns:
trueif the map contains the value,falseotehrwise.
-
iterator
-
iterator
Description copied from interface:CollectionMapGet an iterator which uses the specified lock.- Specified by:
iteratorin interfaceCollectionMap<K,V> - Parameters:
lock- the lock used to synchronize access to the map.- Returns:
- an iterator on the values of the map.
-
clear
public void clear()Description copied from interface:CollectionMapClear the map.- Specified by:
clearin interfaceCollectionMap<K,V>
-
createMap
Create a new map.- Returns:
- a new mutable empty map.
-
newCollection
Create a new collection of values for insertion into the map.- Returns:
- a new mutable empty collection.
-
toString
-
keySet
Description copied from interface:CollectionMapGet the set of keys in the map.- Specified by:
keySetin interfaceCollectionMap<K,V> - Returns:
- a
Setof all keys.
-
entrySet
Description copied from interface:CollectionMapGet the set map entries.- Specified by:
entrySetin interfaceCollectionMap<K,V> - Returns:
- a
Setof all map entries.
-
allValues
Description copied from interface:CollectionMapGet a collection of all the values for all keys.- Specified by:
allValuesin interfaceCollectionMap<K,V> - Returns:
- a collection of all values in this map.
-
createOrGetCollectionSynchronized
Get an exisitng collection for the specified key, or create it if it doesn't exist.- Parameters:
key- the key for which to get a collection of values.- Returns:
- a collection of value for the specified keys, may be empty if newly created.
-
createOrGetCollection
Get an exisitng collection for the specified key, or create it if it doesn't exist.- Parameters:
key- the key for which to get a collection of values.- Returns:
- a collection of value for the specified keys, may be empty if newly created.
-