KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > core > MethodKey


1 // You can redistribute this software and/or modify it under the terms of
2

3 // the Ozone Core License version 1 published by ozone-db.org.
4

5 //
6

7 // The original code and portions created by SMB are
8

9 // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
10

11 //
12

13 // $Id: MethodKey.java,v 1.5 2003/11/01 18:34:36 ohlrogge Exp $
14

15
16
17 package org.ozoneDB.core;
18
19
20
21 import org.ozoneDB.DxLib.DxCompatible;
22
23 import org.ozoneDB.DxLib.DxObject;
24
25
26
27 import java.lang.reflect.Method JavaDoc;
28
29
30
31
32
33 /**
34
35  * Objects of this class are the keys in the method cache table of the
36
37  * {@link AbstractObjectContainer}. This class implements the way we map from
38
39  * class+methodName+sig to the actual method. This is very important for the
40
41  * overall peformance of ozone. Besides this class is used to sort method
42
43  * arrays.
44
45  *
46
47  *
48
49  * @author <a HREF="http://www.softwarebuero.de/">SMB</a>
50
51  * @version $Revision: 1.5 $Date: 2003/11/01 18:34:36 $
52
53  */

54
55 public final class MethodKey implements Comparable JavaDoc
56
57 {
58
59     protected String JavaDoc methodName;
60
61
62
63     protected String JavaDoc sig;
64
65
66
67     protected String JavaDoc className;
68
69
70
71     protected Method JavaDoc method;
72
73
74
75
76
77     public MethodKey( String JavaDoc _className, String JavaDoc _methodName, String JavaDoc _sig ) {
78
79         this( _className, _methodName, _sig, null );
80
81     }
82
83
84
85
86
87     public MethodKey( String JavaDoc _className, String JavaDoc _methodName, String JavaDoc _sig, Method JavaDoc _method ) {
88
89         className = _className;
90
91         methodName = _methodName;
92
93         sig = _sig;
94
95         method = _method;
96
97     }
98
99
100
101
102
103     public Method JavaDoc method() {
104
105         return method;
106
107     }
108
109
110
111
112
113     public int hashCode() {
114
115         return methodName.hashCode() ^ sig.hashCode();
116
117     }
118
119
120
121
122
123     public boolean equals( Object JavaDoc obj ) {
124
125         MethodKey rhs = (MethodKey)obj;
126
127         return className.equals( rhs.className ) && sig.equals( rhs.sig ) && methodName.equals( rhs.methodName );
128
129     }
130
131   public String JavaDoc toString() {
132
133
134     return className + "." + methodName + "(" + sig + ")";
135
136   }
137
138   public int compareTo(Object JavaDoc o) {
139     MethodKey rhs = (MethodKey) o;
140
141
142
143         // this method is just used to sort a method array, so it doesn't
144

145         // need to be that fast...
146

147         StringBuffer JavaDoc buf = new StringBuffer JavaDoc( className );
148
149         buf.append( methodName );
150
151         buf.append( sig );
152
153
154
155         StringBuffer JavaDoc rhsBuf = new StringBuffer JavaDoc( rhs.className );
156
157         rhsBuf.append( rhs.methodName );
158
159         rhsBuf.append( rhs.sig );
160
161
162
163     return buf.toString().compareTo(rhsBuf.toString());
164
165     }
166 }
Popular Tags