001
014
015 package com.liferay.portal.monitoring.jmx;
016
017 import com.liferay.portal.kernel.util.HashUtil;
018
019 import java.lang.reflect.Method;
020
021
024 public class MethodSignature {
025
026 public MethodSignature(Method method) {
027 Class<?> clazz = method.getDeclaringClass();
028
029 _className = clazz.getName();
030
031 _methodName = method.getName();
032
033 Class<?>[] parameterTypes = method.getParameterTypes();
034
035 _parameterTypeNames = new String[parameterTypes.length];
036
037 for (int i = 0; i < parameterTypes.length; i++) {
038 _parameterTypeNames[i] = parameterTypes[i].getName();
039 }
040 }
041
042 public MethodSignature(
043 String className, String methodName, String[] parameterTypeNames) {
044
045 _className = className;
046 _methodName = methodName;
047 _parameterTypeNames = parameterTypeNames;
048 }
049
050 @Override
051 public boolean equals(Object obj) {
052 if (this == obj) {
053 return true;
054 }
055
056 if (!(obj instanceof MethodSignature)) {
057 return false;
058 }
059
060 MethodSignature methodSignature = (MethodSignature)obj;
061
062 if (_className.equals(methodSignature._className) &&
063 _methodName.equals(methodSignature._methodName) &&
064 (_parameterTypeNames.length ==
065 methodSignature._parameterTypeNames.length)) {
066
067 for (int i = 0; i < _parameterTypeNames.length; i++) {
068 if (!_parameterTypeNames[i].equals(
069 methodSignature._parameterTypeNames[i])) {
070
071 return false;
072 }
073 }
074
075 return true;
076 }
077
078 return false;
079 }
080
081 public String getClassName() {
082 return _className;
083 }
084
085 public String getMethodName() {
086 return _methodName;
087 }
088
089 public String[] getParameterTypeNames() {
090 return _parameterTypeNames;
091 }
092
093 @Override
094 public int hashCode() {
095 int hashCode = HashUtil.hash(0, _className);
096
097 hashCode = HashUtil.hash(hashCode, _methodName);
098
099 for (String parameterTypeName : _parameterTypeNames) {
100 hashCode = HashUtil.hash(hashCode, parameterTypeName);
101 }
102
103 return hashCode;
104 }
105
106 private String _className;
107 private String _methodName;
108 private String[] _parameterTypeNames;
109
110 }