List of usage examples for org.apache.commons.collections MapUtils getDouble
public static Double getDouble(final Map map, final Object key)
From source file:com.glaf.core.util.ParamUtils.java
public static Double getDoubleValue(Map<String, Object> dataMap, String key) { Double result = null;//from w w w . ja va 2 s . c om Object value = dataMap.get(key); if (value == null) { value = dataMap.get(key.toLowerCase()); } if (value == null) { value = dataMap.get(key.toUpperCase()); } if (value != null && StringUtils.isNotEmpty(value.toString())) { if (value instanceof String) { String tmp = (String) value; result = Double.parseDouble(tmp); } else if (value instanceof Integer) { Integer x = (Integer) value; result = x.doubleValue(); } else if (value instanceof Long) { Long x = (Long) value; result = x.doubleValue(); } else if (value instanceof Double) { Double x = (Double) value; result = x.doubleValue(); } else { String tmp = value.toString(); result = Double.parseDouble(tmp); } } else { result = MapUtils.getDouble(dataMap, key); } return result; }
From source file:com.glaf.chart.bean.ChartDataManager.java
protected void fetchData(Chart chart, TableModel rowMode, String querySQL, Map<String, Object> paramMap, String actorId) {/* w w w . java 2 s.c o m*/ if (StringUtils.isNotEmpty(querySQL)) { paramMap.put("curr_yyyymm", Integer.parseInt(SystemConfig.getCurrentYYYYMM())); paramMap.put("curr_yyyymmdd", Integer.parseInt(SystemConfig.getCurrentYYYYMMDD())); querySQL = QueryUtils.replaceSQLVars(querySQL); // querySQL = QueryUtils.replaceSQLParas(querySQL, paramMap); logger.debug("paramMap=" + paramMap); logger.debug("querySQL=" + querySQL); rowMode.setSql(querySQL); DatabaseConnectionConfig config = new DatabaseConnectionConfig(); Long databaseId = chart.getDatabaseId(); LoginContext loginContext = IdentityFactory.getLoginContext(actorId); Database currentDB = config.getDatabase(loginContext, databaseId); String systemName = Environment.getCurrentSystemName(); try { if (currentDB != null) { Environment.setCurrentSystemName(currentDB.getName()); } List<Map<String, Object>> rows = getTablePageService().getListData(querySQL, paramMap); if (rows != null && !rows.isEmpty()) { logger.debug(rows); int index = 0; Map<String, Object> dataMap = new java.util.HashMap<String, Object>(); for (Map<String, Object> rowMap : rows) { dataMap.clear(); Set<Entry<String, Object>> entrySet = rowMap.entrySet(); for (Entry<String, Object> entry : entrySet) { String key = entry.getKey(); Object value = entry.getValue(); dataMap.put(key, value); dataMap.put(key.toLowerCase(), value); } if ("pie".equals(chart.getChartType())) { index++; ColumnModel cell = new ColumnModel(); cell.setColumnName("col_" + index); cell.setSeries(MapUtils.getString(dataMap, "series")); cell.setDoubleValue(MapUtils.getDouble(dataMap, "doublevalue")); chart.addCellData(cell); } else { index++; ColumnModel cell = new ColumnModel(); cell.setColumnName("col_" + index); cell.setCategory(MapUtils.getString(dataMap, "category")); cell.setSeries(MapUtils.getString(dataMap, "series")); cell.setDoubleValue(MapUtils.getDouble(dataMap, "doublevalue")); chart.addCellData(cell); } } logger.debug("rows size:" + chart.getColumns().size()); } } catch (Exception ex) { ex.printStackTrace(); logger.error(ex); } finally { Environment.setCurrentSystemName(systemName); } } }