0

i have map and list inside map, and want to get the data for this map objects from db, can anyone suggest me please am i in a right way to getting the keys and values for both map on this code, i have an object A it contains an objects B with list of C values, i am getting the data for A object, but the data for B and C objects are similar in all A object and the C object is point only one points without rendering the all values, where did i wrong?:

void getData(int dataNo) {

AsyncCallback<Map<A, Map<B,List<C>>>> callback = new AsyncCallback<Map<A, Map<B,List<C>>>>() {

  public void onFailure(Throwable caught) {

  }

  public void onSuccess(Map<A, Map<B,List<C>>> result) {

    panel.clear();

    for (Map.Entry<A, Map<B,List<C>>> entry : result.entrySet()) {
      A a = entry.getKey();
      Map<B, List<C>> bc = entry.getValue();

      chart = new Chart().setType(Series.Type.LINE)
                  .setLegend(new Legend()
                                 .setLayout(Legend.Layout.VERTICAL)
                                 .setAlign(Legend.Align.RIGHT)
                                 .setVerticalAlign(Legend.VerticalAlign.TOP)
                                 .setX(-10).setY(100)
                                 .setBorderWidth(0))
                                 .setZoomType(Chart.ZoomType.X_AND_Y);

      chart.setChartTitleText(a.getL());

      for(Map.Entry<B, List<C>> in : bc.entrySet()){
        B b = in.getKey();
        List<C> c=in.getValue();

        bc.containsKey(b);
        bc.containsValue(c);
        serie = chart.createSeries().setName(b.getF());
        C[] ac=c.toArray(new C[c.size()]);
        for (C cd: ac) {
          serie.setPoints(new Number[] { cd.getS()});
        }

        chart.addSeries(serie);

      }
      panel.add(chart);
    }

  }

};  

EDIT populate map:

   public Map<A, Map<B, List<C>>> getL(int dataNo) {
    Map<A, Map<B, List<C>>> outermap = new HashMap<A, Map<B, List<C>>>();
    Map<B,List<C>> innermap=new HashMap<B,List<C>>();

    List<A> a= DB.getL(dataNo);
    for (A aa: a) {
        outermap.put(aa, innermap);
        List<B> b=DB.getK(aa.getId());
        for(B bb: b){
        innermap.put(bb, DB.getD(bb.getId()));
     }

    }
    return outermap;
}
user3721625
  • 267
  • 1
  • 3
  • 9

1 Answers1

1

When you're populating the outermap you need to use a different innermap for each entry. Your code should read:

public Map<A, Map<B, List<C>>> getL(int dataNo) {
  Map<A, Map<B, List<C>>> outermap = new HashMap<A, Map<B, List<C>>>();
  List<A> a= DB.getL(dataNo);
  for (A aa: a) {
    Map<B,List<C>> innermap=new HashMap<B,List<C>>();
    outermap.put(aa, innermap);
    List<B> b=DB.getK(aa.getId());
    for(B bb: b){
      innermap.put(bb, DB.getD(bb.getId()));
    }
  }
  return outermap;
}
Andy King
  • 1,632
  • 2
  • 20
  • 29