Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-1696

Add support of java collections to EqualsBuilder

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • lang.builder.*
    • None

    Description

      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, however that does not hold for collections.

      Suggestion: if either left or right is Collection or Map then delegate equals to

      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;
          }
          ...
      

      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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            dma_k Dmitry Katsubo
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: