001
014
015 package com.liferay.portal.kernel.util;
016
017 import java.lang.reflect.Method;
018
019 import java.util.Objects;
020
021
026 @Deprecated
027 public class MethodTargetClassKey {
028
029 public MethodTargetClassKey(Method method, Class<?> targetClass) {
030 _method = method;
031 _targetClass = targetClass;
032 }
033
034 @Override
035 public boolean equals(Object obj) {
036 if (this == obj) {
037 return true;
038 }
039
040 if (!(obj instanceof MethodTargetClassKey)) {
041 return false;
042 }
043
044 MethodTargetClassKey methodTargetClassKey = (MethodTargetClassKey)obj;
045
046 if ((_targetClass == methodTargetClassKey._targetClass) &&
047 Objects.equals(_method, methodTargetClassKey._method)) {
048
049 return true;
050 }
051
052 return false;
053 }
054
055 public Method getMethod() {
056 return _method;
057 }
058
059 public Class<?> getTargetClass() {
060 return _targetClass;
061 }
062
063 public Method getTargetMethod() {
064 if ((_targetMethod == null) && (_targetClass != null)) {
065 try {
066 _targetMethod = _targetClass.getDeclaredMethod(
067 _method.getName(), _method.getParameterTypes());
068 }
069 catch (Throwable t) {
070 }
071 }
072
073 return _targetMethod;
074 }
075
076 @Override
077 public int hashCode() {
078 if (_hashCode == 0) {
079 int hashCode = 77;
080
081 if (_method != null) {
082 hashCode += _method.hashCode();
083 }
084
085 hashCode = 11 * hashCode;
086
087 if (_targetClass != null) {
088 String targetClassName = _targetClass.getName();
089
090 hashCode += targetClassName.hashCode();
091 }
092
093 _hashCode = hashCode;
094 }
095
096 return _hashCode;
097 }
098
099 @Override
100 public String toString() {
101 if (_toString != null) {
102 return _toString;
103 }
104
105 Class<?>[] parameterTypes = _method.getParameterTypes();
106
107 StringBundler sb = new StringBundler(parameterTypes.length * 2 + 6);
108
109 sb.append(_method.getDeclaringClass().getName());
110 sb.append(StringPool.PERIOD);
111 sb.append(_method.getName());
112 sb.append(StringPool.OPEN_PARENTHESIS);
113
114 for (int i = 0; i < parameterTypes.length; i++) {
115 sb.append(parameterTypes[i].getName());
116
117 if ((i + 1) < parameterTypes.length) {
118 sb.append(StringPool.COMMA);
119 }
120 }
121
122 sb.append(StringPool.CLOSE_PARENTHESIS);
123
124 if (_targetClass != null) {
125 sb.append(StringPool.AT);
126 sb.append(_targetClass.getName());
127 }
128
129 _toString = sb.toString();
130
131 return _toString;
132 }
133
134 private int _hashCode;
135 private final Method _method;
136 private Class<?> _targetClass;
137 private Method _targetMethod;
138 private String _toString;
139
140 }