From d4a4d302a26927b97d06d59ee21249d852f40042 Mon Sep 17 00:00:00 2001 From: Phil Steitz Date: Thu, 17 Jun 2004 22:31:58 +0000 Subject: [PATCH] Implemented equals and hashcode. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@141303 13f79535-47bb-0310-9956-ffa450edef68 --- .../AbstractStorelessUnivariateStatistic.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/java/org/apache/commons/math/stat/univariate/AbstractStorelessUnivariateStatistic.java b/src/java/org/apache/commons/math/stat/univariate/AbstractStorelessUnivariateStatistic.java index 1946b6e0e..3801d0a97 100644 --- a/src/java/org/apache/commons/math/stat/univariate/AbstractStorelessUnivariateStatistic.java +++ b/src/java/org/apache/commons/math/stat/univariate/AbstractStorelessUnivariateStatistic.java @@ -15,6 +15,7 @@ */ package org.apache.commons.math.stat.univariate; +import org.apache.commons.math.util.MathUtils; import java.io.Serializable; /** @@ -23,7 +24,7 @@ import java.io.Serializable; *

* Provides a default evaluate() implementation. * - * @version $Revision: 1.15 $ $Date: 2004/06/01 21:34:35 $ + * @version $Revision: 1.16 $ $Date: 2004/06/17 22:31:58 $ */ public abstract class AbstractStorelessUnivariateStatistic extends AbstractUnivariateStatistic @@ -66,5 +67,33 @@ public abstract class AbstractStorelessUnivariateStatistic * @see org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double) */ public abstract void increment(final double d); + + /** + * Returns true iff object is an + * AbstractStorelessUnivariateStatistic returning the same + * values as this for getResult() and getN() + * + * @return true if object returns the same value as this + */ + public boolean equals(Object object) { + if (object == this ) { + return true; + } + if (object instanceof AbstractStorelessUnivariateStatistic == false) { + return false; + } + AbstractStorelessUnivariateStatistic stat = (AbstractStorelessUnivariateStatistic) object; + return (MathUtils.equals(stat.getResult(), this.getResult()) && + MathUtils.equals(stat.getN(), this.getN())); + } + + /** + * Returns hash code based on getResult() and getN() + * + * @return hash code + */ + public int hashCode() { + return 31* (31 + MathUtils.hash(getResult())) + MathUtils.hash(getN()); + } } \ No newline at end of file