com.google.visualization.datasource.query.scalarfunction
Class Sum

java.lang.Object
  extended by com.google.visualization.datasource.query.scalarfunction.Sum
All Implemented Interfaces:
ScalarFunction

public class Sum
extends java.lang.Object
implements ScalarFunction

The binary scalar function sum(). Returns the sum of two number values.

Author:
Liron L.

Method Summary
 Value evaluate(java.util.List<Value> values)
          Executes the scalar function sum() on the given values.
 java.lang.String getFunctionName()
          Returns the function's name.
static Sum getInstance()
          Returns the singleton instance of this class.
 ValueType getReturnType(java.util.List<ValueType> types)
          Returns the return type of the function.
 java.lang.String toQueryString(java.util.List<java.lang.String> argumentsQueryStrings)
          Returns a string that when given to the query parser will yield a similar scalar function.
 void validateParameters(java.util.List<ValueType> types)
          Validates that all function parameters are of type NUMBER, and that there are exactly 2 parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static Sum getInstance()
Returns the singleton instance of this class.

Returns:
The singleton instance of this class.

getFunctionName

public java.lang.String getFunctionName()
Returns the function's name.

Specified by:
getFunctionName in interface ScalarFunction
Returns:
The function's name.

evaluate

public Value evaluate(java.util.List<Value> values)
Executes the scalar function sum() on the given values. Returns the sum of the given values. All values are number values. The method does not validate the parameters, the user must check the parameters before calling this method.

Specified by:
evaluate in interface ScalarFunction
Parameters:
values - A list of values on which the scalar function is performed.
Returns:
Value with the sum of all given values, or number null value if one of the values is null.

getReturnType

public ValueType getReturnType(java.util.List<ValueType> types)
Returns the return type of the function. In this case, NUMBER. The method does not validate the parameters, the user must check the parameters before calling this method.

Specified by:
getReturnType in interface ScalarFunction
Parameters:
types - A list of the types of the scalar function parameters.
Returns:
The type of the returned value: Number.

validateParameters

public void validateParameters(java.util.List<ValueType> types)
                        throws InvalidQueryException
Validates that all function parameters are of type NUMBER, and that there are exactly 2 parameters. Throws a ScalarFunctionException otherwise.

Specified by:
validateParameters in interface ScalarFunction
Parameters:
types - A list of parameter types.
Throws:
InvalidQueryException - Thrown if the parameters are invalid.

toQueryString

public java.lang.String toQueryString(java.util.List<java.lang.String> argumentsQueryStrings)
Returns a string that when given to the query parser will yield a similar scalar function. Takes as arguments the query strings of the arguments.

Specified by:
toQueryString in interface ScalarFunction
Parameters:
argumentsQueryStrings - The query strings of the actual arguments.
Returns:
The query string.


Copyright © 2009 Google. All Rights Reserved.