1 26 27 package org.objectweb.util.browser.plugin.java.reflect; 28 29 import java.lang.reflect.Field ; 30 import java.lang.reflect.Method ; 31 import java.util.Comparator ; 32 33 43 public class MemberComparator 44 implements Comparator { 45 46 52 58 64 protected int compare(String s1, String s2){ 65 return s1.compareTo(s2); 66 } 67 68 protected int compare(Class c1, Class c2){ 69 return compare(c1.getName(), c2.getName()); 70 } 71 72 protected int compare(Field f1, Field f2){ 73 return compare(f1.getName(), f2.getName()); 74 } 75 76 protected int compare(Method m1, Method m2){ 77 return compare(m1.getName(), m2.getName()); 78 } 79 80 86 public int compare(Object o1, Object o2) { 87 if(o1!=null && o2!=null){ 88 if(o1 instanceof Class && o2 instanceof Class ) 89 return compare((Class )o1,(Class )o2); 90 else if(o1 instanceof Field && o2 instanceof Field ) 91 return compare((Field )o1,(Field )o2); 92 else if(o1 instanceof Method && o2 instanceof Method ) 93 return compare((Method )o1,(Method )o2); 94 else 95 return 0; 96 } 97 return 0; 98 } 99 100 } 101 | Popular Tags |