Package edu.caltech.nanodb.expressions
Class CompareOperator
java.lang.Object
edu.caltech.nanodb.expressions.Expression
edu.caltech.nanodb.expressions.CompareOperator
- All Implemented Interfaces:
Cloneable
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, <=
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThis enumeration specifies the types of comparisons that can be performed. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ExpressionThe left expression in the comparison.private ExpressionThe right expression in the comparison.private CompareOperator.TypeThe kind of comparison, such as "equals" or "less than." -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanareObjectsEqual(Object obj1, Object obj2) Performs an equality comparison between two objects, using the database's rules for type conversions/coercions.protected Objectclone()Creates a copy of expression.booleanChecks if the argument is an expression with the same structure, but not necessarily the same references.evaluate(Environment env) Evaluates this comparison expression and returns eitherBoolean.TRUEorBoolean.FALSE.getColumnInfo(Schema schema) Returns aColumnInfoobject describing the type (and possibly the name) of the expression's result.Returns the left expression.Returns the right expression.getType()Returns the type of this comparison operator.inthashCode()Computes the hashcode of an Expression.voidNormalize the comparison expression.toString()Returns a string representation of this comparison expression and its subexpressions.This method allows the entire expression tree to be traversed node by node, either for analysis or for transformation.Methods inherited from class edu.caltech.nanodb.expressions.Expression
duplicate, evaluate, evaluatePredicate, evaluatePredicate, getAllSymbols, hasSymbols, simplify
-
Field Details
-
type
The kind of comparison, such as "equals" or "less than." -
leftExpr
The left expression in the comparison. -
rightExpr
The right expression in the comparison.
-
-
Constructor Details
-
CompareOperator
-
-
Method Details
-
getColumnInfo
Description copied from class:ExpressionReturns aColumnInfoobject describing the type (and possibly the name) of the expression's result.- Specified by:
getColumnInfoin classExpression- 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
Evaluates this comparison expression and returns eitherBoolean.TRUEorBoolean.FALSE. If either the left-hand or right-hand expression evaluates tonull(representing the SQL NULL value), then the expression's result is alwaysFALSE.- Specified by:
evaluatein classExpression- 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.- Design Note:
- (Donnie) We have to suppress "unchecked operation" warnings on
this code, since
Comparableis 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
Description copied from class:ExpressionThis method allows the entire expression tree to be traversed node by node, either for analysis or for transformation. The
ExpressionProcessorinstance 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
ExpressionProcessorwants to do. If the expression node thattraverse()is invoked on, needs to be replaced with a new expression node, the replacement is returned by thetraverse()method. (TheExpressionProcessorspecifies the replacement as the return-value from theExpressionProcessor.leave(Expression)method.)- Specified by:
traversein classExpression- Parameters:
p- the object that performs analysis or transformation of the expression tree- Returns:
- an
Expressionnode to replace this node, ornullif no changes are to be made.
-
toString
Returns a string representation of this comparison expression and its subexpressions. -
getType
Returns the type of this comparison operator.- Returns:
- the type of comparison
-
getLeftExpression
Returns the left expression.- Returns:
- the left expression
-
getRightExpression
Returns the right expression.- Returns:
- 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
Checks if the argument is an expression with the same structure, but not necessarily the same references.- Specified by:
equalsin classExpression- 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 might be equal.- Specified by:
hashCodein classExpression
-
clone
Creates a copy of expression. This method is used by theExpression.duplicate()method to make a deep copy of an expression tree.- Overrides:
clonein classExpression- Throws:
CloneNotSupportedException
-
areObjectsEqual
Performs an equality comparison between two objects, using the database's rules for type conversions/coercions.- Parameters:
obj1- the first object to compareobj2- the second object to compare- Returns:
- the results of the equality comparison
-