Class CompareOperator

  • All Implemented Interfaces:

    public class CompareOperator
    extends Expression
    This class implements simple binary comparison operations. The supported operations are:
    • equals, =
    • not-equals, != or <>
    • greater-than, >
    • less-than, <
    • greater-or-equal, >=
    • less-or-equal, <=
    • 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
        schema - a schema object that can be used to look up name and type details for symbols referenced by the expression.
        a column-information object describing the type (and possibly the name and table-name) of this expression's result
        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
        Evaluates this comparison expression and returns either Boolean.TRUE or Boolean.FALSE. If either the left-hand or right-hand expression evaluates to null (representing the SQL NULL value), then the expression's result is always FALSE.
        Specified by:
        evaluate in class Expression
        env - the environment to look up symbol-values from, when evaluating the expression
        the result of the expression evaluation
        ExpressionException - if the expression cannot be evaluated for some reason.
        Design Note:
        (Donnie) We have to suppress "unchecked operation" warnings on this code, since Comparable is a generic (and thus allows us to specify the type of object being compared), but we want to use it without specifying any types.
      • 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
        p - the object that performs analysis or transformation of the expression tree
        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 comparison expression and its subexpressions.
        toString in class java.lang.Object
      • getType

        public CompareOperator.Type getType()
        Returns the type of this comparison operator.
        the type of comparison
      • getLeftExpression

        public Expression getLeftExpression()
        Returns the left expression.
        the left expression
      • getRightExpression

        public Expression getRightExpression()
        Returns the right expression.
        the right expression
      • normalize

        public void normalize()
        Normalize the comparison expression. The rules are:
        • Comparisons with a column-name and a literal value will be updated so that the literal value is always on the right.
        • Comparisons with two column-names will be updated so that the left column-name is "less than" the right column-name, using the ColumnName.compareTo(edu.caltech.nanodb.expressions.ColumnName) method.
      • equals

        public boolean equals​(java.lang.Object obj)
        Checks if the argument is an expression with the same structure, but not necessarily the same references.
        Specified by:
        equals in class Expression
        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 might be equal.
        Specified by:
        hashCode in class Expression
      • clone

        protected java.lang.Object clone()
                                  throws java.lang.CloneNotSupportedException
        Creates a copy of expression. This method is used by the Expression.duplicate() method to make a deep copy of an expression tree.
        clone in class Expression
      • areObjectsEqual

        public static boolean areObjectsEqual​(java.lang.Object obj1,
                                              java.lang.Object obj2)
        Performs an equality comparison between two objects, using the database's rules for type conversions/coercions.
        obj1 - the first object to compare
        obj2 - the second object to compare
        the results of the equality comparison