net.scheinerman.phoenix.interpreter.variables
Interface Variable

All Known Implementing Classes:
AbstractVariable, FunctionVariable, NumberVariable, StringVariable

public interface Variable

A variable is a named data container that can be manipulated through operators. A variable holds some type of data which can then be mutated through its various operators which are represented here with methods. The operators are meant to differ between implementations of this interface. Any operator that is not supported by this can throw an UnsupportedOperatorException with the instance of the variable and the operator symbol. For example, if one wanted a class to not support the addition operator, the add(Variable) would have the following content:

throw new UnsupportedOperatorException(this, "+")

Since:
1.5
Version:
1.0
Author:
Jonah Scheinerman
See Also:
AbstractVariable}, {@link NumberVariable}, {@link StringVariable}, {@link UnsupportedOperatorException}

Method Summary
 Variable add(Variable v)
          Takes two variables and returns the addition operator solution.
 Variable and(Variable v)
          Takes two variables and returns the logical and operator solution.
 void assign(Variable v)
          Assigns a new variable value to this variable.
 Variable copy()
          Returns a copy of this variable.
 Variable divide(Variable v)
          Takes two variables and returns the division operator solution.
 Variable exp(Variable v)
          Takes two variables and returns the exponentiation operator solution.
 java.lang.String getType()
          Returns a string name of this particular variable type.
 Variable greaterEqual(Variable v)
          Takes two variables and returns the greater than or equal to operator solution.
 Variable greaterThan(Variable v)
          Takes two variables and returns the greater than operator solution.
 boolean isConstant()
          Returns whether or not this variable is a constant variable.
 Variable isEqualTo(Variable v)
          Takes two variables and returns the equality operator solution.
 boolean isFunctionReference()
           
 boolean isLiteral()
          Returns whether or not this variable is a literal variable.
 Variable lessEqual(Variable v)
          Takes two variables and returns the less than or equal to operator solution.
 Variable lessThan(Variable v)
          Takes two variables and returns the less than operator solution.
 Variable mod(Variable v)
          Takes two variables and returns the modulus arithmetic operator solution.
 Variable multiply(Variable v)
          Takes two variables and returns the multiplication operator solution.
 Variable not()
          Returns the result of the logical not (complement) of this variable.
 Variable notEqualTo(Variable v)
          Takes two variables and returns the inequality operator solution.
 Variable or(Variable v)
          Takes two variables and returns the logical inclusive or operator solution.
 Variable round(Variable v)
          Takes two variables and returns the rouding operator solution.
 void setConstant(boolean constant)
          Defines whether or not this variable is a constant variable.
 void setFunctionReference(boolean functionReference)
           
 void setLiteral(boolean literal)
          Defines whether or not this variable is a literal variable.
 Variable subscript(Variable sub)
          Returns the result of a simple, one variable subscript of this variable.
 Variable subscript(Variable sub1, Variable sub2)
          Returns the result of a two variable subscript of this variable.
 Variable subtract(Variable v)
          Takes two variables and returns the subtraction operator solution.
 Variable xor(Variable v)
          Takes two variables and returns the logical exclusive operator solution.
 

Method Detail

assign

void assign(Variable v)
Assigns a new variable value to this variable. This method should check to make sure the variable is of the correct type and throw SyntaxException if it is not. This method must be supported, it should not throw a UnsupportedOperatorException.

Parameters:
v - - the variable to assign this variable to be
Throws:
SyntaxException - if the variable is the wrong type or if the variable is a literal.

add

Variable add(Variable v)
Takes two variables and returns the addition operator solution. The symbol for the addition operator is +. This method should provide functionality such that x.add(y) is equivalent to x + y. This operator is not required and can therefore throw the UnsupportedOperatorException. If the variable passed to this operator is of a wrong type a SyntaxException should be thrown.

Parameters:
v - - the variable to operate on
Returns:
the operator's result
Throws:
SyntaxException - if v is the wrong type of variable
UnsupportedOperatorException - if this operator is not supported.

subtract

Variable subtract(Variable v)
Takes two variables and returns the subtraction operator solution. The symbol for the subtraction operator is -. This method should provide functionality such that x.subtract(y) is equivalent to x - y. This operator is not required and can therefore throw the UnsupportedOperatorException. If the variable passed to this operator is of a wrong type a SyntaxException should be thrown.

Parameters:
v - - the variable to operate on
Returns:
the operator's result
Throws:
SyntaxException - if v is the wrong type of variable
UnsupportedOperatorException - if this operator is not supported.

multiply

Variable multiply(Variable v)
Takes two variables and returns the multiplication operator solution. The symbol for the multiplication operator is *. This method should provide functionality such that x.multiply(y) is equivalent to x * y. This operator is not required and can therefore throw the UnsupportedOperatorException. If the variable passed to this operator is of a wrong type a SyntaxException should be thrown.

