Solr
  1. Solr
  2. SOLR-3136

FacetField and Count : Override equals() and hashCode()

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Trivial Trivial
    • Resolution: Unresolved
    • Affects Version/s: 3.5
    • Fix Version/s: None
    • Component/s: clients - java
    • Labels:
      None

      Description

      Overriding equals() and hashCode() of FacetField and Count to provide equality based on content (on their properties) would allow using these classes in sets and as keys in maps.

      Implementation via commons-lang (which is already a dependency) should be fairly straight forward?

      For FacetFields, compare name, gap and end but not the list of counts:

      public boolean equals(Object o) {
        if (o != null && o instanceof FacetField) {
          FacetField ff = (FacetField)o;
          return new EqualsBuilder().append(_name, ff._name).append(_gap, ff._gap).append(_end, ff._end).isEquals();
        }
        return false;
      }
      
      public int hashCode() {
        return new HashCodeBuilder(33,11).append(_name).append(_gap).append(_end).toHashCode();
      }
      

      For Count compare FacetField, name and count:

      public boolean equals(Object o) {
        if (o != null && o instanceof Count) {
          Count c = (Count)o;
          return new EqualsBuilder().append(_ff, c._ff).append(_name, c._name).append(_count, c._count).isEquals();
        }
        return false;
      }
      
      public int hashCode() {
        return new HashCodeBuilder(35,17).append(_ff).append(_name).append(_count).toHashCode();
      }
      

        Activity

        No work has yet been logged on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            Chantal Ackermann
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:

              Development