Dart Documentationquiver.collectionMultimap<K, V>

Multimap<K, V> abstract class

An associative container that maps a key to multiple values.

Key lookups return mutable collections that are views of the multimap. Updates to the multimap are reflected in these collections and similarly, modifications to the returned collections are reflected in the multimap.

abstract class Multimap<K, V> {
 /**
  * Constructs a new list-backed multimap.
  */
 factory Multimap() => new ListMultimap<K, V>();

 /**
  * Returns whether this multimap contains the given [value].
  */
 bool containsValue(Object value);

 /**
  * Returns whether this multimap contains the given [key].
  */
 bool containsKey(Object key);

 /**
  * Returns the values for the given [key]. An empty iterable is returned if
  * [key] is not mapped. The returned collection is a view on the multimap.
  * Updates to the collection modify the multimap and likewise, modifications
  * to the multimap are reflected in the returned collection.
  */
 Iterable<V> operator [](Object key);

 /**
  * Adds an association from the given key to the given value.
  */
 void add(K key, V value);

 /**
  * Adds an association from the given key to each of the given values.
  */
  void addValues(K key, Iterable<V> values);

 /**
  * Adds all associations of [other] to this multimap.
  *
  * The operation is equivalent to doing `this[key] = value` for each key
  * and associated value in other. It iterates over [other], which must
  * therefore not change during the iteration.
  */
 void addAll(Multimap<K, V> other);

 /**
  * Removes the association between the given [key] and [value]. Returns
  * `true` if the association existed, `false` otherwise.
  */
 bool remove(Object key, V value);

 /**
  * Removes the association for the given [key]. Returns the collection of
  * removed values, or an empty iterable if [key] was unmapped.
  */
 Iterable<V> removeAll(Object key);

 /**
  * Removes all data from the multimap.
  */
 void clear();

 /**
  * Applies [f] to each {key, Iterable<value>} pair of the multimap.
  *
  * It is an error to add or remove keys from the map during iteration.
  */
 void forEachKey(void f(key, value));

 /**
  * Applies [f] to each {key, value} pair of the multimap.
  *
  * It is an error to add or remove keys from the map during iteration.
  */
 void forEach(void f(key, value));

 /**
  * The keys of [this].
  */
 Iterable<K> get keys;

 /**
  * The values of [this].
  */
 Iterable<V> get values;

 /**
  * Returns a copy of this multimap as a map.
  */
 Map<K, Iterable<V>> toMap();

 /**
  * The number of keys in the multimap.
  */
 int get length;

 /**
  * Returns true if there is no key in the multimap.
  */
 bool get isEmpty;

 /**
  * Returns true if there is at least one key in the multimap.
  */
 bool get isNotEmpty;
}

Constructors

factory Multimap() #

Constructs a new list-backed multimap.

factory Multimap() => new ListMultimap<K, V>();

Properties

final bool isEmpty #

Returns true if there is no key in the multimap.

bool get isEmpty;

final bool isNotEmpty #

Returns true if there is at least one key in the multimap.

bool get isNotEmpty;

final Iterable<K> keys #

The keys of this.

Iterable<K> get keys;

final int length #

The number of keys in the multimap.

int get length;

final Iterable<V> values #

The values of this.

Iterable<V> get values;

Operators

abstract Iterable<V> operator [](Object key) #

Returns the values for the given key. An empty iterable is returned if key is not mapped. The returned collection is a view on the multimap. Updates to the collection modify the multimap and likewise, modifications to the multimap are reflected in the returned collection.

Methods

abstract void add(K key, V value) #

Adds an association from the given key to the given value.

abstract void addAll(Multimap<K, V> other) #

Adds all associations of other to this multimap.

The operation is equivalent to doing this[key] = value for each key and associated value in other. It iterates over other, which must therefore not change during the iteration.

abstract void addValues(K key, Iterable<V> values) #

Adds an association from the given key to each of the given values.

abstract void clear() #

Removes all data from the multimap.

abstract bool containsKey(Object key) #

Returns whether this multimap contains the given key.

abstract bool containsValue(Object value) #

Returns whether this multimap contains the given value.

abstract void forEach(void f(key, value)) #

Applies f to each {key, value} pair of the multimap.

It is an error to add or remove keys from the map during iteration.

abstract void forEachKey(void f(key, value)) #

Applies f to each {key, Iterable<value>} pair of the multimap.

It is an error to add or remove keys from the map during iteration.

abstract bool remove(Object key, V value) #

Removes the association between the given key and value. Returns true if the association existed, false otherwise.

abstract Iterable<V> removeAll(Object key) #

Removes the association for the given key. Returns the collection of removed values, or an empty iterable if key was unmapped.

abstract Map<K, Iterable<V>> toMap() #

Returns a copy of this multimap as a map.