KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > reflect > plugins > javassist > SignatureKey


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software 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 software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.reflect.plugins.javassist;
23
24 import org.jboss.reflect.spi.TypeInfo;
25 import org.jboss.util.JBossStringBuilder;
26
27
28 /**
29  * SignatureKey.
30  *
31  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
32  * @version $Revision: 41318 $
33  */

34 class SignatureKey
35 {
36    /** The name */
37    String JavaDoc name;
38    
39    /** The parameter names */
40    String JavaDoc[] params;
41
42    /** The cached hashcode */
43    private transient int cachedHashCode = Integer.MIN_VALUE;
44    
45    /**
46     * Create a new SignatureKey.
47     *
48     * @param name the name
49     * @param typeInfos the type infos
50     */

51    public SignatureKey(String JavaDoc name, TypeInfo[] typeInfos)
52    {
53       this.name = name;
54       if (typeInfos != null && typeInfos.length > 0)
55       {
56          params = new String JavaDoc[typeInfos.length];
57          for (int i = 0; i < typeInfos.length; ++i)
58             params[i] = typeInfos[i].getName();
59       }
60    }
61    
62    /**
63     * Create a new SignatureKey.
64     *
65     * @param name the name
66     * @param params the params
67     */

68    public SignatureKey(String JavaDoc name, String JavaDoc[] params)
69    {
70       this.name = name;
71       this.params = params;
72    }
73    
74    public boolean equals(Object JavaDoc obj)
75    {
76       if (obj == this)
77          return true;
78       if (obj == null || obj instanceof SignatureKey == false)
79          return false;
80       
81       SignatureKey other = (SignatureKey) obj;
82       
83       if (name == null && other.name != null)
84          return false;
85       if (name != null && other.name == null)
86          return false;
87       if (name != null && name.equals(other.name) == false)
88          return false;
89       
90       if (params == null && other.params == null)
91          return true;
92       if (params == null && other.params != null)
93          return false;
94       if (params != null && other.params == null)
95          return false;
96       
97       if (params.length != other.params.length)
98          return false;
99       
100       for (int i = 0; i < params.length; ++i)
101       {
102          if (params[i].equals(other.params[i]) == false)
103             return false;
104       }
105       return true;
106    }
107    
108    public int hashCode()
109    {
110       if (cachedHashCode == Integer.MIN_VALUE)
111       {
112          JBossStringBuilder builder = new JBossStringBuilder();
113          if (name != null)
114             builder.append(name);
115          if (params != null)
116          {
117             for (int i = 0; i < params.length; ++i)
118                builder.append(params[i]);
119          }
120          cachedHashCode = builder.toString().hashCode();
121       }
122       return cachedHashCode;
123    }
124 }
125
Popular Tags