Implemented equals and hashcode.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@141303 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Phil Steitz 2004-06-17 22:31:58 +00:00
parent 1d37fc5fd5
commit d4a4d302a2
1 changed files with 30 additions and 1 deletions

View File

@ -15,6 +15,7 @@
*/ */
package org.apache.commons.math.stat.univariate; package org.apache.commons.math.stat.univariate;
import org.apache.commons.math.util.MathUtils;
import java.io.Serializable; import java.io.Serializable;
/** /**
@ -23,7 +24,7 @@ import java.io.Serializable;
* <p> * <p>
* Provides a default <code>evaluate()</code> implementation. * Provides a default <code>evaluate()</code> 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 public abstract class AbstractStorelessUnivariateStatistic
extends AbstractUnivariateStatistic extends AbstractUnivariateStatistic
@ -67,4 +68,32 @@ public abstract class AbstractStorelessUnivariateStatistic
*/ */
public abstract void increment(final double d); public abstract void increment(final double d);
/**
* Returns true iff <code>object</code> is an
* <code>AbstractStorelessUnivariateStatistic</code> returning the same
* values as this for <code>getResult()</code> and <code>getN()</code>
*
* @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());
}
} }