StatViewServlet: add activeConnectionStackTrace support, refactor js

This commit is contained in:
sand
2012-07-30 20:42:46 +08:00
parent 0370afc794
commit 5aabf6b5cb
14 changed files with 424 additions and 217 deletions
@@ -1,5 +1,6 @@
package com.alibaba.druid.util;
import java.lang.reflect.Array;
import java.text.Collator;
import java.util.Comparator;
import java.util.Date;
@@ -11,9 +12,9 @@ import java.util.Map;
public class MapComparator<K extends Object, V extends Object> implements Comparator<Map<K, V>> {
private boolean isDesc;
private String orderByKey;
private K orderByKey;
public MapComparator(String orderByKey, boolean isDesc) {
public MapComparator(K orderByKey, boolean isDesc) {
this.orderByKey = orderByKey;
this.isDesc = isDesc;
}
@@ -39,9 +40,24 @@ public class MapComparator<K extends Object, V extends Object> implements Compar
return result;
}
private Object getValueByKey(Map<K, V> map, K key) {
if (key instanceof String) {
String keyStr = (String) key;
if (keyStr.matches(".+\\[[0-9]+\\]")) {
Object value = map.get(keyStr.substring(0, keyStr.indexOf("[")));
Integer index = StringUtils.subStringToInteger(keyStr, "[", "]");
if (value.getClass().isArray() && Array.getLength(value) >= index) {
return Array.get(value, index);
}
return null;
}
}
return map.get(key);
}
public int compare_0(Map<K, V> o1, Map<K, V> o2) {
Object v1 = o1.get(orderByKey);
Object v2 = o2.get(orderByKey);
Object v1 = getValueByKey(o1, orderByKey);
Object v2 = getValueByKey(o2, orderByKey);
if (v1 == null && v2 == null) return 0;
if (v1 == null) return -1;