把一种特殊的数据结构转化成TreeMap结构

public List allCyclicData(String startTime, String endTime, int flag) { List _cyclicData = new ArrayList(); for (int i = 0; i < allIndicator.size(); i += 2) { int indicatorId = Integer.parseInt(allIndicator.get(i).toString()); String indicatorName = allIndicator.get(i + 1).toString(); List tempData = new ArrayList(); if (flag == 1) { tempData = alertNumOfDeviceIndicatorByDay(deviceId, indicatorId, startTime, endTime); } else { tempData = alertNumOfDeviceIndicatorByHour(deviceId, indicatorId, startTime, endTime); } System.out.println("tempData = " + tempData); int numOfFlag = 0; Map<Integer, Integer> position = new HashMap<Integer, Integer>(); if (tempData.isEmpty() || !ifHaveProbe(deviceId, indicatorId)) { numOfFlag = -1; } else { int index = 0; while (index < tempData.size()) { if ("*".equals(tempData.get(index).toString())) { position.put(numOfFlag++, index); } index++; } System.out.println(index + "_index"); } System.out.println(numOfFlag + "_numOfFlag"); if (numOfFlag == -1) { TreeMap tm = new TreeMap(); tm.put("rendered", false); System.out.println(false + "_rendered"); } else if (numOfFlag == 1) { System.out.println("tempData true = " + tempData); int endOfFlag = position.get(0); System.out.println("endOfFlag 1 = " + endOfFlag); TreeMap tm = new TreeMap(); tm.put("rendered", true); tm.put("type", "line"); tm.put("unit", "".equals(tempData.get(2).toString()) ? "" : ("(" + tempData.get(2).toString() + ")")); tm.put("chartTitle", indicatorName); int length = (tempData.size() - 4) / 5; System.out.println("length 1 = " + length); double[][] levelData = new double[length][4]; String[] label = new String[length]; for (int j = 3, k = 0; j < endOfFlag - 4; j += 5, k++) { String str = tempData.get(j).toString(); if (flag == 1) { label[k] = str.substring(5, 10); } else { label[k] = str.substring(11, 16); } double warnEventNo = Double.valueOf(tempData.get(j + 1).toString()); double critEventNo = Double.valueOf(tempData.get(j + 2).toString()); double emerEventNo = Double.valueOf(tempData.get(j + 3).toString()); double totalEventNo = Double.valueOf(tempData.get(j + 4).toString()); levelData[k][0] = warnEventNo; levelData[k][1] = critEventNo; levelData[k][2] = emerEventNo; levelData[k][3] = totalEventNo; } List labelsX = Arrays.asList(label); List everyLevelData = Arrays.asList(levelData); tm.put("labelsX", labelsX); tm.put("everyLevelData", everyLevelData); _cyclicData.add(tm); } else if (numOfFlag > 1) { int endOfFlag = -1; for (int m = 0; m < numOfFlag; m++) { int startFlag = endOfFlag + 4; endOfFlag = position.get(m); int length = (endOfFlag - startFlag) / 5; double[][] levelData = new double[length][4]; String[] label = new String[length]; TreeMap tm = new TreeMap(); tm.put("rendered", true); tm.put("type", "line"); tm.put("unit", "".equals(tempData.get(startFlag - 1).toString()) ? "" : ("(" + tempData.get(startFlag - 1).toString() + ")")); tm.put("chartTitle", indicatorName + "(" + tempData.get(startFlag - 2).toString() + ")"); for (int j = startFlag, k = 0; j < endOfFlag - 4; j += 5, k++) { String str = tempData.get(j).toString(); if (flag == 1) { label[k] = str.substring(5, 10); } else { label[k] = str.substring(11, 16); } double warnEventNo = Double.valueOf(tempData.get(j + 1).toString()); double critEventNo = Double.valueOf(tempData.get(j + 2).toString()); double emerEventNo = Double.valueOf(tempData.get(j + 3).toString()); double totalEventNo = Double.valueOf(tempData.get(j + 4).toString()); levelData[k][0] = warnEventNo; levelData[k][1] = critEventNo; levelData[k][2] = emerEventNo; levelData[k][3] = totalEventNo; } List labelsX = Arrays.asList(label); List everyLevelData = Arrays.asList(levelData); tm.put("labelsX", labelsX); tm.put("everyLevelData", everyLevelData); _cyclicData.add(tm); } } } return _cyclicData; }

你可能感兴趣的:(把一种特殊的数据结构转化成TreeMap结构)