Details
-
Improvement
-
Status: Open
-
Trivial
-
Resolution: Unresolved
-
3.5
-
None
-
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(); }