-1

The below data is an in memory collection as java ArrayList, from this collection the need is to filter the data based on the combination of two fields (VRNT_CD and 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

As mentioned above, each row in the above table is mapped to a below java object

public class SummaryDataOracle {

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

The collection of the above table represents as List<SummaryDataOracle> , a map needs to be generated using the collection object based on the below key

public class VssKey {

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

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

}

so the resultant collection should have the below data structure

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
isudarsan
  • 437
  • 1
  • 6
  • 14
  • Looks correct, what do you get as output here? – Naman Jun 14 '19 at 07:42
  • @Naman added the output by editing the question.Thanks – isudarsan Jun 14 '19 at 07:46
  • 1
    I am guessing that you are looking for a mapping further. Something like this possibly `protected Map>> groupByFieldsAndMap(List modelList, Function super V, ? extends K> classifier1, Function super V, ? extends L> classifier2, Function super V, ? extends M> mapper) { return modelList.stream().collect(Collectors.groupingBy(classifier1, Collectors.groupingBy(classifier2, Collectors.mapping(mapper, Collectors.toList())))); }`... Note, that I tried to use different type for all operations performed. – Naman Jun 14 '19 at 08:16
  • @Naman I am looking for composite mapping on the table based on multiple classifiers. – isudarsan Jun 14 '19 at 08:43
  • I am unable to see the composite mapping in the input/output shared in the question. Would be good to highlight the mapping that you meant here. – Naman Jun 14 '19 at 10:02

1 Answers1

0

Solved the problem by implementing the below object and using 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);    
}
isudarsan
  • 437
  • 1
  • 6
  • 14