org.jopendocument.util
Class CollectionMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap
          extended by org.apache.commons.collections.MultiHashMap
              extended by org.jopendocument.util.CollectionMap<K,V>
Type Parameters:
K - type of the keys
V - type of elements in collections
All Implemented Interfaces:
Serializable, Cloneable, Map, org.apache.commons.collections.MultiMap

public class CollectionMap<K,V>
extends org.apache.commons.collections.MultiHashMap

Une MultiMap qui permet de ne pas renvoyer null. De plus elle permet de choisir le type de Collection utilisé.

Author:
ILM Informatique 8 sept. 2004
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
CollectionMap()
          Une nouvelle map avec ArrayList comme collection.
CollectionMap(Class aCollectionClass)
          Une nouvelle map.
CollectionMap(Class aCollectionClass, int initialCapacity)
           
CollectionMap(Collection<V> collectionSpecimen)
           
CollectionMap(Collection<V> collectionSpecimen, int initialCapacity)
          A map that creates new collections by cloning collectionSpecimen.
CollectionMap(int initialCapacity)
          Une nouvelle map sans préciser le type de collection.
 
Method Summary
 Collection<V> createCollection(Collection coll)
           
 Set<Map.Entry<K,Collection<V>>> entrySet()
           
 Class getCollectionClass()
           
 Collection<V> getNonNull(K key)
          Renvoie la collection associée à la clef passée.
 Collection<V> getNull(K key)
          Just for the generics.
 Set<K> keySet()
           
 void merge(org.apache.commons.collections.MultiMap mm)
          Fusionne la MultiMap avec celle-ci.
 boolean putAll(K key, V... values)
           
 void putAll(Map mapToCopy)
          Copies all of the mappings from the specified map to this map.
 Collection<V> remove(Object key)
           
 void removeAll(CollectionMap<? extends K,? extends V> mm)
           
 void removeAll(Map<? extends K,? extends V> m)
           
static
<K,V> CollectionMap<K,V>
singleton(K key, Collection<V> values)
          Create a map with a single entry.
static
<K,V> CollectionMap<K,V>
singleton(K key, V... values)
           
static
<K,V> CollectionMap<K,V>
singleton(K key, V value)
           
 Collection<V> values()
           
 
Methods inherited from class org.apache.commons.collections.MultiHashMap
clear, clone, containsValue, containsValue, getCollection, iterator, put, putAll, remove, size, totalSize
 
Methods inherited from class java.util.HashMap
containsKey, get, isEmpty, size
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.commons.collections.MultiMap
get, size
 
Methods inherited from interface java.util.Map
containsKey, equals, hashCode, isEmpty
 

Constructor Detail

CollectionMap

public CollectionMap()
Une nouvelle map avec ArrayList comme collection.


CollectionMap

public CollectionMap(Class aCollectionClass)
Une nouvelle map. collectionClass doit descendre de Collection, et posséder un constructeur prenant une Collection (c'est le cas de la majorité des classes de java.util).

Parameters:
aCollectionClass - le type de collection utilisé.

CollectionMap

public CollectionMap(int initialCapacity)
Une nouvelle map sans préciser le type de collection. Dans ce cas si vous voulez spécifier une collection surchargez createCollection(Collection). Ce constructeur est donc utile pour des raisons de performances (évite la réflexion nécessaire avec les autres).

Parameters:
initialCapacity - the initial capacity.

CollectionMap

public CollectionMap(Class aCollectionClass,
                     int initialCapacity)

CollectionMap

public CollectionMap(Collection<V> collectionSpecimen)

CollectionMap

public CollectionMap(Collection<V> collectionSpecimen,
                     int initialCapacity)
A map that creates new collections by cloning collectionSpecimen. Allow one to customize an instance, contrary to the constructor which only takes a class.

Parameters:
collectionSpecimen - the collection from which to all others will be cloned.
initialCapacity - the initial capacity
Throws:
IllegalArgumentException - is not a Cloneable.
Method Detail

singleton

public static <K,V> CollectionMap<K,V> singleton(K key,
                                                 Collection<V> values)
Create a map with a single entry.

Type Parameters:
K - type of key.
V - type of items.
Parameters:
key - the single key.
values - the values for key.
Returns:
a map with one entry.

singleton

public static <K,V> CollectionMap<K,V> singleton(K key,
                                                 V... values)

singleton

public static <K,V> CollectionMap<K,V> singleton(K key,
                                                 V value)

getNonNull

public Collection<V> getNonNull(K key)
Renvoie la collection associée à la clef passée. Si la clef n'existe pas, renvoie une collection vide.

Parameters:
key - la clef.
Returns:
le collectionClass (par défaut ArrayList) associé à la clef passée.
See Also:
getCollectionClass()

getNull

public Collection<V> getNull(K key)
Just for the generics.

Parameters:
key - the key whose associated value is to be returned
Returns:
the value to which the specified key is mapped, or null if this map contains no mapping for the key.

createCollection

public Collection<V> createCollection(Collection coll)
Overrides:
createCollection in class org.apache.commons.collections.MultiHashMap

getCollectionClass

public Class getCollectionClass()

removeAll

public void removeAll(CollectionMap<? extends K,? extends V> mm)

removeAll

public void removeAll(Map<? extends K,? extends V> m)

merge

public void merge(org.apache.commons.collections.MultiMap mm)
Fusionne la MultiMap avec celle-ci. C'est à dire rajoute les valeurs de mm à la suite des valeurs de cette map (contrairement à putAll(Map) qui ajoute les valeurs de mm en tant que valeur scalaire et non en tant que collection).

Parameters:
mm - la MultiMap à fusionner.

putAll

public void putAll(Map mapToCopy)
Copies all of the mappings from the specified map to this map. This method is equivalent to MultiHashMap.MultiHashMap(Map). NOTE: cannot use Map since java complains (MultiHashMap not being generic).

Specified by:
putAll in interface Map
Overrides:
putAll in class HashMap
Parameters:
mapToCopy - mappings to be stored in this map

putAll

public boolean putAll(K key,
                      V... values)

entrySet

public Set<Map.Entry<K,Collection<V>>> entrySet()
Specified by:
entrySet in interface Map
Overrides:
entrySet in class HashMap

keySet

public Set<K> keySet()
Specified by:
keySet in interface Map
Overrides:
keySet in class HashMap

values

public Collection<V> values()
Specified by:
values in interface Map
Specified by:
values in interface org.apache.commons.collections.MultiMap
Overrides:
values in class org.apache.commons.collections.MultiHashMap

remove

public Collection<V> remove(Object key)
Specified by:
remove in interface Map
Specified by:
remove in interface org.apache.commons.collections.MultiMap
Overrides:
remove in class HashMap


Copyright © 2010 jOpenDocument All Rights Reserved.