I have a List<POJO> that I want to extract data from and the variables I'm interested in are:
Environment: StringApplication: StringThroughput: Double
There are 7 Environment objects and each Environment has 18 Application objects, which each have multiple values.
I'm trying to iterate over the List<POJO> and store these values in a Hashmap<Environment.ToString, Hashmap<Applications.ToString, List<Double>>
I'm trying to use Java 8's Lambda features; my code so far:
private HashMap<String, List<BigDecimal>> appMap = new HashMap<String, List<BigDecimal>>();
private HashMap<String, HashMap> envMap = new HashMap<String, HashMap>();
for(POJO chartModel: List<POJO>) {
appMap.computeIfAbsent(chartModel.getName(), v -> new ArrayList<BigDecimal>())
.add(BigDecimal.valueOf(chartModel.getThroughput()));
envMap.put(chartModel.getEnvironment(), appMap);
}
Firstly, is there a shorthand way to iterate over the List inside the inner Map using Java8?
Secondly, my code isn't quite right, so currently the map adds all the Throughput values to its Application key, so I end up with 18 keys with a list of values.
What I need it to do is in my envMap I should have 7 Environment objects, with each having its 18 Application objects and values, so there would be 126 Application objects in total. Can this be achieved the way I'm attempting it, is there a Lambda way to achieve this?
appMap, and that's going to be inserted into theenvMap7 times, once for eachEnvironment.