Return-Path: X-Original-To: apmail-commons-dev-archive@www.apache.org Delivered-To: apmail-commons-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 EAA0D18B3E for ; Tue, 3 Nov 2015 17:08:23 +0000 (UTC) Received: (qmail 12597 invoked by uid 500); 3 Nov 2015 17:08:23 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 12441 invoked by uid 500); 3 Nov 2015 17:08:23 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 12429 invoked by uid 99); 3 Nov 2015 17:08:23 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Nov 2015 17:08:23 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id A349AC028A for ; Tue, 3 Nov 2015 17:08:22 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.69 X-Spam-Level: X-Spam-Status: No, score=0.69 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, KAM_ASCII_DIVIDERS=0.8, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (1024-bit key) header.d=spaceroots.org Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id fYGG45P9DILL for ; Tue, 3 Nov 2015 17:08:17 +0000 (UTC) Received: from smtp.spaceroots.org (smtp.spaceroots.org [80.67.176.229]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTPS id 966B72315C for ; Tue, 3 Nov 2015 17:08:16 +0000 (UTC) Received: from [192.168.163.2] (lehrin.spaceroots.org [192.168.163.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.spaceroots.org (Postfix) with ESMTPSA id 00EA0540A9 for ; Tue, 3 Nov 2015 18:08:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=spaceroots.org; s=mail; t=1446570488; bh=mwnOt6ixdqtwaEgkDmvvaCYswV5WBSuRrwVOi45p/iI=; h=Date:From:To:Subject:References:In-Reply-To; b=INBs9LYr+oqZhG6fSJ+5QK9r7rZJ25qrFa8USdgQOV9IiFfPTo+0lGPMZBfvntTHW sd5F5M/mgRVfhQuGpStvhGFUF2NsljHYtKbRoRBopGH5M5BbhAzPAN14jIbiktvfyc 3OzMJPdtIBwELHqTJKGof0brFdmdsZ45OdI37kkA= Message-ID: <5638E9E6.8010805@spaceroots.org> Date: Tue, 03 Nov 2015 18:07:50 +0100 From: Luc Maisonobe User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.7.0 MIME-Version: 1.0 To: dev@commons.apache.org Subject: Re: [5/6] [math] Fixed findbugs warning. References: <229bd4e8035b36ca0f0ba5d78c090b2d@scarlet.be> In-Reply-To: <229bd4e8035b36ca0f0ba5d78c090b2d@scarlet.be> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Le 03/11/2015 15:33, Gilles a écrit : > On Tue, 03 Nov 2015 11:06:50 -0000, luc@apache.org wrote: >> Fixed findbugs warning. >> >> When defining compareTo, we should also define equals and hashcode. >> >> >> Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo >> Commit: >> http://git-wip-us.apache.org/repos/asf/commons-math/commit/04454fc0 >> Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/04454fc0 >> Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/04454fc0 >> >> Branch: refs/heads/MATH_3_X >> Commit: 04454fc0096d5d388e10c5b13024b2a947a4e923 >> Parents: b72d446 >> Author: Luc Maisonobe >> Authored: Tue Nov 3 11:23:46 2015 +0100 >> Committer: Luc Maisonobe >> Committed: Tue Nov 3 11:23:46 2015 +0100 >> >> >> ---------------------------------------------------------------------- >> .../commons/math3/ml/neuralnet/MapUtils.java | 24 >> +++++++++++++++++--- >> 1 file changed, 21 insertions(+), 3 deletions(-) >> >> ---------------------------------------------------------------------- >> >> >> >> http://git-wip-us.apache.org/repos/asf/commons-math/blob/04454fc0/src/main/java/org/apache/commons/math3/ml/neuralnet/MapUtils.java >> >> >> ---------------------------------------------------------------------- >> diff --git >> a/src/main/java/org/apache/commons/math3/ml/neuralnet/MapUtils.java >> b/src/main/java/org/apache/commons/math3/ml/neuralnet/MapUtils.java >> index 83036c2..6ef9327 100644 >> --- a/src/main/java/org/apache/commons/math3/ml/neuralnet/MapUtils.java >> +++ b/src/main/java/org/apache/commons/math3/ml/neuralnet/MapUtils.java >> @@ -17,14 +17,15 @@ >> >> package org.apache.commons.math3.ml.neuralnet; >> >> -import java.util.HashMap; >> +import java.util.ArrayList; >> import java.util.Collection; >> import java.util.Collections; >> +import java.util.HashMap; >> import java.util.List; >> -import java.util.ArrayList; >> + >> +import org.apache.commons.math3.exception.NoDataException; >> import org.apache.commons.math3.ml.distance.DistanceMeasure; >> import org.apache.commons.math3.ml.neuralnet.twod.NeuronSquareMesh2D; >> -import org.apache.commons.math3.exception.NoDataException; >> import org.apache.commons.math3.util.Pair; >> >> /** >> @@ -320,5 +321,22 @@ public class MapUtils { >> public int compareTo(PairNeuronDouble other) { >> return Double.compare(this.value, other.value); >> } >> + >> + /** {@inheritDoc} */ >> + @Override >> + public boolean equals(Object other) { >> + if (!(other instanceof PairNeuronDouble)) { >> + return false; >> + } >> + return Double.doubleToRawLongBits(value) == >> + Double.doubleToRawLongBits(((PairNeuronDouble) >> other).value); >> + } >> + >> + /** {@inheritDoc} */ >> + @Override >> + public int hashCode() { >> + return Double.valueOf(value).hashCode(); >> + } >> + >> } >> } > > I think that in general, it is not correct to assume pair equality > by only taking "value" into account. > I also think that the default implementation provided the correct > semantics (for the sole usage of sorting). Sure, but as the compareTo method did only use value, the equals method should be consistent with it. Otherwise, you could have compareTo return 0 when equals does not return true for example. best regards, Luc > > > Regards, > Gilles > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > For additional commands, e-mail: dev-help@commons.apache.org > > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org