Class Variable

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

public class Variable extends Object implements Savable
Author:
GBENRO template for modeling/creating variable objects
See Also:
  • Field Details

    • lastResult

      public static MathExpression.EvalResult lastResult
    • PI

      public static final Variable PI
      The constant PI
    • PI_ALT

      public static final Variable PI_ALT
    • PI_ALT_1

      public static final Variable PI_ALT_1
    • GOLDEN_RATIO

      public static final Variable GOLDEN_RATIO
    • 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)
      Parameters:
      name - The name of the variable (will create and initialize the variable with the given name to 0.0) or a variable assignment statement like a=4; or b=a; (where a is an existing stored variable)
    • Variable

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

      public Variable(String name, String fullName, double 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.
  • Method Details

    • set

      public void set(double[] frame, double newValue)
      High-Speed Handle Method: SET Use this in your loops to update values without Map lookups.
    • get

      public double get(double[] frame)
      High-Speed Handle Method: GET Use this in your evaluator loop.
    • getFrameIndex

      public int getFrameIndex()
    • setFrameIndex

      public void setFrameIndex(int frameIndex)
    • 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 ë
    • isGoldenRatio

      public static boolean isGoldenRatio(String str)
    • isPI

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

      public static double getConstantValue(String str)
    • 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 final 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.
    • setValue

      public final void setValue(double value)
    • getValue

      public double 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
    • toJSON

      public String toJSON()