Dmitry Katsubo created LANG-1696:
------------------------------------

             Summary: Add support of java collections to EqualsBuilder
                 Key: LANG-1696
                 URL: https://issues.apache.org/jira/browse/LANG-1696
             Project: Commons Lang
          Issue Type: Improvement
          Components: lang.builder.*
            Reporter: Dmitry Katsubo


Provided that new {{HashSet<>().equals(Collections.emptySet())}} it would be 
great if {{EqualsBuilder}} also supports that. Currently it checks that 
[left/right classes are subclasses of each 
other|https://github.com/apache/commons-lang/blob/master/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java#L499],
 however that does not hold for collections.

Suggestion: if either left or right is {{Collection}} or {{Map}} then delegate 
equals to
{code}
public EqualsBuilder reflectionAppend(final Object lhs, final Object rhs) {
    if (!isEquals()) {
        return this;
    }
    if (lhs == rhs) {
        return this;
    }
    if (lhs == null || rhs == null) {
        setEquals(false);
        return this;
    }

    if (lhs instanceof Collection || rhs instanceof Collection || lhs 
instanceof Map || rhs instanceof Map) {
        setEquals(lhs.equals(rhs));
        return this;
    }
    ...
{code}
Likely this mode should be additionally controlled (switched on/off), as 
strictly speaking, it won't be a reflection tree walker starting from that 
field.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to