1 package com.jofti.util; 2 3 4 import java.util.Comparator ; 5 import java.util.Map ; 6 7 import com.jofti.exception.JoftiException; 8 import com.jofti.introspect.ClassIntrospector; 9 10 public class ReflectionComparator implements Comparator { 11 12 private Object [] methods =null; 13 ClassIntrospector introspector =null; 14 15 public ReflectionComparator(Object [] methods, ClassIntrospector introspector){ 16 this.methods = methods; 17 this.introspector = introspector; 18 } 19 public int compare(Object o1, Object o2) { 20 int res =0; 21 try { 22 23 24 Object or1 = ((Map.Entry )o1).getValue(); 25 Object or2 = ((Map.Entry )o2).getValue(); 26 27 Comparable comp1 = (Comparable )introspector.getResultFromMethods(or1, methods); 28 Object comp2 = introspector.getResultFromMethods(or2, methods); 29 30 res = comp1.compareTo(comp2); 31 32 if (res ==0){ 33 return ((Map.Entry )o1).getKey().toString().compareTo(((Map.Entry )o1).getKey().toString()); 34 } 35 } catch (JoftiException e){ 36 throw new RuntimeException (e); 37 } 38 return res; 39 40 } 41 42 } 43 | Popular Tags |