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

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

public class ToDate
extends java.lang.Object
implements ScalarFunction

The unary scalar function toDate(). Transforms the given value to date value. If the given value is already a date, it's trivial. If the given value is a date-time, it extracts its date part. If the given value is number, it treats that number as the number of milliseconds since the Epoch, and returns the corresponding date.

Author:
Liron L.

Method Summary
 Value evaluate(java.util.List<Value> values)
          Executes the scalar function toDate() on the given values.
 java.lang.String getFunctionName()
          Returns the function's name.
static ToDate 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 is only 1 parameter given for this function, and that its type is either DATE, DATETIME or NUMBER.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ToDate 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 toDate() on the given values. The list is expected to be of length 1, and the value in it should be of an appropiate type. 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 with the values that the scalar function is performed on them.
Returns:
A date value with the appropriate date.

getReturnType

public ValueType getReturnType(java.util.List<ValueType> types)
Returns the return type of the function. In this case, DATE. 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: DATE.

validateParameters

public void validateParameters(java.util.List<ValueType> types)
                        throws InvalidQueryException
Validates that there is only 1 parameter given for this function, and that its type is either DATE, DATETIME or NUMBER. 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.