|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--Variable
The Variable
class allows the user to represent a mathematical variable.
A variable has a name and a value. For example, X + 3 * X = Y is a mathematical equation.
The characters X and Y are mathematical variables which represent numeric values.
Similarly, density = mass / volume is a mathematical equation with the variables density,
mass and volume. Because in the equation Z = (X + 3) * X the two X's are not in fact
different variables, but represent different references to the same value, each
Variable
object does not maintain its own value. Rather there is a static member
VariableDereferencer de
which maintains a list of all
variable names and maintains a value for each.
Field Summary | |
protected static VariableDereferencer |
d
An object which stores the values of the variables.This in an implementer of VariableDereferencer which stores the values for all of the variables. |
java.lang.String |
name
The name of the variable in the dereferencer. |
Constructor Summary | |
Variable()
A default constructor. |
|
Variable(java.lang.String s)
Instantiates a variable with just a name. |
|
Variable(java.lang.String s,
int value)
This contructor allows a variable to be given an intial value. |
Method Summary | |
static VariableDereferencer |
dereferencer()
|
int |
hashCode()
Returns the hash code from String for the name of the current Variable . |
int |
intValue()
Returns the same as valueOf() . |
boolean |
isFalse()
A Variable operates along the same lines as an integer variable in C. |
boolean |
isTrue()
A Variable operates along the same lines as an integer variable in C. |
static void |
setDereferencer()
This sets the object which is responsible for storing the values of the variables and returning them. |
static void |
setDereferencer(VariableDereferencer de)
This sets the object which is responsible for storing the values of the variables and returning them. |
void |
setValue(int i)
Assigns a value to the reference in the VariableDereferencer with the same name as the current name. |
java.lang.String |
toString()
Returns a string containing the name of the variable followed by its value. |
int |
valueOf()
Returns the current value of the variable. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
protected static VariableDereferencer d
public java.lang.String name
Constructor Detail |
public Variable()
public Variable(java.lang.String s)
s
- a string representing the name of the variablepublic Variable(java.lang.String s, int value)
s
- a string representing the name of the variablevalue
- an initial value for the variableMethod Detail |
public int valueOf()
public int intValue()
valueOf()
. Added to make the Variable
useable in a similar contect to Integer
.valueOf()
public int hashCode()
Variable
.String.hashCode()
public void setValue(int i)
i
- value to be assignedpublic static void setDereferencer()
public static void setDereferencer(VariableDereferencer de)
de
- class implementing VariableDereferencer to store variable valuespublic boolean isTrue()
false
, otherwise it is considered
true
.public boolean isFalse()
false
, otherwise it is considered
true
.public java.lang.String toString()
public static VariableDereferencer dereferencer()
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |