All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.jagg.StdDevAggregator Maven / Gradle / Ivy

Go to download

jAgg is a Java 5.0 API that supports “group by” operations on Lists of Java objects: aggregate operations such as count, sum, max, min, avg, and many more. It also allows custom aggregate operations.

The newest version!
package net.sf.jagg;

import net.sf.jagg.math.DoubleDouble;

/**
 * This class represents the "sample standard deviation" aggregator over
 * numeric values.
 *
 * @author Randy Gettman
 * @since 0.1.0
 */
public class StdDevAggregator extends AbstractVarianceAggregator
{
   /**
    * Constructs an StdDevAggregator that operates on the specified
    * property.
    * @param property Calculate the standard deviation of this property's values.
    */
   public StdDevAggregator(String property)
   {
      super(property);
   }

   /**
    * Returns an uninitialized copy of this Aggregator object,
    * with the same property(ies) to analyze.
    * @return An uninitialized copy of this Aggregator object.
    */
   public StdDevAggregator replicate()
   {
      return new StdDevAggregator(getProperty());
   }
   
   /**
    * Return the sample standard deviation by taking the square root of the
    * sample variance.
    *
    * @return The sample standard deviation as a Double.  Returns
    *    NaN if no items have been accumulated, or 0 if exactly
    *    one value has been accumulated.
    */
   public Double terminate()
   {
      return terminateDoubleDouble().doubleValue();
   }

   /**
    * Return the result as a DoubleDouble.  This is used mainly
    * when other Aggregators that use this result must maintain a
    * high precision.
    * @return The sample standard deviation as a DoubleDouble,
    *    NaN if no items have been accumulated, or 0 if exactly
    *    one value has been accumulated.
    * @since 0.4.0
    */
   public DoubleDouble terminateDoubleDouble()
   {
      if (myCount <= 0)
         return new DoubleDouble(DoubleDouble.NaN);
      if (myCount == 1)
         return new DoubleDouble(0);
      DoubleDouble result = new DoubleDouble(myVarNumerator);
      result.divideSelfBy(myCount - 1);
      result.sqrtSelf();
      return result;
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy