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