Synchronize the specified
EventList to a MultiMap that is
returned from this method. Each time the
EventList is changed
the MultiMap is updated to reflect the change.
This can be useful when it is known that an EventList
will experience very few mutations compared to read operation and wants
to provide a data structure that guarantees fast O(1) reads.
The keys of the MultiMap are determined by evaluating each
source
element with the keyMaker
function.
This form of the MultiMap requires that the keys produced by the
keyMaker
are
Comparable and that the natural
ordering of those keys also defines the grouping of values. If either
of those assumptions are false, consider using
#syncEventListToMultiMap(EventList,FunctionList.Function,Comparator).
If two distinct values, say v1
and v2
each
produce a common key, k
, when they are evaluated by the
keyMaker
function, then a corresponding entry in the
MultiMap will resemble:
k -> {v1, v2}
For example, assume the keyMaker
function returns the
first letter of a name and the source
EventListcontains the names:
{"Andy", "Arthur", "Jesse", "Holger", "James"}
The MultiMap returned by this method would thus resemble:
"A" -> {"Andy", "Arthur"}
"H" -> {"Holger"}
"J" -> {"Jesse", "James"}
It is important to note that all mutating methods on the
Mapinterface "write through" to the backing
EventList as expected.
These mutating methods include:
- the mutating methods of
Map#keySet() and its
Iterator
- the mutating methods of
Map#values() and its
Iterator
- the mutating methods of
Map#entrySet() and its
Iterator
- the
Map.Entry#setValue method
- the mutating methods of
Map itself, including
Map#put,
Map#putAll,
Map#remove, and
Map#clear
For information on MultiMaps go
here.