Class Variable

java.lang.Object
parser.Variable
All Implemented Interfaces:
Savable, Serializable

public class Variable extends Object implements Savable
See Also:
  • Field Details

    • name

      private String name
    • type

      private TYPE type
    • value

      private String value
    • units

      private String units
    • constant

      private boolean constant
    • fullName

      private String fullName
      The full name of the variable
    • PI

      public static final Variable PI
      The constant PI
    • ans

      public static Variable ans
      The last answer variable used for flexibility on computational systems.
    • e

      public static Variable e
  • Constructor Details

    • Variable

      public Variable(String name)
    • Variable

      public Variable(String name, String value, boolean constant)
      Parameters:
      name - the name of the Variable object e.g A,B...e.t.c
      value - the value stored by the Variable object
      constant - 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(String name, String fullName, String value, boolean constant)
      Parameters:
      name - the name of the Variable object e.g A,B...e.t.c
      fullName - the full name of the Variable object
      value - the value stored by the Variable object
      constant - 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(String name, double value, boolean constant)
      Parameters:
      name - the name of the Variable object e.g A,B...e.t.c
      value - the value stored by the Variable object
      constant - 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

      public void setType(TYPE type)
    • getType

      public TYPE getType()
    • setFullName

      public void setFullName(String fullName)
    • getFullName

      public 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(String var)
      Parameters:
      var -
      Returns:
      true if the variable is a valid Variable starting character
    • isVariableString

      public static boolean isVariableString(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(String unit)
    • isSystemVar

      public static boolean isSystemVar(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(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 String getSystemConstantValue(String name)
      Parameters:
      name - the name of the system constant
      Returns:
      the constant value associated with it.
    • isExpNumber

      public static boolean isExpNumber(String str)
      Parameters:
      str - the name of the String variable
      Returns:
      true if the variable is ë
    • isPI

      public static boolean isPI(String str)
      Parameters:
      str - the name of the String variable
      Returns:
      true if the variable is PI
    • isTheta

      public static boolean isTheta(String str)
      Parameters:
      str - the name of the String variable
      Returns:
      true if the variable is theta
    • isLastEvaluatedAnswer

      public static boolean isLastEvaluatedAnswer(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(String name)
      Parameters:
      name - mutator method that changes the name of the variable
    • getName

      public String getName()
      Returns:
      the String property of the variable
    • setValue

      public void setValue(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 String getValue()
      returns the value of the variable
      Returns:
      the value stored in the variable
    • setUnits

      public void setUnits(String units)
    • getUnits

      public String getUnits()
    • getSimpleVarIndex

      public static int getSimpleVarIndex(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(Object obj)
      Overrides:
      equals in class Object
    • parse

      public static Variable parse(String enc)
      Parameters:
      enc - The encoded format of the byte array: [num1, num2, num3, num4, ...]
      Returns:
      the Variable object that represents the encoded data
    • serialize

      public String serialize()
      Specified by:
      serialize in interface Savable
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • main

      public static void main(String[] args)
      Parameters:
      args -