Parameters:
v - - the variable to operate on
Returns:
the operator's result
Throws:
SyntaxException - if v is the wrong type of variable
UnsupportedOperatorException - if this operator is not supported.

divide

Variable divide(Variable v)
Takes two variables and returns the division operator solution. The symbol for the division operator is /. This method should provide functionality such that x.divide(y) is equivalent to x / y. This operator is not required and can therefore throw the UnsupportedOperatorException. If the variable passed to this operator is of a wrong type a SyntaxException should be thrown.

Parameters:
v - - the variable to operate on
Returns:
the operator's result
Throws:
SyntaxException - if v is the wrong type of variable
UnsupportedOperatorException - if this operator is not supported.

mod

Variable mod(Variable v)
Takes two variables and returns the modulus arithmetic operator solution. The symbol for the modulus arithmetic operator is %. This method should provide functionality such that x.mod(y) is equivalent to x % y. This operator is not required and can therefore throw the UnsupportedOperatorException. If the variable passed to this operator is of a wrong type a SyntaxException should be thrown.

Parameters:
v - - the variable to operate on
Returns:
the operator's result
Throws:
SyntaxException - if v is the wrong type of variable
UnsupportedOperatorException - if this operator is not supported.

exp

Variable exp(Variable v)
Takes two variables and returns the exponentiation operator solution. The symbol for the exponentiation operator is ^. This method should provide functionality such that x.exp(y) is equivalent to x ^ y. This operator is not required and can therefore throw the UnsupportedOperatorException. If the variable passed to this operator is of a wrong type a SyntaxException should be thrown.

Parameters:
v - - the variable to operate on
Returns:
the operator's result
Throws:
SyntaxException - if v is the wrong type of variable
UnsupportedOperatorException - if this operator is not supported.

round

Variable round(Variable v)
Takes two variables and returns the rouding operator solution. The symbol for the rounding operator is #. This method should provide functionality such that x.round(y) is equivalent to x # y. This operator is not required and can therefore throw the UnsupportedOperatorException. If the variable passed to this operator is of a wrong type a SyntaxException should be thrown.

Parameters:
v - - the variable to operate on
Returns:
the operator's result
Throws:
SyntaxException - if v is the wrong type of variable
UnsupportedOperatorException - if this operator is not supported.

isEqualTo

Variable isEqualTo(Variable v)
Takes two variables and returns the equality operator solution. The symbol for the equality operator is ==. This method should provide functionality such that x.isEqualTo(y) is equivalent to x == y. This operator is not required and can therefore throw the UnsupportedOperatorException. If the variable passed to this operator is of a wrong type a SyntaxException should be thrown.

Parameters:
v - - the variable to operate on
Returns:
the operator's result which should be a true or false solution
Throws:
SyntaxException - if v is the wrong type of variable
UnsupportedOperatorException - if this operator is not supported.

notEqualTo

Variable notEqualTo(Variable v)
Takes two variables and returns the inequality operator solution. The symbol for the inequality operator is !=. This method should provide functionality such that x.notEqualTo(y) is equivalent to x != y. This operator is not required and can therefore throw the UnsupportedOperatorException. If the variable passed to this operator is of a wrong type a SyntaxException should be thrown.

Parameters:
v - - the variable to operate on
Returns:
the operator's result which should be a true or false solution
Throws:
SyntaxException - if v is the wrong type of variable
UnsupportedOperatorException - if this operator is not supported.

greaterThan

Variable greaterThan(Variable v)
Takes two variables and returns the greater than operator solution. The symbol for the greater than operator is >. This method should provide functionality such that x.greaterThan(y) is equivalent to x > y. This operator is not required and can therefore throw the UnsupportedOperatorException. If the variable passed to this operator is of a wrong type a SyntaxException should be thrown.

Parameters:
v - - the variable to operate on
Returns:
the operator's result which should be a true or false solution
Throws:
SyntaxException - if v is the wrong type of variable
UnsupportedOperatorException - if this operator is not supported.

lessThan

Variable lessThan(Variable v)
Takes two variables and returns the less than operator solution. The symbol for the less than operator is <. This method should provide functionality such that x.lessThan(y) is equivalent to x < y. This operator is not required and can therefore throw the UnsupportedOperatorException. If the variable passed to this operator is of a wrong type a SyntaxException should be thrown.

Parameters:
v - - the variable to operate on
Returns:
the operator's result which should be a true or false solution
Throws:
SyntaxException - if v is the wrong type of variable
UnsupportedOperatorException - if this operator is not supported.

greaterEqual

Variable greaterEqual(Variable v)
Takes two variables and returns the greater than or equal to operator solution. The symbol for the greater than or equal to operator is >=. This method should provide functionality such that x.greaterEqual(y) is equivalent to x == y. This operator is not required and can therefore throw the UnsupportedOperatorException. If the variable passed to this operator is of a wrong type a SyntaxException should be thrown.

Parameters:
v - - the variable to operate on
Returns:
the operator's result which should be a true or false solution
Throws:
SyntaxException - if v is the wrong type of variable
UnsupportedOperatorException - if this operator is not supported.

