java - How to call existing function on value of ImmutableListMultimap instead of Map - Stack Overflow

I currently have this function:ImmutableMap<String, ImmutableList<ImpactSummary>>toSummari

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?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745281846a4620322.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信