From 043e97c9fec278c29d7f91e2077698bb914bd0a6 Mon Sep 17 00:00:00 2001 From: Phil Steitz Date: Tue, 29 Jun 2004 02:18:22 +0000 Subject: [PATCH] Implemented equals and hashcode. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@141343 13f79535-47bb-0310-9956-ffa450edef68 --- .../univariate/StatisticalSummaryValues.java | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/src/java/org/apache/commons/math/stat/univariate/StatisticalSummaryValues.java b/src/java/org/apache/commons/math/stat/univariate/StatisticalSummaryValues.java index 067743932..d8d594a3c 100644 --- a/src/java/org/apache/commons/math/stat/univariate/StatisticalSummaryValues.java +++ b/src/java/org/apache/commons/math/stat/univariate/StatisticalSummaryValues.java @@ -16,11 +16,12 @@ package org.apache.commons.math.stat.univariate; import java.io.Serializable; +import org.apache.commons.math.util.MathUtils; /** * Value object representing the results of a univariate statistical summary. * - * @version $Revision: 1.3 $ $Date: 2004/06/23 16:26:16 $ + * @version $Revision: 1.4 $ $Date: 2004/06/29 02:18:22 $ */ public class StatisticalSummaryValues implements Serializable, StatisticalSummary { @@ -72,7 +73,6 @@ public class StatisticalSummaryValues implements Serializable, super(); } - /** * @return Returns the max. */ @@ -121,5 +121,44 @@ public class StatisticalSummaryValues implements Serializable, public double getVariance() { return variance; } + + /** + * Returns true iff object is a + * StatisticalSummaryValues instance and all statistics have + * the same values as this. + * + * @param object the object to test equality against. + * @return true if object equals this + */ + public boolean equals(Object object) { + if (object == this ) { + return true; + } + if (object instanceof StatisticalSummaryValues == false) { + return false; + } + StatisticalSummaryValues stat = (StatisticalSummaryValues) object; + return (MathUtils.equals(stat.getMax(), this.getMax()) && + MathUtils.equals(stat.getMean(),this.getMean()) && + MathUtils.equals(stat.getMin(),this.getMin()) && + MathUtils.equals(stat.getN(), this.getN()) && + MathUtils.equals(stat.getSum(), this.getSum()) && + MathUtils.equals(stat.getVariance(),this.getVariance())); + } + + /** + * Returns hash code based on values of statistics + * + * @return hash code + */ + public int hashCode() { + int result = 31 + MathUtils.hash(getMax()); + result = result * 31 + MathUtils.hash(getMean()); + result = result * 31 + MathUtils.hash(getMin()); + result = result * 31 + MathUtils.hash(getN()); + result = result * 31 + MathUtils.hash(getSum()); + result = result * 31 + MathUtils.hash(getVariance()); + return result; + } }