@
xdchl 写完算了
import java.util.HashMap;
import java.util.Map;
public class MutipleIfQuestionFromV2ex {
public int testMethod() {
Map<String, Integer> map1 = new HashMap<>();
Map<String, Integer> map2 = new HashMap<>();
if (map2.get("unitLevel") == null || map1.get("unitLevel") == null) {
// return something according to your business logic
return 0;
} else {
return recursiveCompareLevelCount("countAA", "countAA", map1, map2);
}
}
private int recursiveCompareLevelCount(String key0, String key1, Map<String, Integer> map0, Map<String, Integer> map1) {
// key0 and key1 equals your end compare logic
if (key0.equals("unitScore") && key1.equals("unitScore")) {
return map1.get(key0).compareTo(map0.get(key1));
}
int flag = compareLevelCount(map1.get(key1), map0.get(key0));
if (flag != 0) {
return flag;
} else {
// set some rule to increment the key
char count = (char) (key0.charAt(key0.length() - 1) + 1);
if (count == 'E') {
key0 = "unitScore";
key1 = "unitScore";
} else if (count == 'B' && key0.charAt(key0.length() - 2) == 'A') {
key0 = "countA";
key1 = "countA";
} else {
key0 = key0.substring(0, key0.length() - 1) + count;
key1 = key1.substring(0, key1.length() - 1) + count;
}
return recursiveCompareLevelCount(key0, key1 , map0, map1);
}
}
private int compareLevelCount(int v1, int v2) {
return Integer.compare(v1, v2);
}
}