Returns a view of a
ListMultimap whose values are derived from the
original multimap's entries. In contrast to
#transformValues(ListMultimap,Function), this method's
entry-transformation logic may depend on the key as well as the value.
All other properties of the transformed multimap, such as iteration
order, are left intact. For example, the code:
Multimap multimap =};
Multimap transformed =
Multimaps.transformEntries(multimap, transformer);
System.out.println(transformed);}
... prints
{"a"=["a1", "a4"], "b"=["b6"]}}.
Changes in the underlying multimap are reflected in this view.
Conversely, this view supports removal operations, and these are reflected
in the underlying multimap.
It's acceptable for the underlying multimap to contain null keys and
null values provided that the transformer is capable of accepting null
inputs. The transformed multimap might contain null values if the
transformer sometimes gives a null result.
The returned multimap is not thread-safe or serializable, even if the
underlying multimap is.
The transformer is applied lazily, invoked when needed. This is
necessary for the returned multimap to be a view, but it means that the
transformer will be applied many times for bulk operations like
Multimap#containsValue and
Object#toString. For this to perform
well,
transformer should be fast. To avoid lazy evaluation when the
returned multimap doesn't need to be a view, copy the returned multimap
into a new multimap of your choosing.
Warning: This method assumes that for any instance
k of
EntryTransformer key type
K,
k.equals(k2) implies
that
k2 is also of type
K. Using an
EntryTransformer key type for which this may not hold, such as
ArrayList, may risk a
ClassCastException when calling methods on
the transformed multimap.