K - key typeI - item typeC - Collection subclass used to collect itemspublic class CollectionMap<K,I,C extends Collection<I>> extends LinkedHashMap<K,C>
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>| Constructor and Description |
|---|
CollectionMap(C emptySet)
Initializes the map by providing an instance of the empty collection
|
| Modifier and Type | Method and Description |
|---|---|
CollectionMap<K,I,C> |
clone() |
boolean |
containsItem(I item)
Checks if there are some collections that contain the given item
|
CollectionMap<K,I,C> |
empty()
Generates an empty
CollectionMap instance with the same
collection type for values |
static void |
main(String[] args)
Test procedure
|
void |
makeAllCollectionsUnmodifiable()
Makes all collections read-only
|
void |
mapValueToKeys(Map<I,K> map)
Populates the current instance with the data from another map.
|
static <KX,IX,CX extends Collection<IX>,EX extends CX> |
newCollectionMap(EX emptySet)
Generates a new
CollectionMap instance. |
C |
putAllItems(K key,
Collection<? extends I> c)
Adds a collection of items to the collection corresponding to the given key
|
C |
putItem(K key,
I item)
Adds an item to the collection corresponding to the given key
|
C |
removeAllItems(K key,
Collection<? extends I> c)
Removes a collection of items from the collection corresponding to the given key
|
C |
removeItem(K key,
I item)
Removes the item from the collection corresponding to the given key
|
clear, containsValue, get, removeEldestEntrycontainsKey, entrySet, isEmpty, keySet, put, putAll, remove, size, valuesequals, hashCode, toStringpublic CollectionMap(C emptySet)
emptySet - the empty collectionpublic CollectionMap<K,I,C> clone()
public CollectionMap<K,I,C> empty()
CollectionMap instance with the same
collection type for valuesCollectionMap instancepublic static <KX,IX,CX extends Collection<IX>,EX extends CX> CollectionMap<KX,IX,CX> newCollectionMap(EX emptySet)
CollectionMap instance. It is an alternative to
the constructor CollectionMap(Collection) that reduces the code
to write.KX - key typeIX - item typeCX - Collection subclass used to collect itemsEX - empty subset typeemptySet - the empty collectionCollectionMappublic void mapValueToKeys(Map<I,K> map)
map - the input mappublic boolean containsItem(I item)
item - item to checktrue if the item exists within some collectionspublic C putItem(K key, I item)
key - the key for the identification of the collectionitem - item to addpublic C putAllItems(K key, Collection<? extends I> c)
key - the key for the identification of the collectionc - items to addpublic C removeItem(K key, I item)
key - the key for the identification of the collectionitem - item to removepublic C removeAllItems(K key, Collection<? extends I> c)
key - the key for the identification of the collectionc - items to removepublic void makeAllCollectionsUnmodifiable()
public static void main(String[] args)
Expected output:
{}
{A=[1]}
{A=[1, 2]}
{A=[1, 2], B=[3]}
{A=[1, 2], B=[3, 4, 5, 6]}
true
true
false
{A=[1], B=[3, 4, 5, 6]}
{A=[1], B=[3, 4, 5, 6]}
{A=[1], B=[6]}
args - Copyright © 2016. All rights reserved.