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