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 SummaryStatistics.java
Date Thu, 17 Jun 2004 23:14:55 GMT
psteitz     2004/06/17 16:14:55

  Modified:    math/src/java/org/apache/commons/math/stat/univariate
                        SummaryStatistics.java
  Log:
  Implemented equals and hashcode, making summaries with identical statistics equal.
  
  Revision  Changes    Path
  1.8       +45 -1     jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/SummaryStatistics.java
  
  Index: SummaryStatistics.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/SummaryStatistics.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SummaryStatistics.java	14 Jun 2004 23:26:53 -0000	1.7
  +++ SummaryStatistics.java	17 Jun 2004 23:14:55 -0000	1.8
  @@ -18,6 +18,7 @@
   import java.io.Serializable;
   
   import org.apache.commons.discovery.tools.DiscoverClass;
  +import org.apache.commons.math.util.MathUtils;
   
   /**
    * Abstract factory class for univariate statistical summaries.
  @@ -157,5 +158,48 @@
        * Resets all statistics
        */
       public abstract void clear();
  +    
  +    /**
  +     * Returns true iff <code>object</code> is a <code>SummaryStatistics</code>
  +     * instance and all statistics have the same values as this.
  +     *
  +     * @return true if object equals this
  +     */
  +    public boolean equals(Object object) {
  +        if (object == this ) {
  +            return true;
  +        }
  +        if (object instanceof SummaryStatistics == false) {
  +            return false;
  +        }
  +        SummaryStatistics stat = (SummaryStatistics) object;
  +        return (MathUtils.equals(stat.getGeometricMean(), 
  +                this.getGeometricMean()) &&
  +                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.getSumsq(),this.getSumsq()) &&
  +                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(getGeometricMean());
  +        result = result * 31 + MathUtils.hash(getGeometricMean());
  +        result = 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(getSumsq());
  +        result = result * 31 + MathUtils.hash(getVariance());
  +        return result;
  +    }
   
   }
  
  
  

---------------------------------------------------------------------
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