private Map<String, Double> existsRowModel( Map<String, Double> mRowModel, String key, Double value) { if (mRowModel.get(key) == null) { mRowModel.put(key, value); } else { mRowModel.put(key, mRowModel.get(key) + value); } return mRowModel; }
private List<RowModel> populateMonths() { List<Map> ds1 = (List<Map>) dataSources.get(0); List<RowModel> rowModels = new ArrayList<RowModel>(); Map<String, Double> mRowModel = new HashMap<String, Double>(); RowModel rowModel; Map ds = null; for (int j = 0; j < ds1.size(); j++) { ds = ds1.get(j); mRowModel = existsRowModel(mRowModel, "01Jan", (Double) ds.get("JAN")); mRowModel = existsRowModel(mRowModel, "02Feb", (Double) ds.get("FEB")); mRowModel = existsRowModel(mRowModel, "03Mar", (Double) ds.get("MAR")); mRowModel = existsRowModel(mRowModel, "04Apr", (Double) ds.get("APR")); mRowModel = existsRowModel(mRowModel, "05Mei", (Double) ds.get("MEI")); mRowModel = existsRowModel(mRowModel, "06Jun", (Double) ds.get("JUN")); mRowModel = existsRowModel(mRowModel, "07Jul", (Double) ds.get("JUL")); mRowModel = existsRowModel(mRowModel, "08Ags", (Double) ds.get("AGUS")); mRowModel = existsRowModel(mRowModel, "09Sep", (Double) ds.get("SEP")); mRowModel = existsRowModel(mRowModel, "10Okt", (Double) ds.get("OKT")); mRowModel = existsRowModel(mRowModel, "11Nov", (Double) ds.get("NOV")); mRowModel = existsRowModel(mRowModel, "12Dec", (Double) ds.get("DES")); } String key = null; Iterator iterator = mRowModel.keySet().iterator(); while (iterator.hasNext()) { key = (String) iterator.next(); rowModels.add(new RowModel(key, mRowModel.get(key))); } return rowModels; }