private static boolean areEquals()

in src/main/java/org/apache/sling/feature/diff/impl/ConfigurationsComparator.java [114:157]


    private static boolean areEquals(Object lhs, Object rhs) {
        if (lhs == rhs) {
            return true;
        }

        if (lhs == null ^ rhs == null) {
            return false;
        }

        // Find the leaf class since there may be transients in the leaf
        // class or in classes between the leaf and root.
        // If we are not testing transients or a subclass has no ivars,
        // then a subclass can test equals to a superclass.
        final Class<?> lhsClass = lhs.getClass();
        final Class<?> rhsClass = rhs.getClass();
        Class<?> testClass;

        if (lhsClass.isInstance(rhs)) {
            testClass = lhsClass;
            if (!rhsClass.isInstance(lhs)) {
                // rhsClass is a subclass of lhsClass
                testClass = rhsClass;
            }
        } else if (rhsClass.isInstance(lhs)) {
            testClass = rhsClass;
            if (!lhsClass.isInstance(rhs)) {
                // lhsClass is a subclass of rhsClass
                testClass = lhsClass;
            }
        } else {
            // The two classes are not related.
            return false;
        }

        if (testClass.isArray()) {
            return deepEquals(lhs, rhs);
        } else if (Collection.class.isAssignableFrom(testClass)) {
            return areEquals((Collection<?>) lhs, (Collection<?>) rhs);
        } else if (Map.class.isAssignableFrom(testClass)) {
            return areEquals((Map<?, ?>) lhs, (Map<?, ?>) rhs);
        }

        return Objects.equals(lhs, rhs);
    }