Class Formula

java.lang.Object
studio.magemonkey.fabled.data.formula.Formula
All Implemented Interfaces:
IValue

public class Formula extends Object implements IValue
Represents a basic math equation read from left to right, ignoring order of operations. Currently this only supports addition, subtraction, multiplication, and division.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Formula(String equation, CustomValue... defined)
    Creates a new formula from a config string
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    compute(double... input)
    Calculates the formula using the given base value and attribute.
    boolean
    Whether the equation was valid when parsed.
    Negates the output of the formula for future computations
    Returns the equation string for toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • Formula

      public Formula(String equation, CustomValue... defined)
      Creates a new formula from a config string
      Parameters:
      equation - equation string
  • Method Details

    • negate

      public Formula negate()
      Negates the output of the formula for future computations
      Returns:
      the negated Formula
    • compute

      public double compute(double... input)
      Calculates the formula using the given base value and attribute. If the formula is invalid, this returns the value.
      Specified by:
      compute in interface IValue
      Parameters:
      input - the input data
      Returns:
      computed value
    • toString

      public String toString()
      Returns the equation string for toString
      Overrides:
      toString in class Object
      Returns:
      the equation string
    • isValid

      public boolean isValid()
      Whether the equation was valid when parsed.
      Returns:
      whether the equation was valid