Implementation of Multimap that uses an ArrayList to store the items for a given key. A HashMap associates each key with an ArrayList of items.

When iterating through the collections supplied by this class, the ordering of items for a given key agrees with the order in which the items were added.

This multimap allows duplicate key-item pairs. After adding a new key-item pair equal to an existing key-item pair, the ArrayListMultimap will contain entries for both the new item and the old item.

no subtypes hierarchy

Constructors
ArrayListMultimapSource Codeshared ArrayListMultimap(Stability keyStability = ..., {<Key->Item>*} entries = [])
Parameters:
  • keyStability = linked

    Determines whether a linked hash map with a stable iteration order will be used for this multimap's keys, defaulting to linked (stable).

  • entries = []
Attributes
asMapSource Codeshared actual Map<Key,MutableList<Item>> asMap

Returns a view of this multimap as a Map from each distinct key to the nonempty collection of that key's associated values. Note that this.asMap.get(k) is equivalent to this.get(k) only when k is a key contained in the multimap; otherwise it returns null as opposed to an empty collection.

The returned map is a view of the underlying multimap.

Refines MutableListMultimap.asMap ultimately refines Multimap.asMap
hashSource Codeshared actual Integer hash

The hash value of the value, which allows the value to be an element of a hash-based set or key of a hash-based map. Implementations must respect the constraint that:

  • if x==y then x.hash==y.hash.

Therefore, a class which refines equals must also refine hash.

In general, hash values vary between platforms and between executions of the same program.

Note that when executing on a Java Virtual Machine, the 64-bit Integer value returned by an implementation of hash is truncated to a 32-bit integer value by removal of the 32 highest order bits, before returning the value to the caller.

Refines Identifiable.hash ultimately refines Object.hash
itemsSource Codeshared actual Collection<Item> items

Returns a view collection containing the item from each key-item pair contained in this multimap, without collapsing duplicates (so items.size == size).

keysSource Codeshared actual MutableSet<Key> keys

The Category of all keys for which a value is defined by this Correspondence.

Refines MutableListMultimap.keys ultimately refines Correspondence.keys
sizeSource Codeshared actual Integer size

The number of elements returned by the iterator of this stream, if the iterator terminates. In the case of an infinite stream, this operation never terminates.

Refines Multimap.size ultimately refines Iterable.size
Inherited Attributes
Attributes inherited from: Object
hash, string
Attributes inherited from: Collection<Element>
empty, permutations, string
Attributes inherited from: Correspondence<Key,Item>
keys
Attributes inherited from: Iterable<Element,Absent>
coalesced, cycled, distinct, empty, exceptLast, first, indexed, last, paired, rest, size, string
Attributes inherited from: ListMultimap<Key,Item>
Attributes inherited from: ListMultimapMutator<Key,Item>
Attributes inherited from: Multimap<Key,Item>
Attributes inherited from: MultimapMutator<Key,Item>
Attributes inherited from: MutableListMultimap<Key,Item>
Attributes inherited from: MutableMultimap<Key,Item>
Methods
clearSource Codeshared actual void clear()

Removes all key->item pairs from the multimap, leaving it Multimap.empty.

Refines MutableMultimap.clear ultimately refines MultimapMutator.clear
cloneSource Codeshared actual ListMultimap<Key,Item> clone()

A shallow copy of this collection, that is, a collection with identical elements which does not change if this collection changes. If this collection is immutable, it is acceptable to return a reference to this collection. If this collection is mutable, a newly instantiated collection must be returned.

Refines ListMultimap.clone ultimately refines Collection.clone
definesSource Codeshared actual Boolean defines(Key key)

Determines if there is a value defined for the given key.

Refines Multimap.defines ultimately refines Correspondence.defines
equalsSource Codeshared actual Boolean equals(Object that)

Determine if two values are equal. Implementations should respect the constraints that:

  • if x===y then x==y (reflexivity),
  • if x==y then y==x (symmetry),
  • if x==y and y==z then x==z (transitivity).

Furthermore it is recommended that implementations ensure that if x==y then x and y have the same concrete class.

A class which explicitly refines equals() is said to support value equality, and the equality operator == is considered much more meaningful for such classes than for a class which simply inherits the default implementation of identity equality from Identifiable.

Note that an implementation of equals() that always returns false does satisfy the constraints given above. Therefore, in very rare cases where there is no reasonable definition of value equality for a class, for example, function references (Callable), it is acceptable for equals() to be defined to return false for every argument.

Refines Identifiable.equals ultimately refines Object.equals
getSource Codeshared actual MutableList<Item> get(Key key)

Returns the value defined for the given key, or null if there is no value defined for the given key.

Refines MutableListMultimap.get ultimately refines Correspondence.get
iteratorSource Codeshared actual Iterator<Key->Item> iterator()

An iterator for the elements belonging to this stream.

Refines Multimap.iterator ultimately refines Iterable.iterator
putSource Codeshared actual Boolean put(Key key, Item item)

Stores a key->item pair in this multimap.

Some multimap implementations allow duplicate key->item pairs, in which case put always adds a new key->item pair and increases the multimap size by 1. Other implementations prohibit duplicates, and storing a key->item pair that's already in the multimap has no effect.

Returns true if the method increased the size of the multimap, or false if the multimap already contained the key->item pair and doesn't allow duplicates

Refines MutableMultimap.put ultimately refines MultimapMutator.put
removeAllSource Codeshared actual List<Item> removeAll(Key key)

Removes all items associated with the key key.

Once this method returns, key will not be mapped to any items, so it will not appear in keys, asMap, or any other views.

Returns the items that were removed (possibly empty). The returned collection may be modifiable, but updating it will have no effect on the multimap.

replaceItemsSource Codeshared actual List<Item> replaceItems(Key key, {Item*} items)

Stores a collection of items with the same key, replacing any existing items for that key.

If items is empty, this is equivalent to removeAll(key).

Returns the collection of replaced items, or an empty collection if no items were previously associated with the key. The collection may be modifiable, but updating it will have no effect on the multimap.

Inherited Methods
Methods inherited from: Object
equals
Methods inherited from: Category<Element>
contains, containsAny, containsEvery
Methods inherited from: Collection<Element>
clone, contains
Methods inherited from: Correspondence<Key,Item>
defines, definesAny, definesEvery, get, getAll
Methods inherited from: Iterable<Element,Absent>
any, by, chain, collect, contains, count, defaultNullElements, each, every, filter, find, findLast, flatMap, fold, follow, frequencies, getFromFirst, group, indexes, interpose, iterator, locate, locateLast, locations, longerThan, map, max, narrow, partition, product, reduce, repeat, scan, select, sequence, shorterThan, skip, skipWhile, sort, spread, summarize, tabulate, take, takeWhile
Methods inherited from: ListMultimap<Key,Item>
Methods inherited from: ListMultimapMutator<Key,Item>
Methods inherited from: Multimap<Key,Item>
Methods inherited from: MultimapMutator<Key,Item>
Methods inherited from: MutableListMultimap<Key,Item>
Methods inherited from: MutableMultimap<Key,Item>