Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## edu.stanford.nlp.util
Class CollectionValuedMap<K,V>

    java.lang.Object
      edu.stanford.nlp.util.CollectionValuedMap<K,V>

Type Parameters:
  `K` - Key type of map
  `V` - Type of the Collection that is the Map's value

All Implemented Interfaces:
  Serializable, Map<K,Collection<V>>

Direct Known Subclasses:
  DeltaCollectionValuedMap

    public class CollectionValuedMap<K,V>

extends Object
implements Map<K,Collection<V>>, Serializable

Map from keys to `Collection`s. Important methods are the `add(K, V)` and `remove(java.lang.Object)` methods for adding and removing a value to/from the Collection associated with the key, and the `get(java.lang.Object)` method for getting the Collection associated with a key. The class is quite general, because on construction, it is possible to pass a `MapFactory` which will be used to create the underlying map and a `CollectionFactory` which will be used to create the Collections. Thus this class can be configured to act like a "HashSetValuedMap" or a "ListValuedMap", or even a "HashSetValuedIdentityHashMap". The possibilities are endless!

Author:
  Teg Grenager (grenager@cs.stanford.edu), Sarah Spikes (sdspikes@cs.stanford.edu) - cleanup and filling in types
See Also:
  Serialized Form

Nested Class Summary

Nested classes/interfaces inherited from interface java.util.Map
`Map.Entry<K,V>`

Field Summary
`protected CollectionFactory<V>` | `cf`
`protected MapFactory<K,Collection<V>>` | `mf`

Constructor Summary
`CollectionValuedMap()` Creates a new empty CollectionValuedMap which uses a HashMap as the underlying Map, and HashSets as the Collections in each mapping.
`CollectionValuedMap(CollectionFactory<V> cf)` Creates a new empty CollectionValuedMap which uses a HashMap as the underlying Map.
`CollectionValuedMap(CollectionValuedMap<K,V> cvm)` Creates a new CollectionValuedMap with all of the mappings from cvm.
`CollectionValuedMap(MapFactory<K,Collection<V>> mf, CollectionFactory<V> cf, boolean treatCollectionsAsImmutable)` Creates a new empty CollectionValuedMap.

Method Summary
`void` | `add(K key, V value)` Adds the value to the Collection mapped to by the key.
`void` | `addAll(Map<K,V> m)` Adds all of the mappings in m to this CollectionValuedMap.
`Collection<V>` | `allValues()`
`void` | `clear()` Clears this Map.
`CollectionValuedMap<K,V>` | `clone()`
`boolean` | `containsKey(Object key)`
`boolean` | `containsValue(Object value)` Unsupported.
`CollectionValuedMap<K,V>` | `deltaClone()` Creates a "delta clone" of this Map, where only the differences are represented.
`Set<Map.Entry<K,Collection<V>>>` | `entrySet()` Each element of the Set is a Map.Entry object, where getKey() returns the key of the mapping, and getValue() returns the Collection mapped to by the key.
`boolean` | `equals(Object o)`
`Collection<V>` | `get(Object key)`
`int` | `hashCode()`
`boolean` | `isEmpty()`
`Set<K>` | `keySet()`
`static void` | `main(String[] args)` For testing only.
`Collection<V>` | `put(K key, Collection<V> collection)` Replaces current Collection mapped to key with the specified Collection.
`void` | `putAll(Map<? extends K,? extends Collection<V>> m)` Unsupported.
`Collection<V>` | `remove(Object key)` Removes the mapping associated with this key from this Map.
`void` | `removeMapping(K key, V value)` Removes the value from the Collection mapped to by this key, leaving the rest of the collection intact.
`int` | `size()` The number of keys in this map.
`String` | `toString()`
`Collection<Collection<V>>` | `values()` Unsupported.

Methods inherited from class java.lang.Object
`finalize, getClass, notify, notifyAll, wait, wait, wait`

Field Detail

### cf

    protected CollectionFactory<V> cf

### mf

    protected MapFactory<K,Collection<V>> mf

Constructor Detail

### CollectionValuedMap

    public CollectionValuedMap(MapFactory<K,Collection<V>> mf,
                               CollectionFactory<V> cf,
                               boolean treatCollectionsAsImmutable)

  Creates a new empty CollectionValuedMap.

  Parameters:
    `mf` - a MapFactory which will be used to generate the underlying Map
    `cf` - a CollectionFactory which will be used to generate the Collections in each mapping
    `treatCollectionsAsImmutable` - if true, forces this Map to create new a Collection everytime a new value is added to or deleted from the Collection a mapping.

