Return-Path: Delivered-To: apmail-commons-commits-archive@locus.apache.org Received: (qmail 20754 invoked from network); 8 Feb 2008 11:23:14 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 8 Feb 2008 11:23:14 -0000 Received: (qmail 47787 invoked by uid 500); 8 Feb 2008 11:23:05 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 47695 invoked by uid 500); 8 Feb 2008 11:23:04 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 47680 invoked by uid 99); 8 Feb 2008 11:23:04 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Feb 2008 03:23:04 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Feb 2008 11:22:34 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8C8C31A9832; Fri, 8 Feb 2008 03:22:41 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r619836 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/util/MathUtils.java site/xdoc/changes.xml test/org/apache/commons/math/util/MathUtilsTest.java Date: Fri, 08 Feb 2008 11:22:40 -0000 To: commits@commons.apache.org From: luc@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080208112241.8C8C31A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: luc Date: Fri Feb 8 03:22:35 2008 New Revision: 619836 URL: http://svn.apache.org/viewvc?rev=619836&view=rev Log: added equals and hash methods for double arrays (supporting null) in MathUtils Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java commons/proper/math/trunk/src/site/xdoc/changes.xml commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java?rev=619836&r1=619835&r2=619836&view=diff ============================================================================== --- commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java (original) +++ commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java Fri Feb 8 03:22:35 2008 @@ -276,6 +276,30 @@ } /** + * Returns true iff both arguments aren null or have same dimensions + * and all their elements are {@link #equals(double,double) equals} + * + * @param x first array + * @param y second array + * @return true if the values are both null or have same dimension + * and equal elements + */ + public static boolean equals(double[] x, double[] y) { + if ((x == null) || (y == null)) { + return !((x == null) ^ (y == null)); + } + if (x.length != y.length) { + return false; + } + for (int i = 0; i < x.length; ++i) { + if (!equals(x[i], y[i])) { + return false; + } + } + return true; + } + + /** * Returns n!. Shorthand for n Factorial, the * product of the numbers 1,...,n. @@ -430,6 +454,23 @@ public static int hash(double value) { long bits = Double.doubleToLongBits(value); return (int)(bits ^ (bits >>> 32)); + } + + /** + * Returns an integer hash code representing the given double array value. + * + * @param value the value to be hashed (may be null) + * @return the hash code + */ + public static int hash(double[] value) { + if (value == null) { + return 0; + } + int result = value.length; + for (int i = 0; i < value.length; ++i) { + result = result * 31 + hash(value[i]); + } + return result; } /** Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=619836&r1=619835&r2=619836&view=diff ============================================================================== --- commons/proper/math/trunk/src/site/xdoc/changes.xml (original) +++ commons/proper/math/trunk/src/site/xdoc/changes.xml Fri Feb 8 03:22:35 2008 @@ -143,6 +143,9 @@ Throw EOFException when using empty files with ValueServer in replay and digest modes. + + Added a equals and hash methods in MathUtils to check for double arrays +