01: package com.jofti.util;
02:
03: import java.util.Comparator;
04: import java.util.Map;
05: import java.util.Map.Entry;
06:
07: public class ArrayComparator implements Comparator {
08:
09: private int index = 0;
10:
11: public ArrayComparator(int index) {
12: this .index = index;
13: }
14:
15: public int compare(Object o1, Object o2) {
16: int res = 0;
17: try {
18:
19: Object[] arr1 = (Object[]) ((Map.Entry) o1).getValue();
20: Object[] arr2 = (Object[]) ((Map.Entry) o2).getValue();
21:
22: res = ((Comparable) arr1[index]).compareTo(arr2[index]);
23:
24: if (res == 0) {
25: return ((Map.Entry) o1).getKey().toString().compareTo(
26: ((Map.Entry) o1).getKey().toString());
27: }
28: } catch (Exception e) {
29: throw new RuntimeException(e);
30: }
31: return res;
32:
33: }
34:
35: }
|