Example usage for org.springframework.util ReflectionUtils isHashCodeMethod

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

Introduction

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

Prototype

public static boolean isHashCodeMethod(@Nullable Method method) 

Source Link

Document

Determine whether the given method is a "hashCode" method.

Usage

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

public boolean implementsHashCode(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;
            }/* ww w  .  j  av a 2s. c  om*/

            if (ReflectionUtils.isHashCodeMethod(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/*  ww  w  . jav  a2s .  c  o 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  va2 s.c o  m
    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);
}