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

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

public class Constant
extends java.lang.Object
implements ScalarFunction

A constant function, i.e., a 0-ary function that always returns the same value, given at construction time. The value can be of any supported ValueType.

Author:
Liron L.

Constructor Summary
Constant(Value value)
          Constructs a new constant function that always returns the given value.
 
Method Summary
 boolean equals(java.lang.Object o)
           
 Value evaluate(java.util.List<Value> values)
          Executes the scalar function constant().
 java.lang.String getFunctionName()
          Returns the function's name.
 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 are no parameters given for the function.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Constant

public Constant(Value value)
Constructs a new constant function that always returns the given value.

Parameters:
value - The value to constantly return.
Method Detail

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 constant(). The values parameter is ignored. Returns the value supplied at construction time.

Specified by:
evaluate in interface ScalarFunction
Parameters:
values - Ignored.
Returns:
The value supplied at construction time.

getReturnType

public ValueType getReturnType(java.util.List<ValueType> types)
Returns the return type of the function. This matches the type of the value supplied at construction time. The types parameter is ignored.

Specified by:
getReturnType in interface ScalarFunction
Parameters:
types - Ignored.
Returns:
The return type of this function.

validateParameters

public void validateParameters(java.util.List<ValueType> types)
                        throws InvalidQueryException
Validates that there are no parameters given for the function. Throws a ScalarFunctionException otherwise.

Specified by:
validateParameters in interface ScalarFunction
Parameters:
types - A list with parameters types. Should be empty for this type of function.
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.