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

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

public class DateDiff
extends java.lang.Object
implements ScalarFunction

The binary scalar function datediff(). Returns the difference in days between two dates or date time values.

Author:
Liron L.

Method Summary
 Value evaluate(java.util.List<Value> values)
          Executes this scalar function on the given values.
 java.lang.String getFunctionName()
          Returns the function's name.
static DateDiff 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 there are only 2 parameters given for this function, and that their types are either DATE or DATETIME.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static DateDiff 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 this scalar function on the given values. Returns values[0] - values[1] expressed as a number value denoting the number of days from one date to the other. Both values can be of type date or date-time. Only the date parts of date-time values are used in the calculation. Thus the returned number is always an integer. 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 will be performed.
Returns:
Value holding the difference, in whole days, between the two given Date/DateTime values, or a null value (of type number) 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 there are only 2 parameters given for this function, and that their types are either DATE or DATETIME. Throws a ScalarFunctionException if the parameters are invalid.

Specified by:
validateParameters in interface ScalarFunction
Parameters:
types - A list with parameters 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.