psteitz     2004/06/28 19:18:22

  Modified:    math/src/java/org/apache/commons/math/stat/univariate
                        StatisticalSummaryValues.java
  Log:
  Implemented equals and hashcode.
  
  Revision  Changes    Path
  1.4       +41 -2     
jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/StatisticalSummaryValues.java
  
  Index: StatisticalSummaryValues.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/StatisticalSummaryValues.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StatisticalSummaryValues.java     23 Jun 2004 16:26:16 -0000      1.3
  +++ StatisticalSummaryValues.java     29 Jun 2004 02:18:22 -0000      1.4
  @@ -16,6 +16,7 @@
   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.
  @@ -72,7 +73,6 @@
           super();
       }
   
  -    
       /**
        * @return Returns the max.
        */
  @@ -120,6 +120,45 @@
        */
       public double getVariance() {
           return variance;
  +    }
  +    
  +    /**
  +     * Returns true iff <code>object</code> is a 
  +     * <code>StatisticalSummaryValues</code> 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;
       }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to