1
14
15 package com.liferay.portal.kernel.util;
16
17 import java.lang.reflect.Method;
18
19
25 public class MethodTargetClassKey {
26
27 public MethodTargetClassKey(Method method, Class<?> targetClass) {
28 _method = method;
29 _targetClass = targetClass;
30 }
31
32 public boolean equals(Object obj) {
33 if (this == obj) {
34 return true;
35 }
36
37 if (!(obj instanceof MethodTargetClassKey)) {
38 return false;
39 }
40
41 MethodTargetClassKey methodTargetClassKey = (MethodTargetClassKey)obj;
42
43 if (_targetClass == methodTargetClassKey._targetClass &&
44 Validator.equals(_method, methodTargetClassKey._method)) {
45
46 return true;
47 }
48
49 return false;
50 }
51
52 public Method getMethod() {
53 return _method;
54 }
55
56 public Class<?> getTargetClass() {
57 return _targetClass;
58 }
59
60 public Method getTargetMethod() {
61 if (_targetMethod == null && _targetClass != null) {
62 try {
63 _targetMethod = _targetClass.getDeclaredMethod(
64 _method.getName(), _method.getParameterTypes());
65 }
66 catch (Throwable t) {
67 }
68 }
69
70 return _targetMethod;
71 }
72
73 public int hashCode() {
74 if (_hashCode == 0) {
75 int hashCode = 77;
76
77 if (_method != null) {
78 hashCode += _method.hashCode();
79 }
80
81 hashCode = 11 * hashCode;
82
83 if (_targetClass != null) {
84 hashCode += _targetClass.hashCode();
85 }
86
87 _hashCode = hashCode;
88 }
89
90 return _hashCode;
91 }
92
93 public String toString() {
94 if (_toString == null) {
95 Class<?>[] parameterTypes = _method.getParameterTypes();
96
97 StringBundler sb = new StringBundler(parameterTypes.length * 2 + 6);
98
99 sb.append(_method.getDeclaringClass().getName());
100 sb.append(StringPool.PERIOD);
101 sb.append(_method.getName());
102 sb.append(StringPool.OPEN_PARENTHESIS);
103
104 for (int i = 0; i < parameterTypes.length; i++) {
105 sb.append(parameterTypes[i].getName());
106
107 if ((i + 1) < parameterTypes.length) {
108 sb.append(StringPool.COMMA);
109 }
110 }
111
112 sb.append(StringPool.CLOSE_PARENTHESIS);
113
114 if (_targetClass != null) {
115 sb.append(StringPool.AT);
116 sb.append(_targetClass.getName());
117 }
118
119 _toString = sb.toString();
120 }
121
122 return _toString;
123 }
124
125 private int _hashCode;
126 private Method _method;
127 private Class<?> _targetClass;
128 private Method _targetMethod;
129 private String _toString;
130
131 }