net.scheinerman.phoenix.interpreter.variables
Class NumberVariable

java.lang.Object
  extended by net.scheinerman.phoenix.interpreter.variables.AbstractVariable
      extended by net.scheinerman.phoenix.interpreter.variables.NumberVariable
All Implemented Interfaces:
Variable

public class NumberVariable
extends AbstractVariable


Field Summary
private  NumberVariable FALSE
           
private  NumberVariable TRUE
           
private  double value
           
 
Fields inherited from class net.scheinerman.phoenix.interpreter.variables.AbstractVariable
constant, functionReference, literal
 
Constructor Summary
NumberVariable()
          Creates a new NumberVariable with the default value of 0.
NumberVariable(double value)
          Creates a new NumberVariable with the given value.
NumberVariable(double value, boolean constant)
           
NumberVariable(Variable value)
          Creates a new NumberVariable with the given value.
NumberVariable(Variable value, boolean constant)
           
 
Method Summary
 Variable add(Variable v)
          Returns a NumberVariable that is a sum of this variable and the the parameter.
 Variable and(Variable v)
          Takes two variables and returns the logical and operator solution.
 void assign(double value)
          Assigns a new value to this variable.
 void assign(Variable v)
          Assigns a new variable value to this variable.
 void check(Variable v)
           
 Variable copy()
          Returns a copy of this variable.
 Variable divide(Variable v)
          Returns a NumberVariable that is a quotient of this variable and the the parameter.
 Variable exp(Variable v)
          Takes two variables and returns the exponentiation operator solution.
 java.lang.String getType()
          Always returns "num".
 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.
 Variable isEqualTo(Variable v)
          Takes two variables and returns the equality operator solution.
 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)
          Returns a NumberVariable that is a product of this variable and the the parameter.
 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.
 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)
          Returns a NumberVariable that is a difference of this variable and the the parameter.
 java.lang.String toString()
           
 double value()
          Returns the double value of this variable.
 Variable xor(Variable v)
          Takes two variables and returns the logical exclusive operator solution.
 
Methods inherited from class net.scheinerman.phoenix.interpreter.variables.AbstractVariable
equals, isConstant, isFunctionReference, isLiteral, setConstant, setFunctionReference, setLiteral
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TRUE

private final NumberVariable TRUE

FALSE

private final NumberVariable FALSE

value

private double value
Constructor Detail

NumberVariable

public NumberVariable()
Creates a new NumberVariable with the default value of 0.


NumberVariable

public NumberVariable(double value)
Creates a new NumberVariable with the given value.

Parameters:
value - - the initial value

NumberVariable

public NumberVariable(Variable value)
Creates a new NumberVariable with the given value.

Parameters:
value - - the initial value

NumberVariable

public NumberVariable(double value,
                      boolean constant)

NumberVariable

public NumberVariable(Variable value,
                      boolean constant)
Method Detail

assign

public void assign(double value)
Assigns a new value to this variable.

Parameters:
value - - the new value

assign

public void assign(Variable v)
Assigns a new variable value to this variable.

Parameters:
v - - the new value
Throws:
SyntaxException - if the variable is not a NumberVariable

value

public double value()
Returns the double value of this variable.

Returns:
the double value.

getType

public java.lang.String getType()
Always returns "num".

Specified by:
getType in interface Variable
Overrides:
getType in class AbstractVariable
Returns:
"void"

add

public Variable add(Variable v)
Returns a NumberVariable that is a sum of this variable and the the parameter. The parameter must be a NumberVariable otherwise an exception will be thrown. This is the addition (+) operator.

Parameters:
v - - the variable to add to
Returns:
the sum of this variable and the parameter
Throws:
SyntaxException - if the argument is not a NumberVariable

subtract

public Variable subtract(Variable v)
Returns a NumberVariable that is a difference of this variable and the the parameter. The parameter must be a NumberVariable otherwise an exception will be thrown. This is the subtraction (-) operator.

Parameters:
v - - the variable that will be subtracted
Returns:
the difference returned when the paramater is subtracted from this variable
Throws:
SyntaxException - if the argument is not a NumberVariable

multiply

public Variable multiply(Variable v)
Returns a NumberVariable that is a product of this variable and the the parameter. The parameter must be a NumberVariable otherwise an exception will be thrown. This is the addition (*) operator.

Parameters:
v - - the variable to multiply by
Returns:
the product of this variable and the parameter
Throws:
SyntaxException - if the argument is not a NumberVariable

divide

public Variable divide(Variable v)
Returns a NumberVariable that is a quotient of this variable and the the parameter. The parameter must be a NumberVariable otherwise an exception will be thrown. This is the addition (*) operator.

Parameters:
v - - the variable to divide by
Returns:
the quotient returned when this variable is divided by the parameter
Throws:
SyntaxException - if the argument is not a NumberVariable

mod

public Variable mod(Variable v)
Description copied from interface: Variable
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

exp

public Variable exp(Variable v)
Description copied from interface: Variable
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

round

public Variable round(Variable v)
Description copied from interface: Variable
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

isEqualTo

public Variable isEqualTo(Variable v)
Description copied from interface: Variable
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

notEqualTo

public Variable notEqualTo(Variable v)
Description copied from interface: Variable
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

greaterThan

public Variable greaterThan(Variable v)
Description copied from interface: Variable
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

greaterEqual

public Variable greaterEqual(Variable v)
Description copied from interface: Variable
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

lessThan

public Variable lessThan(Variable v)
Description copied from interface: Variable
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

lessEqual

public Variable lessEqual(Variable v)
Description copied from interface: Variable
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

and

public Variable and(Variable v)
Description copied from interface: Variable
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

or

public Variable or(Variable v)
Description copied from interface: Variable
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

xor

public Variable xor(Variable v)
Description copied from interface: Variable
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

not

public Variable not()
Description copied from interface: Variable
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.

Returns:
the operator's result which should be a true or false solution

subscript

public Variable subscript(Variable sub)
Description copied from interface: Variable
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

subscript

public Variable subscript(Variable sub1,
                          Variable sub2)
Description copied from interface: Variable
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

check

public void check(Variable v)

toString

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

copy

public Variable copy()
Description copied from interface: Variable
Returns a copy of this variable.

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