private static ExcMsg[] changeSort(ExcMsg[] msg, String param, final int sort)
throws Exception {
final Field f = ExcMsg.class.getField(param);
java.util.Arrays.sort(msg, new Comparator() {
public int compare(Object o1, Object o2) {
if(o1 instanceof ExcMsg && o2 instanceof ExcMsg) {
ExcMsg m1 = (ExcMsg)o1;
ExcMsg m2 = (ExcMsg)o2;
try {
if(f.get(m1) instanceof Comparable) {
return ((int)Math.pow(-1, sort)) * ((Comparable)f.get(m1)).compareTo(f.get(m2));
} else {
return 0;
}
} catch(Exception ee) {}
}
return 0;
} public boolean equals(Object obj) {
return false;
}
}); return msg;
}
throws Exception {
final Field f = ExcMsg.class.getField(param);
java.util.Arrays.sort(msg, new Comparator() {
public int compare(Object o1, Object o2) {
if(o1 instanceof ExcMsg && o2 instanceof ExcMsg) {
ExcMsg m1 = (ExcMsg)o1;
ExcMsg m2 = (ExcMsg)o2;
try {
if(f.get(m1) instanceof Comparable) {
return ((int)Math.pow(-1, sort)) * ((Comparable)f.get(m1)).compareTo(f.get(m2));
} else {
return 0;
}
} catch(Exception ee) {}
}
return 0;
} public boolean equals(Object obj) {
return false;
}
}); return msg;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货