net.scheinerman.phoenix.interpreter.variables
Class StringVariable

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

public class StringVariable
extends AbstractVariable


Field Summary
private  NumberVariable FALSE
           
private  NumberVariable TRUE
           
private  java.lang.String value
          The value of the string variable.
 
Fields inherited from class net.scheinerman.phoenix.interpreter.variables.AbstractVariable
constant, functionReference, literal
 
Constructor Summary
StringVariable()
          Creates a new, default StringVariable.
StringVariable(java.lang.String value)
          Creates a new StringVariable with a given String as a starting value for the variable.
StringVariable(java.lang.String value, boolean constant)
          Creates a new StringVariable with a given String as a starting value for the variable and the choice to indicate whether the variable is constant or not.
StringVariable(Variable value)
          Creates a new StringVariable with a given Variable as a starting value for the variable.
StringVariable(Variable value, boolean constant)
          Creates a new StringVariable with a given Variable as a starting value for the variable and the choice to indicate whether the variable is constant or not.
 
Method Summary
 Variable add(Variable v)
          The add (+) operator on two StrVar objects produces the concatenation of the two strings.
 Variable and(Variable v)
          This operator is not supported for String variables.
 void assign(java.lang.String value)
           
 void assign(Variable v)
          Assigns a new variable value to this variable.
 void check(Variable v)
           
private  int convertValue(int value)
           
 Variable copy()
          Returns a copy of this variable.
 Variable divide(Variable v)
          This operator is not supported for String variables.
 Variable exp(Variable v)
          This operator is not supported for String variables.
 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.
 Variable isEqualTo(Variable v)
          The equality operator (==) on two strings returns Constants.TRUE if the two strings are equal and Constants.FALSE otherwise.
 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)
          This operator is not supported for String variables.
 Variable multiply(Variable v)
          The multiply (*) operator on a StrVar takes a NumVar that must be an integer value.
 Variable not()
          This operator is not supported for String variables.
 Variable notEqualTo(Variable v)
          Takes two variables and returns the inequality operator solution.
 Variable or(Variable v)
          This operator is not supported for String variables.
 Variable round(Variable v)
          This operator is not supported for String variables.
 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)
          This operator is not supported for String variables.
 java.lang.String toString()
           
 java.lang.String value()
           
 Variable xor(Variable v)
          This operator is not supported for String variables.
 
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
See Also:
Constants.TRUE

FALSE

private final NumberVariable FALSE
See Also:
Constants.FALSE

value

private java.lang.String value
The value of the string variable.

Constructor Detail

StringVariable

public StringVariable()
Creates a new, default StringVariable. By default the value of the string is the empty string, it is a literal and not constant.


StringVariable

public StringVariable(java.lang.String value)
Creates a new StringVariable with a given String as a starting value for the variable. By default, this is a literal, non-constant variable.

Parameters:
value - - The value to be assigned to this StringVariable.

StringVariable

public StringVariable(Variable value)
Creates a new StringVariable with a given Variable as a starting value for the variable. By default, this is a literal, non-constant variable.

Parameters:
value - - The value to be assigned to this StringVariable.

StringVariable

public StringVariable(java.lang.String value,
                      boolean constant)
Creates a new StringVariable with a given String as a starting value for the variable and the choice to indicate whether the variable is constant or not. By default, this is a literal variable.

Parameters:
value - - The value to be assigned to this StringVariable.
constant - - Whether or not this variable is constant.

StringVariable

public StringVariable(Variable value,
                      boolean constant)
Creates a new StringVariable with a given Variable as a starting value for the variable and the choice to indicate whether the variable is constant or not. By default, this is a literal variable.

Parameters:
value - - The value to be assigned to this StringVariable.
constant - - Whether or not this variable is constant.
Method Detail

assign

public void assign(java.lang.String value)

assign

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

value

public java.lang.String value()

getType

public java.lang.String getType()
Description copied from interface: Variable
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.

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

add

public Variable add(Variable v)
The add (+) operator on two StrVar objects produces the concatenation of the two strings.

Parameters:
v - a StrVar to concatenate this one with.
Returns:
the concatenated StrVar.
Throws:
SyntaxException - if v is not a StrVar.

subtract

public Variable subtract(Variable v)
This operator is not supported for String variables.

Parameters:
v - - the variable to operate on
Returns:
the operator's result
Throws:
UnsupportedOperatorException - always.

multiply

public Variable multiply(Variable v)
The multiply (*) operator on a StrVar takes a NumVar that must be an integer value. The result is the StrVar copied the number of times specified by the argument and concatenated together. So the statements "A" * 3 == "AAA" or "AB" * 4 == "ABABABAB" are both true.

Parameters:
v - a NumVar object
Returns:
a string multiplied v times.

divide

public Variable divide(Variable v)
This operator is not supported for String variables.

Parameters:
v - - the variable to operate on
Returns:
the operator's result
Throws:
UnsupportedOperatorException - always.

mod

public Variable mod(Variable v)
This operator is not supported for String variables.

Parameters:
v - - the variable to operate on
Returns:
the operator's result
Throws:
UnsupportedOperatorException - always.

exp

public Variable exp(Variable v)
This operator is not supported for String variables.

Parameters:
v - - the variable to operate on
Returns:
the operator's result
Throws:
UnsupportedOperatorException - always.

round

public Variable round(Variable v)
This operator is not supported for String variables.

Parameters:
v - - the variable to operate on
Returns:
the operator's result
Throws:
UnsupportedOperatorException - always.

isEqualTo

public Variable isEqualTo(Variable v)
The equality operator (==) on two strings returns Constants.TRUE if the two strings are equal and Constants.FALSE otherwise.

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)
This operator is not supported for String variables.

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

or

public Variable or(Variable v)
This operator is not supported for String variables.

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

xor

public Variable xor(Variable v)
This operator is not supported for String variables.

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

not

public Variable not()
This operator is not supported for String variables.

Returns:
the operator's result which should be a true or false solution
Throws:
UnsupportedOperatorException - always.

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

convertValue

private int convertValue(int value)

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.