| MethodKey.java |
1 /**
2 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions 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 */
37 public class MethodKey implements Serializable {
38
39 public MethodKey(String className, String methodName, Class<?>[] types) {
40 this(null, null, className, methodName, types);
41 }
42
43 public MethodKey(
44 Map<String, Class<?>> classesMap, Map<MethodKey, Method> methodsMap,
45 String className, String methodName, Class<?>[] types) {
46
47 _classesMap = classesMap;
48 _methodsMap = methodsMap;
49 _className = className;
50 _methodName = methodName;
51 _types = types;
52 }
53
54 public Map<String, Class<?>> getClassesMap() {
55 return _classesMap;
56 }
57
58 public Map<MethodKey, Method> getMethodsMap() {
59 return _methodsMap;
60 }
61
62 public String getClassName() {
63 return _className;
64 }
65
66 public String getMethodName() {
67 return _methodName;
68 }
69
70 public Class<?>[] getTypes() {
71 return _types;
72 }
73
74 public boolean equals(Object obj) {
75 if (obj == null) {
76 return false;
77 }
78
79 MethodKey methodKey = (MethodKey)obj;
80
81 if (toString().equals(methodKey.toString())) {
82 return true;
83 }
84 else {
85 return false;
86 }
87 }
88
89 public int hashCode() {
90 return toString().hashCode();
91 }
92
93 public String toString() {
94 return _toString();
95 }
96
97 private String _toString() {
98 if (_toString == null) {
99 StringBuilder sb = new StringBuilder();
100
101 sb.append(_className);
102 sb.append(_methodName);
103
104 if (_types != null && _types.length > 0) {
105 sb.append("-");
106
107 for (int i = 0; i < _types.length; i++) {
108 sb.append(_types[i].getClass().getName());
109 }
110 }
111
112 _toString = sb.toString();
113 }
114
115 return _toString;
116 }
117
118 private Map<String, Class<?>> _classesMap;
119 private Map<MethodKey, Method> _methodsMap;
120 private String _className;
121 private String _methodName;
122 private Class<?>[] _types;
123 private String _toString;
124
125 }