1 package com.jofti.util; 2 3 import java.util.Comparator ; 4 import java.util.Map ; 5 import java.util.Map.Entry; 6 7 public class ArrayComparator implements Comparator { 8 9 private int index =0; 10 11 public ArrayComparator(int index){ 12 this.index=index; 13 } 14 public int compare(Object o1, Object o2) { 15 int res =0; 16 try { 17 18 Object [] arr1 = (Object [])((Map.Entry )o1).getValue(); 19 Object [] arr2 = (Object [])((Map.Entry )o2).getValue(); 20 21 res = ((Comparable )arr1[index]).compareTo(arr2[index]); 22 23 if (res ==0){ 24 return ((Map.Entry )o1).getKey().toString().compareTo(((Map.Entry )o1).getKey().toString()); 25 } 26 } catch (Exception e){ 27 throw new RuntimeException (e); 28 } 29 return res; 30 31 } 32 33 } 34 | Popular Tags |