KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > browser > plugin > java > reflect > MemberComparator


1 /*====================================================================
2
3 Objectweb Browser Framework
4 Copyright (C) 2000-2003 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Philippe Merle, Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.util.browser.plugin.java.reflect;
28
29 import java.lang.reflect.Field JavaDoc;
30 import java.lang.reflect.Method JavaDoc;
31 import java.util.Comparator JavaDoc;
32
33 /**
34  * This class compares two <code>Field</code> objects
35  * or two <code>Method</code> objects, or two <code>Class</code> objects
36  * lexicographically.
37  *
38  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>,
39  * <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>
40  *
41  * @version 0.1
42  */

43 public class MemberComparator
44     implements Comparator JavaDoc {
45
46     //==================================================================
47
//
48
// No internal state.
49
//
50
//==================================================================
51

52     //==================================================================
53
//
54
// No constructor.
55
//
56
//==================================================================
57

58     //==================================================================
59
//
60
// Internal methods.
61
//
62
//==================================================================
63

64     protected int compare(String JavaDoc s1, String JavaDoc s2){
65         return s1.compareTo(s2);
66     }
67
68     protected int compare(Class JavaDoc c1, Class JavaDoc c2){
69         return compare(c1.getName(), c2.getName());
70     }
71
72     protected int compare(Field JavaDoc f1, Field JavaDoc f2){
73         return compare(f1.getName(), f2.getName());
74     }
75         
76     protected int compare(Method JavaDoc m1, Method JavaDoc m2){
77         return compare(m1.getName(), m2.getName());
78     }
79
80     //==================================================================
81
//
82
// Public method for Comparator interface.
83
//
84
//==================================================================
85

86     public int compare(Object JavaDoc o1, Object JavaDoc o2) {
87         if(o1!=null && o2!=null){
88             if(o1 instanceof Class JavaDoc && o2 instanceof Class JavaDoc)
89                 return compare((Class JavaDoc)o1,(Class JavaDoc)o2);
90             else if(o1 instanceof Field JavaDoc && o2 instanceof Field JavaDoc)
91                 return compare((Field JavaDoc)o1,(Field JavaDoc)o2);
92             else if(o1 instanceof Method JavaDoc && o2 instanceof Method JavaDoc)
93                 return compare((Method JavaDoc)o1,(Method JavaDoc)o2);
94             else
95                 return 0;
96         }
97         return 0;
98     }
99
100 }
101     
Popular Tags