下面列出了java.lang.reflect.Method#equals ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public Boolean run() {
Method[] methods = immutableClass.getMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
String methodName = method.getName();
if (methodName.startsWith("get") &&
method.getParameterTypes().length == 0 &&
method.getReturnType().isArray()) {
try {
Method submethod =
subclass.getMethod(methodName);
if (!submethod.equals(method))
return false;
} catch (NoSuchMethodException e) {
return false;
}
}
}
return true;
}
public Boolean run() {
Method[] methods = immutableClass.getMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
String methodName = method.getName();
if (methodName.startsWith("get") &&
method.getParameterTypes().length == 0 &&
method.getReturnType().isArray()) {
try {
Method submethod =
subclass.getMethod(methodName);
if (!submethod.equals(method))
return false;
} catch (NoSuchMethodException e) {
return false;
}
}
}
return true;
}
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
if (method.equals(Disposable.class.getDeclaredMethods()[0])) {
if (delegateUsed && instance != null) {
proxied.dispose(instance);
instance = null;
delegateUsed = false;
}
return null;
}
final EntityManager oldInstance = instance;
instance = EntityManagerHolder.INSTANCE.getEntityManager();
if (instance == null && oldInstance == null) {
instance = proxied.produce(ctx);
delegateUsed = true;
} else if (instance == null) {
instance = oldInstance;
}
return method.invoke(instance, args);
}
public Boolean run() {
Method[] methods = immutableClass.getMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
String methodName = method.getName();
if (methodName.startsWith("get") &&
method.getParameterTypes().length == 0 &&
method.getReturnType().isArray()) {
try {
Method submethod =
subclass.getMethod(methodName);
if (!submethod.equals(method))
return false;
} catch (NoSuchMethodException e) {
return false;
}
}
}
return true;
}
public Boolean run() {
Method[] methods = immutableClass.getMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
String methodName = method.getName();
if (methodName.startsWith("get") &&
method.getParameterTypes().length == 0 &&
method.getReturnType().isArray()) {
try {
Method submethod =
subclass.getMethod(methodName);
if (!submethod.equals(method))
return false;
} catch (NoSuchMethodException e) {
return false;
}
}
}
return true;
}
/** Returns whether the supplied cache loader has bulk load functionality. */
private static boolean canBulkLoad(AsyncCacheLoader<?, ?> loader) {
try {
Class<?> defaultLoaderClass = AsyncCacheLoader.class;
if (loader instanceof CacheLoader<?, ?>) {
defaultLoaderClass = CacheLoader.class;
Method classLoadAll = loader.getClass().getMethod("loadAll", Iterable.class);
Method defaultLoadAll = CacheLoader.class.getMethod("loadAll", Iterable.class);
if (!classLoadAll.equals(defaultLoadAll)) {
return true;
}
}
Method classAsyncLoadAll = loader.getClass().getMethod(
"asyncLoadAll", Iterable.class, Executor.class);
Method defaultAsyncLoadAll = defaultLoaderClass.getMethod(
"asyncLoadAll", Iterable.class, Executor.class);
return !classAsyncLoadAll.equals(defaultAsyncLoadAll);
} catch (NoSuchMethodException | SecurityException e) {
logger.log(Level.WARNING, "Cannot determine if CacheLoader can bulk load", e);
return false;
}
}
private static boolean compare(Method m1, Method m2) {
if ((m1 == null) && (m2 == null)) {
return true;
}
if ((m1 == null) || (m2 == null)) {
return false;
}
return m1.equals(m2);
}
/**
* Package private helper method for Descriptor .equals methods.
*
* @param a first method to compare
* @param b second method to compare
* @return boolean to indicate that the methods are equivalent
*/
boolean compareMethods(Method a, Method b) {
// Note: perhaps this should be a protected method in FeatureDescriptor
if ((a == null) != (b == null)) {
return false;
}
if (a != null && b != null) {
if (!a.equals(b)) {
return false;
}
}
return true;
}
boolean match(Method method, Class<?> targetClass) {
// origin
if (doMatch(method, targetClass)) {
return true;
}
// cglib
Class<?> userClass = ClassUtils.getUserClass(targetClass);
Method specificMethod = ClassUtils.getMostSpecificMethod(method, userClass);
specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
if (!specificMethod.equals(method)) {
if (doMatch(specificMethod, userClass)) {
return true;
}
}
// jdk proxy
if (Proxy.isProxyClass(targetClass)) {
Class<?>[] interfaces = targetClass.getInterfaces();
for (Class<?> interfaceClass : interfaces) {
Method interfaceMethod = ClassUtils.getMethodIfAvailable(interfaceClass, method.getName(),
method.getParameterTypes());
if (interfaceMethod != null && doMatch(interfaceMethod, interfaceClass)) {
return true;
}
}
}
return false;
}
private boolean declaredMethodsContains() {
for(Method m : clazz.getClazz().getDeclaredMethods()) {
if(m.equals(method.method)) {
return true;
}
}
return false;
}
public String methodToProperty(Method m) {
PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors(m.getDeclaringClass());
for (PropertyDescriptor pd : pds) {
if (m.equals(pd.getReadMethod()) || m.equals(pd.getWriteMethod())) {
return pd.getName();
}
}
return null;
}
private static void verifyOneInvocation(Method method, Object[] args,
List invocationQueue)
{
TestProvider.Invocation inv =
(TestProvider.Invocation) invocationQueue.remove(0);
if (!method.equals(inv.method)) {
throw new RuntimeException(
"unexpected provider method invoked: expected " + method +
", detected " + inv.method);
}
List expectedArgs = Arrays.asList(args);
List detectedArgs = Arrays.asList(inv.args);
if (!expectedArgs.equals(detectedArgs)) {
throw new RuntimeException("TEST FAILED: " +
"unexpected provider method invocation arguments: " +
"expected " + expectedArgs + ", detected " + detectedArgs);
}
if (!invocationQueue.isEmpty()) {
inv = (TestProvider.Invocation)
invocationQueue.remove(0);
throw new RuntimeException("TEST FAILED: " +
"unexpected provider invocation: " + inv.method + " " +
Arrays.asList(inv.args));
}
}
void addIfNotPresent(Method newMethod) {
for (int i = 0; i < length; i++) {
Method m = methods[i];
if (m == newMethod || (m != null && m.equals(newMethod))) {
return;
}
}
add(newMethod);
}
void addIfNotPresent(Method newMethod) {
for (int i = 0; i < length; i++) {
Method m = methods[i];
if (m == newMethod || (m != null && m.equals(newMethod))) {
return;
}
}
add(newMethod);
}
private static boolean overridesMethod(Class<? extends Trigger> triggerClass, Method method) {
try {
return !method.equals(triggerClass.getMethod(method.getName(),
method.getParameterTypes()));
} catch (NoSuchMethodException e) {
return false;
}
}
private void assertActionNotDuplicated(Map<ActionKey, ActionMethod> map, ActionKey actionKey, Method method) {
if (map.get(actionKey) != null) {
Method existingMethod = map.get(actionKey).getMethod();
if (method.equals(existingMethod)) {
return;
}
throw new RuntimeException("Trying to add two actions with the same name '" + actionKey + "' to "
+ endpointClazz.getName() + ": one at " + existingMethod.getDeclaringClass().getName() + " and the other at "
+ method.getDeclaringClass().getName());
}
}
private void addExceptionMapping(Class<? extends Throwable> exceptionType, Method method) {
Method oldMethod = this.mappedMethods.put(exceptionType, method);
if (oldMethod != null && !oldMethod.equals(method)) {
throw new IllegalStateException("Ambiguous @ExceptionHandler method mapped for [" +
exceptionType + "]: {" + oldMethod + ", " + method + "}");
}
}
/**
* Package private helper method for Descriptor .equals methods.
*
* @param a first method to compare
* @param b second method to compare
* @return boolean to indicate that the methods are equivalent
*/
boolean compareMethods(Method a, Method b) {
// Note: perhaps this should be a protected method in FeatureDescriptor
if ((a == null) != (b == null)) {
return false;
}
if (a != null && b != null) {
if (!a.equals(b)) {
return false;
}
}
return true;
}
public GenericTypeAwarePropertyDescriptor(Class<?> beanClass, String propertyName,
@Nullable Method readMethod, @Nullable Method writeMethod, Class<?> propertyEditorClass)
throws IntrospectionException {
super(propertyName, null, null);
this.beanClass = beanClass;
Method readMethodToUse = (readMethod != null ? BridgeMethodResolver.findBridgedMethod(readMethod) : null);
Method writeMethodToUse = (writeMethod != null ? BridgeMethodResolver.findBridgedMethod(writeMethod) : null);
if (writeMethodToUse == null && readMethodToUse != null) {
// Fallback: Original JavaBeans introspection might not have found matching setter
// method due to lack of bridge method resolution, in case of the getter using a
// covariant return type whereas the setter is defined for the concrete property type.
Method candidate = ClassUtils.getMethodIfAvailable(
this.beanClass, "set" + StringUtils.capitalize(getName()), (Class<?>[]) null);
if (candidate != null && candidate.getParameterCount() == 1) {
writeMethodToUse = candidate;
}
}
this.readMethod = readMethodToUse;
this.writeMethod = writeMethodToUse;
if (this.writeMethod != null) {
if (this.readMethod == null) {
// Write method not matched against read method: potentially ambiguous through
// several overloaded variants, in which case an arbitrary winner has been chosen
// by the JDK's JavaBeans Introspector...
Set<Method> ambiguousCandidates = new HashSet<>();
for (Method method : beanClass.getMethods()) {
if (method.getName().equals(writeMethodToUse.getName()) &&
!method.equals(writeMethodToUse) && !method.isBridge() &&
method.getParameterCount() == writeMethodToUse.getParameterCount()) {
ambiguousCandidates.add(method);
}
}
if (!ambiguousCandidates.isEmpty()) {
this.ambiguousWriteMethods = ambiguousCandidates;
}
}
this.writeMethodParameter = new MethodParameter(this.writeMethod, 0);
GenericTypeResolver.resolveParameterType(this.writeMethodParameter, this.beanClass);
}
if (this.readMethod != null) {
this.propertyType = GenericTypeResolver.resolveReturnType(this.readMethod, this.beanClass);
}
else if (this.writeMethodParameter != null) {
this.propertyType = this.writeMethodParameter.getParameterType();
}
this.propertyEditorClass = propertyEditorClass;
}
/**
* Returns {@code true} if the supplied '{@code candidateMethod}' can be
* consider a validate candidate for the {@link Method} that is {@link Method#isBridge() bridged}
* by the supplied {@link Method bridge Method}. This method performs inexpensive
* checks and can be used quickly filter for a set of possible matches.
*/
private static boolean isBridgedCandidateFor(Method candidateMethod, Method bridgeMethod) {
return (!candidateMethod.isBridge() && !candidateMethod.equals(bridgeMethod) &&
candidateMethod.getName().equals(bridgeMethod.getName()) &&
candidateMethod.getParameterTypes().length == bridgeMethod.getParameterTypes().length);
}