Class ArithmeticOperator

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class ArithmeticOperator
    extends Expression
    This class implements simple binary arithmetic operations. The supported operations are:
    • addition, +
    • subtraction, -
    • multiplication, *
    • division, /
    • remainder, %
    • exponentiation, ^
    • Field Detail

      • leftExpr

        private Expression leftExpr
        The left expression in the comparison.
      • rightExpr

        private Expression rightExpr
        The right expression in the comparison.
    • Method Detail

      • getColumnInfo

        public ColumnInfo getColumnInfo​(Schema schema)
                                 throws SchemaNameException
        Description copied from class: Expression
        Returns a ColumnInfo object describing the type (and possibly the name) of the expression's result.
        Specified by:
        getColumnInfo in class Expression
        Parameters:
        schema - a schema object that can be used to look up name and type details for symbols referenced by the expression.
        Returns:
        a column-information object describing the type (and possibly the name and table-name) of this expression's result
        Throws:
        SchemaNameException - if a symbol cannot be resolved, either because it doesn't appear in the schema, or because the name is ambiguous.
      • evaluate

        public java.lang.Object evaluate​(Environment env)
                                  throws ExpressionException
        Description copied from class: Expression
        Evaluates this expression object in the context of the specified environment. The environment provides any external information necessary to evaluate the expression, such as the current tuples loaded from tables referenced within the expression.
        Specified by:
        evaluate in class Expression
        Parameters:
        env - the environment to look up symbol-values from, when evaluating the expression
        Returns:
        the result of the expression evaluation
        Throws:
        ExpressionException - if the expression cannot be evaluated for some reason.
      • evalObjects

        public static java.lang.Object evalObjects​(ArithmeticOperator.Type type,
                                                   java.lang.Object aObj,
                                                   java.lang.Object bObj)
        This static helper method can be used to compute basic arithmetic operations between two arguments. It is of course used to evaluate ArithmeticOperator objects, but it can also be used to evaluate specific arithmetic operations within other components of the database system.
        Parameters:
        type - the arithmetic operation to perform
        aObj - the first operand value for the operation
        bObj - the second operand value for the operation
        Returns:
        the result of the arithmetic operation
        Throws:
        ExpressionException - if the operand type is unrecognized
      • evalBigDecimals

        private static java.math.BigDecimal evalBigDecimals​(ArithmeticOperator.Type type,
                                                            java.math.BigDecimal a,
                                                            java.math.BigDecimal b)
      • evalBigIntegers

        private static java.math.BigInteger evalBigIntegers​(ArithmeticOperator.Type type,
                                                            java.math.BigInteger a,
                                                            java.math.BigInteger b)
      • evalDoubles

        private static java.lang.Double evalDoubles​(ArithmeticOperator.Type type,
                                                    java.lang.Double a,
                                                    java.lang.Double b)
        This helper implements the arithmetic operations for Double values. Note that division of two Doubles will produce a Double.
        Parameters:
        type - the arithmetic operation to perform
        a - the first operand value for the operation
        b - the second operand value for the operation
        Returns:
        the result of the arithmetic operation
        Throws:
        ExpressionException - if the operand type is unrecognized
      • evalFloats

        private static java.lang.Float evalFloats​(ArithmeticOperator.Type type,
                                                  java.lang.Float a,
                                                  java.lang.Float b)
        This helper implements the arithmetic operations for Float values. Note that division of two Floats will produce a Float.
        Parameters:
        type - the arithmetic operation to perform
        a - the first operand value for the operation
        b - the second operand value for the operation
        Returns:
        the result of the arithmetic operation
        Throws:
        ExpressionException - if the operand type is unrecognized
      • evalLongs

        private static java.lang.Object evalLongs​(ArithmeticOperator.Type type,
                                                  java.lang.Long a,
                                                  java.lang.Long b)
        This helper implements the arithmetic operations for Long values. Note that division of two Longs will produce a Double, not a Long.
        Parameters:
        type - the arithmetic operation to perform
        a - the first operand value for the operation
        b - the second operand value for the operation
        Returns:
        the result of the arithmetic operation
        Throws:
        ExpressionException - if the operand type is unrecognized
      • evalIntegers

        private static java.lang.Object evalIntegers​(ArithmeticOperator.Type type,
                                                     java.lang.Integer a,
                                                     java.lang.Integer b)
        This helper implements the arithmetic operations for Integer values. Note that division of two Integers will produce a Double, not an Integer.
        Parameters:
        type - the arithmetic operation to perform
        a - the first operand value for the operation
        b - the second operand value for the operation
        Returns:
        the result of the arithmetic operation
        Throws:
        ExpressionException - if the operand type is unrecognized
      • evalDateTimes

        private static java.lang.Object evalDateTimes​(ArithmeticOperator.Type type,
                                                      java.time.LocalDateTime a,
                                                      java.time.LocalDateTime b)
      • evalDates

        private static java.lang.Object evalDates​(ArithmeticOperator.Type type,
                                                  java.time.LocalDate a,
                                                  java.time.LocalDate b)
      • evalTimes

        private static java.lang.Object evalTimes​(ArithmeticOperator.Type type,
                                                  java.time.LocalTime a,
                                                  java.time.LocalTime b)
      • evalDateInterval

        private static java.lang.Object evalDateInterval​(ArithmeticOperator.Type type,
                                                         java.time.LocalDate a,
                                                         java.time.temporal.TemporalAmount b)
      • evalTimeInterval

        private static java.lang.Object evalTimeInterval​(ArithmeticOperator.Type type,
                                                         java.time.LocalTime a,
                                                         java.time.temporal.TemporalAmount b)
      • evalDateTimeInterval

        private static java.lang.Object evalDateTimeInterval​(ArithmeticOperator.Type type,
                                                             java.time.LocalDateTime a,
                                                             java.time.temporal.TemporalAmount b)
      • evalIntervalDate

        private static java.lang.Object evalIntervalDate​(ArithmeticOperator.Type type,
                                                         java.time.temporal.TemporalAmount a,
                                                         java.time.LocalDate b)
      • evalIntervalTime

        private static java.lang.Object evalIntervalTime​(ArithmeticOperator.Type type,
                                                         java.time.temporal.TemporalAmount a,
                                                         java.time.LocalTime b)
      • evalIntervalDateTime

        private static java.lang.Object evalIntervalDateTime​(ArithmeticOperator.Type type,
                                                             java.time.temporal.TemporalAmount a,
                                                             java.time.LocalDateTime b)
      • traverse

        public Expression traverse​(ExpressionProcessor p)
        Description copied from class: Expression

        This method allows the entire expression tree to be traversed node by node, either for analysis or for transformation. The ExpressionProcessor instance receives notifications as each node in the expression is entered and left.

        The expression tree can also be manipulated by this traversal process, depending on what the ExpressionProcessor wants to do. If the expression node that traverse() is invoked on, needs to be replaced with a new expression node, the replacement is returned by the traverse() method. (The ExpressionProcessor specifies the replacement as the return-value from the ExpressionProcessor.leave(Expression) method.)

        Specified by:
        traverse in class Expression
        Parameters:
        p - the object that performs analysis or transformation of the expression tree
        Returns:
        an Expression node to replace this node, or null if no changes are to be made.
      • toString

        public java.lang.String toString()
        Returns a string representation of this arithmetic expression and its subexpressions, including parentheses where necessary to specify precedence.
        Overrides:
        toString in class java.lang.Object
      • simplify

        public Expression simplify()
        Simplifies an arithmetic expression, computing as much of the expression as possible.
        Overrides:
        simplify in class Expression
        Returns:
        a reference to an expression, either a simplified version of this expression, or the original unmodified expression
      • equals

        public boolean equals​(java.lang.Object obj)
        Checks if the argument is an expression with the same structure, but not necesarily the same references.
        Specified by:
        equals in class Expression
        Parameters:
        obj - the object to which we are comparing
      • hashCode

        public int hashCode()
        Computes the hashcode of an Expression. This method is used to see if two expressions CAN be equal.
        Specified by:
        hashCode in class Expression
      • clone

        protected java.lang.Object clone()
                                  throws java.lang.CloneNotSupportedException
        Creates a copy of expression.
        Overrides:
        clone in class Expression
        Throws:
        java.lang.CloneNotSupportedException