lessEqual

Variable lessEqual(Variable v)
Takes two variables and returns the less than or equal to operator solution. The symbol for the less than or equal to operator is <=. This method should provide functionality such that x.lessEqual(y) is equivalent to x <= y. This operator is not required and can therefore throw the UnsupportedOperatorException. If the variable passed to this operator is of a wrong type a SyntaxException should be thrown.

Parameters:
v - - the variable to operate on
Returns:
the operator's result which should be a true or false solution
Throws:
SyntaxException - if v is the wrong type of variable
UnsupportedOperatorException - if this operator is not supported.

and

Variable and(Variable v)
Takes two variables and returns the logical and operator solution. The symbol for the and operator is &. This method should provide functionality such that x.and(y) is equivalent to x & y. This operator is not required and can therefore throw the UnsupportedOperatorException. If the variable passed to this operator is of a wrong type a SyntaxException should be thrown.

Parameters:
v - - the variable to operate on
Returns:
the operator's result which should be a true or false solution
Throws:
SyntaxException - if v is the wrong type of variable
UnsupportedOperatorException - if this operator is not supported.

or

Variable or(Variable v)
Takes two variables and returns the logical inclusive or operator solution. The symbol for the inclusive or operator is |. This method should provide functionality such that x.or(y) is equivalent to x | y. This operator is not required and can therefore throw the UnsupportedOperatorException. If the variable passed to this operator is of a wrong type a SyntaxException should be thrown.

Parameters:
v - - the variable to operate on
Returns:
the operator's result which should be a true or false solution
Throws:
SyntaxException - if v is the wrong type of variable
UnsupportedOperatorException - if this operator is not supported.

xor

Variable xor(Variable v)
Takes two variables and returns the logical exclusive operator solution. The symbol for the exclusive or operator is (+). This method should provide functionality such that x.xor(y) is equivalent to x (+) y. This operator is not required and can therefore throw the UnsupportedOperatorException. If the variable passed to this operator is of a wrong type a SyntaxException should be thrown.

Parameters:
v - - the variable to operate on
Returns:
the operator's result which should be a true or false solution
Throws:
SyntaxException - if v is the wrong type of variable
UnsupportedOperatorException - if this operator is not supported.

not

Variable not()
Returns the result of the logical not (complement) of this variable. The symbol for the not operator is !. This method should provide functionality such that x.not() is equivalent to !x. This operator is not required and can therefore throw the UnsupportedOperatorException.

Parameters:
v - - the variable to operate on
Returns:
the operator's result which should be a true or false solution
Throws:
UnsupportedOperatorException - if this operator is not supported.

subscript

Variable subscript(Variable sub)
Returns the result of a simple, one variable subscript of this variable. The symbol for the subscript operator is []. This method should provide functionality such that x.subscript(y) is equivalent to x[y]. This operator is not required and can therefore throw the UnsupportedOperatorException.

Parameters:
sub - - the variable to operate on
Returns:
the operator's result
Throws:
SyntaxException - if sub is the wrong type of variable
UnsupportedOperatorException - if this operator is not supported.

subscript

Variable subscript(Variable sub1,
                   Variable sub2)
Returns the result of a two variable subscript of this variable. The symbol for the subscript operator is []. This method should provide functionality such that x.subscript(y,z) is equivalent to x[y:z]. This operator is not required and can therefore throw the UnsupportedOperatorException.

Parameters:
sub1 - - the first subscript variable
sub2 - - the second subscript variable
Returns:
the operator's result
Throws:
SyntaxException - if sub1 or sub2 are the wrong types of variables
UnsupportedOperatorException - if this operator is not supported.

setLiteral

void setLiteral(boolean literal)
Defines whether or not this variable is a literal variable. If true, then the variable cannot be assigned. If false, then the variable is a defined variable and can be assigned. If this is set to true, than the assign(Variable) method will throw a SyntaxException.

Parameters:
literal - - whether or not this is a literal value.

isLiteral

boolean isLiteral()
Returns whether or not this variable is a literal variable.

Returns:
whether or not this variable is literal.

setConstant

void setConstant(boolean constant)
Defines whether or not this variable is a constant variable. If true, then the variable cannot be assigned, and if false, then the variable can be assigned. If true, than the assign(Variable) method will throw a SyntaxException

Parameters:
constant - - whether or not this is a constant variable.

isConstant

boolean isConstant()
Returns whether or not this variable is a constant variable.

Returns:
whether or not this variable is constant.

setFunctionReference

void setFunctionReference(boolean functionReference)

isFunctionReference

boolean isFunctionReference()

getType

java.lang.String getType()
Returns a string name of this particular variable type. For example, for an integer variable type, one might have this method return "int". This method should not vary based on the contents of the variable.

Returns:
the string name of this variable type

copy

Variable copy()
Returns a copy of this variable.

Returns:
a copy with the same value of this variable.