org.intermine.sql.query
Class Function

java.lang.Object
  extended by org.intermine.sql.query.AbstractValue
      extended by org.intermine.sql.query.Function
All Implemented Interfaces:
SQLStringable

public class Function
extends AbstractValue

A representation of a function in an SQL query.


Field Summary
static int AVG
          AVG(v) aggregate function - takes one operand.
static int COALESCE
          COALESCE operator - used by the precomputed tables' orderby fields.
static int COUNT
          COUNT(*) aggregate function - takes no operands.
static int DIVIDE
          DIVIDE function - takes two operands.
static int LOWER
          LOWER operator - takes one operand
static int MAX
          MAX(v) aggregate function - takes one operand.
static int MIN
          MIN(v) aggregate function - takes one operand.
static int MINUS
          MINUS function - takes two operands.
static int MODULO
          MODULO arithmetic function - takes two operands.
static int MULTIPLY
          MULTIPLY function - takes two or more operands.
protected  java.util.List<AbstractValue> operands
           
protected  int operation
           
static int PLUS
          PLUS function - takes two or more operands.
static int POWER
          POWER function - takes two operands.
static int STDDEV
          STDDEV operator - takes one operand
static int STRPOS
          STRPOS operator - takes two operands.
static int SUBSTR
          SUBSTR operator - takes two or three operands.
static int SUM
          SUM(v) aggregate function - takes one operand.
static int TYPECAST
          Type casts - takes two operands.
static int UPPER
          UPPER operator - takes one operand
 
Fields inherited from class org.intermine.sql.query.AbstractValue
EQUAL, GREATER, INCOMPARABLE, LESS, NOT_EQUAL
 
Constructor Summary
Function(int operation)
          Constructor for this Function object.
 
Method Summary
 void add(AbstractValue obj)
          Adds an operand to this Function object.
 int compare(AbstractValue obj, java.util.Map<AbstractTable,AbstractTable> tableMap, java.util.Map<AbstractTable,AbstractTable> reverseTableMap)
          Compare the value of this AbstractValue with another.
 boolean equals(java.lang.Object obj)
          Overrides Object.equals.
 java.util.List<AbstractValue> getOperands()
          Returns the List of operands of this function.
 int getOperation()
          Returns the operation of the function.
 java.lang.String getSQLString()
          Returns a String representation of this Function object, suitable for forming part of an SQL query.
 int hashCode()
          Overrides Object.hashcode.
 boolean isAggregate()
          Returns true if this value is an aggregate function.
 
Methods inherited from class org.intermine.sql.query.AbstractValue
greaterOrEqual, greaterThan, lessOrEqual, lessThan, notEqualTo, valueEquals
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

operation

protected int operation

operands

protected java.util.List<AbstractValue> operands

COUNT

public static final int COUNT
COUNT(*) aggregate function - takes no operands.

See Also:
Constant Field Values

MAX

public static final int MAX
MAX(v) aggregate function - takes one operand.

See Also:
Constant Field Values

MIN

public static final int MIN
MIN(v) aggregate function - takes one operand.

See Also:
Constant Field Values

SUM

public static final int SUM
SUM(v) aggregate function - takes one operand.

See Also:
Constant Field Values

AVG

public static final int AVG
AVG(v) aggregate function - takes one operand.

See Also:
Constant Field Values

PLUS

public static final int PLUS
PLUS function - takes two or more operands.

See Also:
Constant Field Values

MINUS

public static final int MINUS
MINUS function - takes two operands.

See Also:
Constant Field Values

MULTIPLY

public static final int MULTIPLY
MULTIPLY function - takes two or more operands.

See Also:
Constant Field Values

DIVIDE

public static final int DIVIDE
DIVIDE function - takes two operands.

See Also:
Constant Field Values

POWER

public static final int POWER
POWER function - takes two operands.

See Also:
Constant Field Values

MODULO

public static final int MODULO
MODULO arithmetic function - takes two operands.

See Also:
Constant Field Values

TYPECAST

public static final int TYPECAST
Type casts - takes two operands.

See Also:
Constant Field Values

STRPOS

public static final int STRPOS
STRPOS operator - takes two operands.

See Also:
Constant Field Values

SUBSTR

public static final int SUBSTR
SUBSTR operator - takes two or three operands.

See Also:
Constant Field Values

COALESCE

public static final int COALESCE
COALESCE operator - used by the precomputed tables' orderby fields.

See Also:
Constant Field Values

LOWER

public static final int LOWER
LOWER operator - takes one operand

See Also:
Constant Field Values

UPPER

public static final int UPPER
UPPER operator - takes one operand

See Also:
Constant Field Values

STDDEV

public static final int STDDEV
STDDEV operator - takes one operand

See Also:
Constant Field Values
Constructor Detail

Function

public Function(int operation)
Constructor for this Function object.

Parameters:
operation - the operation that this Function represents
Throws:
java.lang.IllegalArgumentException - if operation is not valid
Method Detail

add

public void add(AbstractValue obj)
Adds an operand to this Function object. Operands are stored in the order they are added.

Parameters:
obj - the AbstractValue to add as an operand
Throws:
java.lang.IllegalArgumentException - if the operation cannot handle that many operands

getSQLString

public java.lang.String getSQLString()
Returns a String representation of this Function object, suitable for forming part of an SQL query.

Specified by:
getSQLString in interface SQLStringable
Specified by:
getSQLString in class AbstractValue
Returns:
the String representation
Throws:
java.lang.IllegalStateException - if there aren't the correct number of operands for the operation yet.

equals

public boolean equals(java.lang.Object obj)
Overrides Object.equals.

Specified by:
equals in class AbstractValue
Parameters:
obj - the Object to compare to
Returns:
true if they are equal

compare

public int compare(AbstractValue obj,
                   java.util.Map<AbstractTable,AbstractTable> tableMap,
                   java.util.Map<AbstractTable,AbstractTable> reverseTableMap)
Compare the value of this AbstractValue with another.

Specified by:
compare in class AbstractValue
Parameters:
obj - an AbstractValue to compare to
tableMap - a mapping between tablenames of the two elements
reverseTableMap - a reverse of tableMap
Returns:
EQUAL, LESS, GREATER, NOT_EQUAL, or INCOMPARABLE

hashCode

public int hashCode()
Overrides Object.hashcode.

Specified by:
hashCode in class AbstractValue
Returns:
an arbitrary integer based on the contents of the Function

getOperation

public int getOperation()
Returns the operation of the function.

Returns:
operation

getOperands

public java.util.List<AbstractValue> getOperands()
Returns the List of operands of this function.

Returns:
all operands in a List

isAggregate

public boolean isAggregate()
Returns true if this value is an aggregate function.

Specified by:
isAggregate in class AbstractValue
Returns:
a boolean