0

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?

3
  • You should add a mention and/or tag of where you get these classes like ImmutableMap. I’m guessing they come from Google Guava. But you should not make us guess. Commented Jan 29 at 20:53
  • You might need to make helper accept a slightly more general argument type, like List. Is that acceptable? I don't see why that would be an issue with modifying it, even if you have multiple users. Commented Jan 29 at 21:09
  • Is it possible to pull out the common code from helper into a separate method which is used by both the helper that takes an Impact and the helper that takes a list of Impact? Commented Jan 29 at 22:05

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.