Package parser
Class Variable
java.lang.Object
parser.Variable
- All Implemented Interfaces:
Savable,java.io.Serializable
public class Variable extends java.lang.Object implements Savable
- Author:
- GBENRO template for modeling/creating variable objects
- See Also:
- Serialized Form
-
Field Summary
-
Constructor Summary
Constructors Constructor Description Variable(java.lang.String name)Variable(java.lang.String name, double value, boolean constant)Variable(java.lang.String name, java.lang.String value, boolean constant)Variable(java.lang.String name, java.lang.String fullName, java.lang.String value, boolean constant) -
Method Summary
Modifier and Type Method Description booleanequals(java.lang.Object obj)java.lang.StringgetFullName()java.lang.StringgetName()intgetSimpleVarIndex()static intgetSimpleVarIndex(java.lang.String var)static java.lang.StringgetSystemConstantValue(java.lang.String name)TYPEgetType()java.lang.StringgetUnits()java.lang.StringgetValue()returns the value of the variablebooleanisConstant()static booleanisExpNumber(java.lang.String str)static booleanisLastEvaluatedAnswer(java.lang.String str)static booleanisPI(java.lang.String str)booleanisSimpleVar()static booleanisSystemConstant(java.lang.String str)static booleanisSystemVar(java.lang.String str)booleanisTheta()static booleanisTheta(java.lang.String str)static booleanisVariableBeginner(java.lang.String var)static booleanisVariableBuilder(java.lang.String unit)static booleanisVariableString(java.lang.String var)If the name is a string of alphabets and is not an operator name, then it is a valid variable name.static voidmain(java.lang.String[] args)static Variableparse(java.lang.String enc)java.lang.Stringserialize()voidsetConstant(boolean constant)sets the nature of the Variable object to either Variable or constantvoidsetFullName(java.lang.String fullName)voidsetName(java.lang.String name)voidsetType(TYPE type)voidsetUnits(java.lang.String units)voidsetValue(java.lang.String value)changes the value stored in the variablejava.lang.StringtoString()
-
Field Details
-
Constructor Details
-
Variable
public Variable(java.lang.String name) -
Variable
public Variable(java.lang.String name, java.lang.String value, boolean constant)- Parameters:
name- the name of the Variable object e.g A,B...e.t.cvalue- the value stored by the Variable objectconstant- the nature of the Variable object whether it is modifiable or not. If constant = true , then the Variable object represents a constant, whose value cannot be altered.Else,it represents a Variable object whose value can change.
-
Variable
public Variable(java.lang.String name, java.lang.String fullName, java.lang.String value, boolean constant)- Parameters:
name- the name of the Variable object e.g A,B...e.t.cfullName- the full name of the Variable objectvalue- the value stored by the Variable objectconstant- the nature of the Variable object whether it is modifiable or not. If constant = true , then the Variable object represents a constant, whose value cannot be altered.Else,it represents a Variable object whose value can change.
-
Variable
public Variable(java.lang.String name, double value, boolean constant)- Parameters:
name- the name of the Variable object e.g A,B...e.t.cvalue- the value stored by the Variable objectconstant- the nature of the Variable object whether it is modifiable or not. If constant = true , then the Variable object represents a constant, whose value cannot be altered.Else,it represents a Variable object whose value can change.
-
-
Method Details
-
setType
-
getType
-
setFullName
public void setFullName(java.lang.String fullName) -
getFullName
public java.lang.String getFullName() -
isConstant
public boolean isConstant()- Returns:
- true if the Variable object is a constant.
-
setConstant
public void setConstant(boolean constant)sets the nature of the Variable object to either Variable or constant- Parameters:
constant- = true if the Variable object is to be changed into a constant and constant = false if the Variable object is to be changed into a Variable object
-
isTheta
public boolean isTheta() -
isVariableBeginner
public static boolean isVariableBeginner(java.lang.String var)- Parameters:
var-- Returns:
- true if the variable is a valid Variable starting character
-
isVariableString
public static boolean isVariableString(java.lang.String var)If the name is a string of alphabets and is not an operator name, then it is a valid variable name. If the name is alphanumeric,it is a valid variable name.- Parameters:
var- the string to check.- Returns:
- true if the variable is a valid Variable object name.
-
isVariableBuilder
public static boolean isVariableBuilder(java.lang.String unit) -
isSystemVar
public static boolean isSystemVar(java.lang.String str)- Parameters:
str- the name of the String variable- Returns:
- true if the variable is one that is already defined by the parser for its own purposes. An example of such a variable is any constant parameter recognized by the parser, i.e to which the parser has attached a meaning already. Also any parameter such as the "ans" parameter which returns the last value calculated by the parser is regarded by the parser to be a system variable.
-
isSystemConstant
public static boolean isSystemConstant(java.lang.String str)- Parameters:
str- the name of the String variable- Returns:
- true if the variable is a constant one that is already defined by the parser for its own purposes. An example of such a constant is any constant defined by the parser e.g PI and so on.
-
getSystemConstantValue
public static java.lang.String getSystemConstantValue(java.lang.String name)- Parameters:
name- the name of the system constant- Returns:
- the constant value associated with it.
-
isExpNumber
public static boolean isExpNumber(java.lang.String str)- Parameters:
str- the name of the String variable- Returns:
- true if the variable is ë
-
isPI
public static boolean isPI(java.lang.String str)- Parameters:
str- the name of the String variable- Returns:
- true if the variable is PI
-
isTheta
public static boolean isTheta(java.lang.String str)- Parameters:
str- the name of the String variable- Returns:
- true if the variable is theta
-
isLastEvaluatedAnswer
public static boolean isLastEvaluatedAnswer(java.lang.String str)- Parameters:
str- the name of the String variable- Returns:
- true if the variable is the last result evaluated
-
isSimpleVar
public boolean isSimpleVar()- Returns:
- true if the variable is a simple one i.e A-Z or theta
-
setName
public void setName(java.lang.String name)- Parameters:
name- mutator method that changes the name of the variable
-
getName
public java.lang.String getName()- Returns:
- the String property of the variable
-
setValue
public void setValue(java.lang.String value)changes the value stored in the variable- Parameters:
value- The value to be stored. Sometimes the value contains a unit. To support this, the user should place a space between the value and the units.
-
getValue
public java.lang.String getValue()returns the value of the variable- Returns:
- the value stored in the variable
-
setUnits
public void setUnits(java.lang.String units) -
getUnits
public java.lang.String getUnits() -
getSimpleVarIndex
public static int getSimpleVarIndex(java.lang.String var)- Parameters:
var- the String property of the variable.This method returns the index of the Variable object that has this String property.- Returns:
- The index of the Variable object that has this String property.
-
getSimpleVarIndex
public int getSimpleVarIndex()- Returns:
-
equals
public boolean equals(java.lang.Object obj)- Overrides:
equalsin classjava.lang.Object
-
parse
- Parameters:
enc- The encoded format of the byte array: [num1, num2, num3, num4, ...]- Returns:
- the Variable object that represents the encoded data
-
serialize
public java.lang.String serialize() -
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
main
public static void main(java.lang.String[] args)- Parameters:
args-
-