第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 ImmutableMap 中扁平化 ImmutableList

如何在 ImmutableMap 中扁平化 ImmutableList

湖上湖 2023-05-17 16:58:19
比如說,我有一個名為 DomainObject 的類,class DomainObject {  private Long id;  private String domainParam;}我收到的對象列表如下:(id, domainType) = (1, "A") , (1, "B"), (3, "C"), (4, "A"), (1, "C")畢竟,我想接收帶有 Key(ImmutableList of Id) 和 Pair(Immutable list of domainParam) 的 ImmutableMap,例如:1 [A, B, C]3 [C]4 [A]現(xiàn)在我收到類似的東西:{[1]=[DomainObject(id=1, domainParam=A), DomainObject(id=1, domainParam=B), DomainObject(id=1, domainParam=B)]}這不是理想的解決方案。到目前為止,我有這樣的代碼:ImmutableMap<ImmutableList<Long>, ImmutableList<DomainObject>> groupedDomainObject(      List<DomainObject> domainObjectList) {    return domainObjectList.stream()        .collect(            Collectors.collectingAndThen(                Collectors.groupingBy(                    (domainObject) -> ImmutableList.of(domainObject.getId()),                    ImmutableList.<DomainObject>toImmutableList()),                ImmutableMap::copyOf));}我即將實現(xiàn)一個目標(biāo),但我如何才能從這部分中獲得價值:ImmutableList.<DomainObject>toImmutableList()接收唯一沒有 DomainObject id 的 domainParam。如果我能得到任何幫助,我將不勝感激。
查看完整描述

2 回答

?
慕尼黑5688855

TA貢獻(xiàn)1848條經(jīng)驗 獲得超2個贊

       ......

        .stream()

        .collect(Collectors.collectingAndThen(

            Collectors.groupingBy(

                x -> ImmutableList.of(x.getId()),

                Collectors.mapping(

                    DomainObject::getDomainParam,

                    ImmutableList.toImmutableList())),

            ImmutableMap::copyOf

        ));


查看完整回答
反對 回復(fù) 2023-05-17
?
拉丁的傳說

TA貢獻(xiàn)1789條經(jīng)驗 獲得超8個贊

ImmutableMap<Long, ImmutableList<String>> groupedDomainObject(

                List<DomainObject> domainObjectList) {


            return domainObjectList

                    .stream()

                    .collect(

                            Collectors.collectingAndThen(

                                Collectors.toMap(

                                    DomainObject::getId,

                                    obj -> ImmutableList.of(obj.domainParam),

                                    (a, b) -> ImmutableList.<String>builder().addAll(a).addAll(b).build()

                                ),

                                ImmutableMap::copyOf

                            )

                    );

        }


查看完整回答
反對 回復(fù) 2023-05-17
  • 2 回答
  • 0 關(guān)注
  • 166 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號