hartmut
hartmut

Reputation: 982

How to call existing function on value of ImmutableListMultimap instead of Map

I currently have this function:

ImmutableMap<String, ImmutableList<ImpactSummary>>
      toSummariesByKey(ImmutableMap<String, ImmutableList<Impact>> impactsByKey) 
return impactsByKey.entrySet().stream()
    .collect(
        toImmutableMap(
            entry -> entry.getKey(),
            entry -> helper(entry.getValue())));}

which makes use of this function:

  ImmutableList<TierSummary> helper(
  ImmutableList<Impact> impacts) {...}

As you can see, toSummariesByKey simply calls helper on each of the values in the input map.

Now, I need to modify toSummariesByKey to take as argument, and return, an ImmutableListMultimap instead:

  ImmutableListMultimap<String, ImpactSummary> toSummariesByKey(
      ImmutableListMultimap<String, Impact> impactsByKey) {...}

Reusing the body as is causes, when the helper function is called, the following error:

type ImmutableList<Impact> is not compatible with Impact

However, helper is used in several places so I am reluctant to modify it. What is good practice in this scenario, please?

Upvotes: 0

Views: 29

Answers (0)

Related Questions