tuffy.ra
Class Expression

java.lang.Object
  extended by tuffy.ra.Expression
All Implemented Interfaces:
java.lang.Cloneable

public final class Expression
extends java.lang.Object
implements java.lang.Cloneable

An expression to a function is like a literal to a predicate. The interesting part is that expressions can be nested. The value of an expression can be numeric/string/boolean.

Author:
Feng Niu

Field Summary
private  java.util.ArrayList<Expression> args_
           
 boolean changeName
           
private  Function func_
           
private  java.lang.String val
           
private  java.lang.String valBinding
           
 
Constructor Summary
Expression(Function func)
          Construct a new expression based on the function func_
 
Method Summary
 void addArgument(Expression expr)
          Append an argument to the underlying function
static Expression and(Expression e1, Expression e2)
          Boolean AND
 void bindVariables(java.util.Map<java.lang.String,java.lang.String> mapVarVal)
          Bind variable references to their values in the symbol table.
 Expression clone()
           
static Expression exprConstInteger(int n)
          Atomic expression representing a constant integer
static Expression exprConstNum(double num)
          Atomic expression representing a constant number
static Expression exprConstString(java.lang.String str)
          Atomic expression representing a constant string
static Expression exprVariableBinding(java.lang.String var)
          Atomic expression representing a variable binding
 java.util.ArrayList<Expression> getArgs()
           
 Function getFunction()
           
private  java.lang.String getStringForm(boolean inSQL)
          Compute the SQL representation of this expression.
 java.util.HashSet<java.lang.String> getVars()
          Get the variables referenced by this expression.
 boolean isBoolean()
          Test if this expression returns a boolean value
 boolean isNumeric()
          Test if this expression returns a numeric value
 boolean isString()
          Test if this expression returns a string value
private  boolean needEnclosure()
          For aesthetics, check if we need a pair of parenthses for this experession.
static Expression not(Expression e)
          Boolean negation
static Expression or(Expression e1, Expression e2)
          Boolean OR
 java.lang.String renameVariables(java.util.Map<java.lang.String,java.lang.String> mapVarVar)
          Bind variable references to their values in the symbol table.
 java.lang.String toSQL()
          Get the SQL snippet for this expression
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

func_

private Function func_

args_

private java.util.ArrayList<Expression> args_

val

private java.lang.String val

valBinding

private java.lang.String valBinding

changeName

public boolean changeName
Constructor Detail

Expression

public Expression(Function func)
Construct a new expression based on the function func_

Parameters:
func - the underlying function
Method Detail

getArgs

public java.util.ArrayList<Expression> getArgs()

getFunction

public Function getFunction()

getVars

public java.util.HashSet<java.lang.String> getVars()
Get the variables referenced by this expression.


needEnclosure

private boolean needEnclosure()
For aesthetics, check if we need a pair of parenthses for this experession.


not

public static Expression not(Expression e)
Boolean negation

Parameters:
e -

and

public static Expression and(Expression e1,
                             Expression e2)
Boolean AND

Parameters:
e1 -
e2 -

or

public static Expression or(Expression e1,
                            Expression e2)
Boolean OR

Parameters:
e1 -
e2 -

isBoolean

public boolean isBoolean()
Test if this expression returns a boolean value


isString

public boolean isString()
Test if this expression returns a string value


isNumeric

public boolean isNumeric()
Test if this expression returns a numeric value


addArgument

public void addArgument(Expression expr)
Append an argument to the underlying function

Parameters:
expr - the new argument

exprConstInteger

public static Expression exprConstInteger(int n)
Atomic expression representing a constant integer

Parameters:
n -

exprConstNum

public static Expression exprConstNum(double num)
Atomic expression representing a constant number


exprConstString

public static Expression exprConstString(java.lang.String str)
Atomic expression representing a constant string


exprVariableBinding

public static Expression exprVariableBinding(java.lang.String var)
Atomic expression representing a variable binding


clone

public Expression clone()
Overrides:
clone in class java.lang.Object

renameVariables

public java.lang.String renameVariables(java.util.Map<java.lang.String,java.lang.String> mapVarVar)
Bind variable references to their values in the symbol table. Variable name in the clause -> attribute name in SQL representing the value column of the symbol table.

Parameters:
mapVarVar -

bindVariables

public void bindVariables(java.util.Map<java.lang.String,java.lang.String> mapVarVal)
Bind variable references to their values in the symbol table. Variable name in the clause -> attribute name in SQL representing the value column of the symbol table.

Parameters:
mapVarVal -

toSQL

public java.lang.String toSQL()
Get the SQL snippet for this expression


getStringForm

private java.lang.String getStringForm(boolean inSQL)
Compute the SQL representation of this expression. Call bindVariables(Map) first.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object