public static boolean beanEquals(Class<?> beanClass, final Object obj1, final Object obj2) {
        boolean eq;

        if (obj1 == null && obj2 == null) { // both are null
            eq = true;
        } else if (obj1 == null || obj2 == null) { // one of the objects is null
            eq = false;
        } else if (!beanClass.isInstance(obj2)) { // not of the same type
            eq = false;
        } else {
            eq = true;
            try {

                final List<PropertyDescriptor> propertyDescriptors = BeanIntrospector.getPropertyDescriptorsWithGetters(beanClass);
                for (final PropertyDescriptor propertyDescriptor : propertyDescriptors) {

                    final Method getter = propertyDescriptor.getReadMethod();

                    final Object value1 = getter.invoke(obj1, NO_PARAMS);
                    final Object value2 = getter.invoke(obj2, NO_PARAMS);

                    eq = doEquals(value1, value2);

                    if (!eq) {
                        break;
                    }

                }

            } catch (final Exception ex) {
                throw new RuntimeException("Could not execute equals()", ex);
            }

        }
        return eq;
    }
public static boolean beanEquals ( Class < ? > beanClass , final Object obj1 , final Object obj2 ) { boolean eq ; if ( obj1 == null && obj2 == null ) { eq = true ; } else if ( obj1 == null || obj2 == null ) { eq = false ; } else if ( ! beanClass . isInstance ( obj2 ) ) { eq = false ; } else { eq = true ; try { final List < PropertyDescriptor > propertyDescriptors = BeanIntrospector . getPropertyDescriptorsWithGetters ( beanClass ) ; for ( final PropertyDescriptor propertyDescriptor : propertyDescriptors ) { final Method getter = propertyDescriptor . getReadMethod ( ) ; final Object value1 = getter . invoke ( obj1 , NO_PARAMS ) ; final Object value2 = getter . invoke ( obj2 , NO_PARAMS ) ; eq = doEquals ( value1 , value2 ) ; if ( ! eq ) { break ; } } } catch ( final Exception ex ) { throw new RuntimeException ( "Could not execute equals()" , ex ) ; } } return eq ; }
Indicates whether some other object is "equal to" the object passed in the constructor, as
defined by the Object equals() method.
<p>
To be used by classes using EqualsBean in a delegation pattern,

@param obj1 The reference object with which to compare.
@param obj2 The object to which to compare.
@return <b>true</b> if the object passed in the constructor is equal to the 'obj' object.