Class Function

  • All Implemented Interfaces:
    SQLStringable

    public class Function
    extends AbstractValue
    A representation of a function in an SQL query.
    Author:
    Matthew wakeling, Andrew Varley
    • Field Summary

      Fields 
      Modifier and Type Field Description
      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 GREATEST
      GREATEST(x, y) - takes two operands
      static int LEAST
      LEAST(x, y) - 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
    • Constructor Summary

      Constructors 
      Constructor Description
      Function​(int operation)
      Constructor for this Function object.
    • Field Detail

      • operation

        protected int operation
      • 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
      • GREATEST

        public static final int GREATEST
        GREATEST(x, y) - takes two operands
        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