2
私は三つのクラスを持っていますとその量。グループと合計深くネストされたリストは、
私が持っている場合は、次のとおりです、私はgroupingBy
と組み合わせの数を試した
"foo", "unit", 2
"foo", "another_unit", 1
、toMap
:
Unit unit1 = new Unit("unit");
Unit unit2 = new Unit("unit");
Unit unit3 = new Unit("another_unit");
Compartment compartment = new Compartment("foo", newArrayList(unit1, unit2, unit3));
Supply supply = new Supply(newArrayList(compartment));
のJavaストリーム使用して、私のような何かを取得したいと思いそのような幸運はありません。
私の最新の試みのようなものです:
私は非常に近いですが、私は私がキー以来Map
を使用することができませんでしたね、
itemId
が異なる
containerNumber
であり、複数回可能性を感じ
Map<String, List<Map<String, List<Unit>>>> result = supply.getCompartments()
.stream()
.collect(groupingBy(Compartment::getItemId,
mapping(compartment -> compartment.getUnits().stream().collect(groupingBy(Unit::getContainerNumber)), toList())));