commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject cvs commit: jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate AbstractStorelessUnivariateStatistic.java
Date Thu, 17 Jun 2004 22:31:58 GMT
psteitz     2004/06/17 15:31:58

  Modified:    math/src/java/org/apache/commons/math/stat/univariate
                        AbstractStorelessUnivariateStatistic.java
  Log:
  Implemented equals and hashcode.
  
  Revision  Changes    Path
  1.16      +30 -1     jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/AbstractStorelessUnivariateStatistic.java
  
  Index: AbstractStorelessUnivariateStatistic.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/AbstractStorelessUnivariateStatistic.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- AbstractStorelessUnivariateStatistic.java	1 Jun 2004 21:34:35 -0000	1.15
  +++ AbstractStorelessUnivariateStatistic.java	17 Jun 2004 22:31:58 -0000	1.16
  @@ -15,6 +15,7 @@
    */
   package org.apache.commons.math.stat.univariate;
   
  +import org.apache.commons.math.util.MathUtils;
   import java.io.Serializable;
   
   /**
  @@ -66,5 +67,33 @@
        * @see org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double)
        */
       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());
  +    }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message