Return-Path: X-Original-To: apmail-lucene-dev-archive@www.apache.org Delivered-To: apmail-lucene-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0F3479ABD for ; Wed, 15 Feb 2012 17:15:28 +0000 (UTC) Received: (qmail 39797 invoked by uid 500); 15 Feb 2012 17:15:26 -0000 Delivered-To: apmail-lucene-dev-archive@lucene.apache.org Received: (qmail 39745 invoked by uid 500); 15 Feb 2012 17:15:26 -0000 Mailing-List: contact dev-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list dev@lucene.apache.org Received: (qmail 39737 invoked by uid 99); 15 Feb 2012 17:15:26 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Feb 2012 17:15:26 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Feb 2012 17:15:20 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 7390E1B915D for ; Wed, 15 Feb 2012 17:14:59 +0000 (UTC) Date: Wed, 15 Feb 2012 17:14:59 +0000 (UTC) From: "Chantal Ackermann (Updated) (JIRA)" To: dev@lucene.apache.org Message-ID: <495633749.41163.1329326099474.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <1954432923.41155.1329325859655.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Updated] (SOLR-3136) FacetField and Count : Override equals() and hashCode() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/SOLR-3136?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Chantal Ackermann updated SOLR-3136: ------------------------------------ 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: {code:java} 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(); } {code} For Count compare FacetField, name and count: {code:java} 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(); } {code} was: 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(); } > FacetField and Count : Override equals() and hashCode() > ------------------------------------------------------- > > Key: SOLR-3136 > URL: https://issues.apache.org/jira/browse/SOLR-3136 > Project: Solr > Issue Type: Improvement > Components: clients - java > Affects Versions: 3.5 > Reporter: Chantal Ackermann > Priority: Trivial > > 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: > {code:java} > 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(); > } > {code} > For Count compare FacetField, name and count: > {code:java} > 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(); > } > {code} -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org For additional commands, e-mail: dev-help@lucene.apache.org