### CollectionValuedMap

    public CollectionValuedMap(CollectionValuedMap<K,V> cvm)

  Creates a new CollectionValuedMap with all of the mappings from cvm. Same as `clone()`.

### CollectionValuedMap

    public CollectionValuedMap()

  Creates a new empty CollectionValuedMap which uses a HashMap as the underlying Map, and HashSets as the Collections in each mapping. Does not treat Collections as immutable.

### CollectionValuedMap

    public CollectionValuedMap(CollectionFactory<V> cf)

  Creates a new empty CollectionValuedMap which uses a HashMap as the underlying Map. Does not treat Collections as immutable.

  Parameters:
    `cf` - a CollectionFactory which will be used to generate the Collections in each mapping

Method Detail

### put

    public Collection<V> put(K key,
                             Collection<V> collection)

  Replaces current Collection mapped to key with the specified Collection. Use carefully!

  Specified by:
    `put` in interface `Map<K,Collection<V>>`

### putAll

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

  Unsupported. Use `addAll(Map)` instead.

  Specified by:
    `putAll` in interface `Map<K,Collection<V>>`

### get

    public Collection<V> get(Object key)

  Specified by:
    `get` in interface `Map<K,Collection<V>>`
  Returns:
    the Collection mapped to by key, never null, but may be empty.

### add

    public void add(K key,
                    V value)

  Adds the value to the Collection mapped to by the key.

### addAll

    public void addAll(Map<K,V> m)

  Adds all of the mappings in m to this CollectionValuedMap. If m is a CollectionValuedMap, it will behave strangely. Use the constructor instead.

### remove

    public Collection<V> remove(Object key)

  Removes the mapping associated with this key from this Map.

  Specified by:
    `remove` in interface `Map<K,Collection<V>>`
  Returns:
    the Collection mapped to by this key.

### removeMapping

    public void removeMapping(K key,
                              V value)

  Removes the value from the Collection mapped to by this key, leaving the rest of the collection intact.

  Parameters:
    `key` - the key to the Collection to remove the value from
    `value` - the value to remove

### clear

    public void clear()

  Clears this Map.

  Specified by:
    `clear` in interface `Map<K,Collection<V>>`

### containsKey

    public boolean containsKey(Object key)

  Specified by:
    `containsKey` in interface `Map<K,Collection<V>>`
  Returns:
    true iff this key is in this map

### containsValue

    public boolean containsValue(Object value)

  Unsupported.

  Specified by:
    `containsValue` in interface `Map<K,Collection<V>>`

### isEmpty

    public boolean isEmpty()

  Specified by:
    `isEmpty` in interface `Map<K,Collection<V>>`
  Returns:
    true iff this Map has no mappings in it.

### entrySet

    public Set<Map.Entry<K,Collection<V>>> entrySet()

  Each element of the Set is a Map.Entry object, where getKey() returns the key of the mapping, and getValue() returns the Collection mapped to by the key.

  Specified by:
    `entrySet` in interface `Map<K,Collection<V>>`
  Returns:
    a Set view of the mappings contained in this map.

### keySet

    public Set<K> keySet()

  Specified by:
    `keySet` in interface `Map<K,Collection<V>>`
  Returns:
    a Set view of the keys in this Map.

### size

    public int size()

  The number of keys in this map.

  Specified by:
    `size` in interface `Map<K,Collection<V>>`

### values

    public Collection<Collection<V>> values()

  Unsupported.

  Specified by:
    `values` in interface `Map<K,Collection<V>>`

### allValues

    public Collection<V> allValues()

### equals

    public boolean equals(Object o)

  Specified by:
    `equals` in interface `Map<K,Collection<V>>`
  Overrides:
    `equals` in class `Object`
  Returns:
    true iff o is a CollectionValuedMap, and each key maps to the a Collection of the same objects in o as it does in this CollectionValuedMap.

### hashCode

    public int hashCode()

  Specified by:
    `hashCode` in interface `Map<K,Collection<V>>`
  Overrides:
    `hashCode` in class `Object`
  Returns:
    the hashcode of the underlying Map

### deltaClone

    public CollectionValuedMap<K,V> deltaClone()

  Creates a "delta clone" of this Map, where only the differences are represented.

### clone

    public CollectionValuedMap<K,V> clone()

  Overrides:
    `clone` in class `Object`
  Returns:
    a clone of this Map

### toString

    public String toString()

  Overrides:
    `toString` in class `Object`
  Returns:
    A String representation of this CollectionValuedMap, with special machinery to avoid recursion problems

### main

    public static void main(String[] args)

  For testing only.

  Parameters:
    `args` - from command line

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Stanford NLP Group