I have the following data structure
public class Zones {
private List<Zone> zones;
}
public class Zone {
private int id;
private String name;
private List<Part> parts;
}
public class Part {
private int id;
private String name;
}
THis is my problem. I have with me an instance of Zones, say z.
I want to stream z and do the following: construct a map out of z with the following conditions: if the key (based on the "Id" of the Zone) is new, then create an entry in the map with the key and the Zone. If the key is a duplicate, then append all "parts" of this duplicate zone into the existing zone's parts list. In the end I should have a map with "Id" of the zone as the key and the zone as the value.
How can I do this in Java8 using streams?
namein such a case for sayz1andz2beingZonewith the same id?