2.17.2: 2011-06-17

net.sf.basedb.core.query
Class Aggregations

java.lang.Object
  extended by net.sf.basedb.core.query.Aggregations

public class Aggregations
extends Object

A factory class to create aggregate expressions.

Version:
2.0
Author:
Nicklas
Last modified
$Date: 2009-04-06 14:52:39 +0200 (Mon, 06 Apr 2009) $

Constructor Summary
Aggregations()
           
 
Method Summary
static Expression count(Expression e, boolean distinct)
          Calculates the number of values for an expression: new expression = COUNT(e)
static Expression geometricMean(Expression e)
          Calculates the geometric mean of all values for an expression: new expression = EXP(AVG(LN(e))).
static Expression max(Expression e)
          Calculates the maximum value of an expression: new expression = MAX(e)
static Expression mean(Expression e)
          Calculates the arithmetic mean of all values for an expression: new expression = AVG(e)
static Expression min(Expression e)
          Calculates the minimum value of an expression: new expression = MIN(e)
static Expression quadraticMean(Expression e)
          Calculates the quadratic mean, also called Root Mean Square, for an expression: new expression = sqrt(AVG(e*e))
static Expression sum(Expression e)
          Calculates the sum of all values of an expression: new expression = SUM(e)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Aggregations

public Aggregations()
Method Detail

count

public static Expression count(Expression e,
                               boolean distinct)
Calculates the number of values for an expression: new expression = COUNT(e)

Parameters:
e - The expression to count, or null to count all rows (ie. COUNT(*))
distinct - If only distinct values should be counted
Returns:
The new Expression

geometricMean

public static Expression geometricMean(Expression e)
                                throws InvalidDataException
Calculates the geometric mean of all values for an expression: new expression = EXP(AVG(LN(e))). Note that this method can handle values less then or equal with 0 although the mathematical definition of geometric mean doesn't allow it. This is caused by the way that sql handle null values in aggregated operations. The geometric mean of the numbers [2, -5, 8] is therefor 4 (because ln(-5) is undefined, i.e. null, it is ignored in the avg operation). If you ask a mathematician he would say that the geometic mean is undefined for those numbers.

Parameters:
e - The expression to use in the calculation
Returns:
The new Expression
Throws:
InvalidDataException - If the expression is null
Since:
2.4

max

public static Expression max(Expression e)
                      throws InvalidDataException
Calculates the maximum value of an expression: new expression = MAX(e)

Parameters:
e - The expression to use in the calculation
Returns:
The new Expression
Throws:
InvalidDataException - If the expression is null

min

public static Expression min(Expression e)
                      throws InvalidDataException
Calculates the minimum value of an expression: new expression = MIN(e)

Parameters:
e - The expression to use in the calculation
Returns:
The new Expression
Throws:
InvalidDataException - If the expression is null

mean

public static Expression mean(Expression e)
                       throws InvalidDataException
Calculates the arithmetic mean of all values for an expression: new expression = AVG(e)

Parameters:
e - The expression to use in the calculation
Returns:
The new Expression
Throws:
InvalidDataException - If the expression is null

sum

public static Expression sum(Expression e)
                      throws InvalidDataException
Calculates the sum of all values of an expression: new expression = SUM(e)

Parameters:
e - The expression to use in the calculation
Returns:
The new Expression
Throws:
InvalidDataException - If the expression is null

quadraticMean

public static Expression quadraticMean(Expression e)
Calculates the quadratic mean, also called Root Mean Square, for an expression: new expression = sqrt(AVG(e*e))

Parameters:
e - The expression to use in the calculation
Returns:
The new Expression
Throws:
InvalidUseOfNullException - If the expression is null
Since:
2.8

2.17.2: 2011-06-17