1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.kernel.util;
24  
25  import java.io.Serializable;
26  
27  import java.lang.reflect.Method;
28  
29  import java.util.Map;
30  
31  /**
32   * <a href="MethodKey.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   */
36  public class MethodKey implements Serializable {
37  
38      public MethodKey(String className, String methodName, Class<?>[] types) {
39          this(null, null, className, methodName, types);
40      }
41  
42      public MethodKey(
43          Map<String, Class<?>> classesMap, Map<MethodKey, Method> methodsMap,
44          String className, String methodName, Class<?>[] types) {
45  
46          _classesMap = classesMap;
47          _methodsMap = methodsMap;
48          _className = className;
49          _methodName = methodName;
50          _types = types;
51      }
52  
53      public Map<String, Class<?>> getClassesMap() {
54          return _classesMap;
55      }
56  
57      public Map<MethodKey, Method> getMethodsMap() {
58          return _methodsMap;
59      }
60  
61      public String getClassName() {
62          return _className;
63      }
64  
65      public String getMethodName() {
66          return _methodName;
67      }
68  
69      public Class<?>[] getTypes() {
70          return _types;
71      }
72  
73      public boolean equals(Object obj) {
74          if (obj == null) {
75              return false;
76          }
77  
78          MethodKey methodKey = (MethodKey)obj;
79  
80          if (toString().equals(methodKey.toString())) {
81              return true;
82          }
83          else {
84              return false;
85          }
86      }
87  
88      public int hashCode() {
89          return toString().hashCode();
90      }
91  
92      public String toString() {
93          return _toString();
94      }
95  
96      private String _toString() {
97          if (_toString == null) {
98              StringBuilder sb = new StringBuilder();
99  
100             sb.append(_className);
101             sb.append(_methodName);
102 
103             if (_types != null && _types.length > 0) {
104                 sb.append("-");
105 
106                 for (int i = 0; i < _types.length; i++) {
107                     sb.append(_types[i].getClass().getName());
108                 }
109             }
110 
111             _toString = sb.toString();
112         }
113 
114         return _toString;
115     }
116 
117     private Map<String, Class<?>> _classesMap;
118     private Map<MethodKey, Method> _methodsMap;
119     private String _className;
120     private String _methodName;
121     private Class<?>[] _types;
122     private String _toString;
123 
124 }