I have the following Map:
LonM =[0, 0, 0, 0, 46, 15]
LatM =[5, 52, 35, 16, 37, 5]
Paralelly, I have implemented a composite pattern class:
public class CompositeDataFrame implements IDataFrame, ICompositeDataFrame {
private String name;
private List <IDataFrame> children;
public CompositeDataFrame(String name){
this.name = name;
children = new LinkedList<>();
}
public void addChildren(IDataFrame child){
children.add(child);
}
And I've obtained the following query method:
public Map<Object, List<Object>> query(String keySelector, Predicate<Object> valuePredicate) {
Map<Object, List<Object>> result = new HashMap<>();
for (IDataFrame child:children)
result.putAll(child.query(keySelector, valuePredicate));
return result;
}
So then we have the following main which call the query method:
CompositeDataFrame comp = new CompositeDataFrame("CompositeCities");
CompositeDataFrame comp1 = new CompositeDataFrame("2");
comp.addChildren(comp1);
comp1.addChildren(df);
comp.addChildren(df);
System.out.println("\n"+comp.query("LonM", entry -> ((Integer) entry) == 0));
The question is: how can I concatenate the map's of each child?
PD: I used the putAll method but it remove the maps which same keys, so it doesn't be useful in this case.
The output should be:
LonM =[0, 0, 0, 0, 0, 0, 0, 0] LatM =[5, 52, 35, 16, 5, 52, 35, 16]
Thanks a lot!