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

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

public class TimeComponentExtractor
extends java.lang.Object
implements ScalarFunction

A time component extractor. This class encompasses all the unary scalar functions that extract a time component from a date/datetime/timeofday value. e.g., year, month, second.

Author:
Liron L.

Nested Class Summary
static class TimeComponentExtractor.TimeComponent
          An enum of time components that can be extracted from a date/datetime/timeofday value.
 
Method Summary
 boolean equals(java.lang.Object o)
           
 Value evaluate(java.util.List<Value> values)
          Executes the scalar function that extracts the timeComponent on the given values.
 java.lang.String getFunctionName()
          Returns the name of this scalar function, in this case the name of the TimeComponentExtractor.
static TimeComponentExtractor getInstance(TimeComponentExtractor.TimeComponent timeComponent)
          Returns an instance of a TimeComponentExtractor that extracts the given TimeComponent.
 ValueType getReturnType(java.util.List<ValueType> types)
          Returns the return type of the function.
 int hashCode()
           
 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 one parameter given for the function, and that its type is DATE or DATETIME if the timeComponent to extract is year, month or day, or that it is DATETIME or TIMEOFDAY if the timeComponent is hour, minute, second or millisecond.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static TimeComponentExtractor getInstance(TimeComponentExtractor.TimeComponent timeComponent)
Returns an instance of a TimeComponentExtractor that extracts the given TimeComponent.

Parameters:
timeComponent - The TimeComponent to extract.
Returns:
Returns an instance of a TimeComponentExtractor.

getFunctionName

public java.lang.String getFunctionName()
Returns the name of this scalar function, in this case the name of the TimeComponentExtractor.

Specified by:
getFunctionName in interface ScalarFunction
Returns:
the name of this scalar function, in this case the name of the TimeComponentExtractor.

evaluate

public Value evaluate(java.util.List<Value> values)
Executes the scalar function that extracts the timeComponent on the given values. Returns a NumberValue with the timeComponent of the given Date/DateTime/TimeOfDay value. 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 the values on which the scalar function is performed.
Returns:
Value with the timeComponent value of the given value, or number null value if value 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 is only one parameter given for the function, and that its type is DATE or DATETIME if the timeComponent to extract is year, month or day, or that it is DATETIME or TIMEOFDAY if the timeComponent is hour, minute, second or millisecond. Throws a ScalarFunctionException if the parameters are invalid.

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

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

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.