原List : ["0"," 0"," 55555"," 6666666"," 0"," 333"," 0", "4444", "0", "0"]
理想List: ["55555","55555","55555","6666666","6666666","333","333","4444","4444","4444"]
List<Double> winMasterList = new ArrayList<>();
winMasterList.add(0d);
winMasterList.add(0d);
winMasterList.add(55555d);
winMasterList.add(6666666d);
winMasterList.add(0d);
winMasterList.add(333d);
winMasterList.add(0d);
winMasterList.add(4444d);
winMasterList.add(0d);
winMasterList.add(0d);
JSONArray winMasterData = new JSONArray();
Map<Integer, Double> winMasterMap = new HashMap<>();// 所有下标-数值
List<Integer> indexList = new ArrayList<>();// 记录为0的下标
List<Integer> indexMaxList = new ArrayList<>();// 记录为0的下标
for (int i = 0; i < winMasterList.size(); i++) {
winMasterMap.put(i, winMasterList.get(i));
if (winMasterList.get(i) == 0) {
indexList.add(i);
} else {
indexMaxList.add(i);
}
}
if (indexList != null && indexList.size() > 0) {
int index = 0;
for (int i = 0; i < winMasterList.size(); i++) {
if (winMasterList.get(i) == 0) {
for (int j = 0; j < indexMaxList.size(); j++) {
if (j == 0 && indexMaxList.get(j) > i) {
index = indexMaxList.get(j);
break;
}
if (j > 0 && i > indexMaxList.get(j - 1) && i < indexMaxList.get(j)) {
index = indexMaxList.get(j - 1);
break;
} else if (i > indexMaxList.get(j)) {
index = indexMaxList.get(j);
}
}
winMasterData.add(DSHUtils.formatDouble(winMasterList.get(index), 4));
} else {
winMasterData.add(DSHUtils.formatDouble(winMasterList.get(i), 4));
}
}
}
System.out.println(winMasterData);