KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > js > pattern > MethodKey


1 package org.apache.ws.jaxme.js.pattern;
2
3 import org.apache.ws.jaxme.js.JavaMethod;
4 import org.apache.ws.jaxme.js.Parameter;
5
6
7 /** This class is a key for generated methods. The main
8  * purpose is to determine, whether some method is
9  * present in more than one interface. In that case
10  * we have to ensure, that it is generated only once.
11  */

12 public class MethodKey implements Comparable JavaDoc {
13     private JavaMethod method;
14
15     /** Creates a new instance of {@link MethodKey}.
16      */

17     public MethodKey(JavaMethod pMethod) {
18         method = pMethod;
19     }
20
21     /** <p>Returns whether this method key equals the object <code>o</code>.
22      * This is the case, if <code>o != null</code>,
23      * <code>o instanceof MethodKey</code>,
24      * and <code>compareTo(o) == 0</code>.</p>
25      */

26     public boolean equals(Object JavaDoc o) {
27         if (o == null || !(o instanceof MethodKey)) { return false; }
28         return compareTo(o) == 0;
29     }
30     
31     /** <p>Compares this GeneratedMethod to the given GeneratedMethod <code>o</code>.
32      * More precise, compares the method name, the number of parameters
33      * and the class names of the parameters, in that order.</p>
34      * @throws ClassCastException The object o is not an instance of MethodKey.
35      */

36     public int compareTo(Object JavaDoc o) {
37         MethodKey other = (MethodKey) o;
38         int result = method.getName().compareTo(other.method.getName());
39         if (result != 0) {
40             return result;
41         }
42         Parameter[] params = method.getParams();
43         Parameter[] oparams = other.method.getParams();
44         result = params.length - oparams.length;
45         if (result != 0) {
46             return result;
47         }
48         for (int i = 0; i < params.length; i++) {
49             result = params[i].getType().toString().compareTo(oparams[i].getType().toString());
50             if (result != 0) {
51                 return result;
52             }
53         }
54         return 0;
55     }
56     public int hashCode() {
57         int result = method.getName().hashCode();
58         Parameter[] params = method.getParams();
59         result += params.length;
60         for (int i = 0; i < params.length; i++) {
61             result += params[i].getType().toString().hashCode();
62         }
63         return result;
64     }
65 }
Popular Tags