Apache Commons Collections MultiValuedMap 按多个字段过滤数据

伊苏达山

下面的数据是java内存中的一个集合ArrayList,从这个集合中需要根据两个字段(VRNT_CD和ITM_NB)的组合过滤数据

VRNT_CD ITM_NB COMMT_TEXT
 10      A0A     SampleText1
 10      A0A     SampleText2
 10      A0A     SampleText3
 10      A0B     SampleText4
 10      A0C     SampleText5
 20      A0A     SampleText6
 20      A0A     SampleText7
 20      A0B     SampleText8
 20      A0C     SampleText9
 30      A0A     SampleText10
 30      A0A     SampleText11
 30      AOB     SampleText12
 30      A0C     SampleText13
 30      A0C     SampleText14

如上所述,上表中的每一行都映射到下面的java对象

public class SummaryDataOracle {

    private String funcCode;
    private String commentText;
    private String variantCd;
    private String itemNB;
  //setters //getters
}

上表的集合表示为List<SummaryDataOracle>,需要根据下面的键使用集合对象生成地图

public class VssKey {

    private String funCode;
    private String varntCode;
    private String itemNb;

    //setters //getters // equals // hashcode

}

所以结果集合应该具有以下数据结构

AOA   10    SampleText1
            SampleText2
            SampleText3

      20    SampleText6
            SampleText7

      30    SampleText10
            SampleText11

AOB   10    SampleText4

      20    SampleText8

      30    SampleText12

AOC   10    SampleText5

      20    SampleText9

      30    SampleText13
            SampleText14
伊苏达山

通过实现以下对象并使用 apache commons 解决了问题MultiValuedMap

public class VssKey {

     // getterrs
     // setters
     // equals
     // hashcode
}

    MultiValuedMap<VssKey, String> partNumberVarientMap = new ArrayListValuedHashMap<>();

            for (SummaryDataOracle summaryDataOracle : summeryDataOracleList) {

                VssKey key = new VssKey(summaryDataOracle);

                String varntText = null;
                if (!StringUtils.isEmpty(summaryDataOracle.getVariantSmText())) {
                    varntText = summaryDataOracle.getVariantSmText().trim();
                }

                partNumberVarientMap.put(key, varntText);    
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

按键对Apache Commons MultiValuedMap进行排序

使用Apache Commons Collections中的MultiValueMap

缺少org.apache.commons.collections.CollectionUtils

java.lang.NoClassDefFoundError:org / apache / commons / collections / Transformer

是否有与Apache Commons Collections中的ArrayIterator等效的泛型?

是否有可行的通用替代apache.commons.collections.CollectionUtils?

java.lang.NoClassDefFoundError:Lorg / apache / commons / collections / FastHashMap;

Dart 相当于 Apache Commons Collections Bag

数据未通过Apache Commons写入csv

TomEE 1.6.0.2上的org.apache.commons.collections4类的ClassNotFoundException

错误:java.lang.ClassNotFoundException:org.apache.commons.collections4.map.LinkedMap

Guava或Apache Commons Collections中有toArray()的任何通用版本吗?

Apache Commons-Collection的SynchronizedList()和java.util.Collections.synchronizedList()之间的区别

Apache Commons FTP问题

Apache Commons CLI(选项)

Apache Commons FTPClient挂起

Google Guava与Apache Commons

Apache Commons Unzip方法?

Apache Commons CLI无法按预期进行解析?

org.apache.commons.beanutils copyProperties忽略字段

无字段 sessionHostPortCache - Apache Commons Net 存储文件

多个dex文件定义了Lorg / apache / commons / logging / impl / LogFactoryImpl

多个dex文件定义了Lorg / apache / commons / io / IOUtils;

Apache-Commons Commons-Functor的状态

commons-collections和commons-beanutils中的重复类

如何学习使用Java Commons-Collections?

Apache Commons Configuration:ClassNotFoundException:org.apache.commons.beanutils.DynaBean

Apache Commons CLI参数值

Apache Class Commons Math的NoClassDefFoundError