获取嵌套HashMap的值

时间:2014-07-08 19:34:22

标签: java gwt gwt-highcharts

我在地图中有地图和列表,并希望从db获取此地图对象的数据,任何人都可以建议我,我正在以正确的方式获取此代码上的两个地图的键和值,我有一个对象A它包含一个带有C值列表的对象B,我得到的是A对象的数据,但B和C对象的数据在所有A对象中是相似的,而C对象只指向一个点而不渲染全部价值,哪里错了?:

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);
    }

  }

};  

编辑填充地图:

   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;
}

1 个答案:

答案 0 :(得分:1)

当您填充outermap时,您需要为每个条目使用不同的innermap。您的代码应为:

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;
}
相关问题