Example usage for org.springframework.util ReflectionUtils isEqualsMethod

List of usage examples for org.springframework.util ReflectionUtils isEqualsMethod

Introduction

In this page you can find the example usage for org.springframework.util ReflectionUtils isEqualsMethod.

Prototype

public static boolean isEqualsMethod(@Nullable Method method) 

Source Link

Document

Determine whether the given method is an "equals" method.

Usage

From source file:com.googlecode.ehcache.annotations.key.SimpleReflectionHelper.java

public boolean implementsEquals(Object element) {
    final MutableBoolean found = new MutableBoolean();

    ReflectionUtils.doWithMethods(element.getClass(), new MethodCallback() {
        public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
            if (found.value || method.getDeclaringClass() == Object.class) {
                return;
            }/*from  w w w .j a va2 s.c om*/

            if (ReflectionUtils.isEqualsMethod(method)) {
                found.value = true;
            }
        }
    });

    return found.value;
}

From source file:com.googlecode.ehcache.annotations.key.CachingReflectionHelper.java

/**
 * Scans a class to see if it implements the hashCode, toString and equals methods which are commonly
 * used by key generators/*  w  w w.ja v  a 2 s  . co  m*/
 */
private boolean doesImplement(final Class<?> elementClass, ImplementsMethod method) {
    final Map<Class<?>, Set<ImplementsMethod>> cache = this.getCache();
    Set<ImplementsMethod> methodCache = cache.get(elementClass);

    if (methodCache == null) {
        methodCache = EnumSet.noneOf(ImplementsMethod.class);
        cache.put(elementClass, methodCache);

        //Create final reference for use by anonymous class
        final Set<ImplementsMethod> implementsSet = methodCache;
        ReflectionUtils.doWithMethods(elementClass, new MethodCallback() {
            public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
                if (implementsSet.size() == 3 || method.getDeclaringClass() == Object.class) {
                    return;
                }

                if (ReflectionUtils.isEqualsMethod(method)) {
                    implementsSet.add(ImplementsMethod.EQUALS);
                } else if (ReflectionUtils.isHashCodeMethod(method)) {
                    implementsSet.add(ImplementsMethod.HASH_CODE);
                } else if (ReflectionUtils.isToStringMethod(method)) {
                    implementsSet.add(ImplementsMethod.TO_STRING);
                }
            }
        });
    }

    return methodCache.contains(method);
}

From source file:org.springframework.integration.handler.support.MessagingMethodInvokerHelper.java

private static boolean isMethodDefinedOnObjectClass(Method method) {
    return method != null && (method.getDeclaringClass().equals(Object.class)
            || ReflectionUtils.isEqualsMethod(method) || ReflectionUtils.isHashCodeMethod(method)
            || ReflectionUtils.isToStringMethod(method) || AopUtils.isFinalizeMethod(method)
            || (method.getName().equals("clone") && method.getParameterTypes().length == 0));
}

From source file:org.springframework.integration.util.MessagingMethodInvokerHelper.java

private static boolean isMethodDefinedOnObjectClass(Method method) {
    if (method == null) {
        return false;
    }/*from w w w.  j  a va  2 s  .  c  om*/
    if (method.getDeclaringClass().equals(Object.class)) {
        return true;
    }
    if (ReflectionUtils.isEqualsMethod(method) || ReflectionUtils.isHashCodeMethod(method)
            || ReflectionUtils.isToStringMethod(method) || AopUtils.isFinalizeMethod(method)) {
        return true;
    }
    return (method.getName().equals("clone") && method.getParameterTypes().length == 0);
}