Record Class OperationSolver<V extends Pointable,O extends Pointable>

java.lang.Object
java.lang.Record
net.diversionmc.parser.pattern.OperationSolver<V,O>
Type Parameters:
V - Input Value / Result type.
O - Operator type.
Record Components:
rightToLeft - Whether the solver should run right to left (e.g. power, assign, etc) or left to right (e.g. sum, product, etc).
opCheck - Check whether a given piece is an operator. Only even pieces in a file are checked.
operator - Action that combines two values and an operator into a new resulting value.

public record OperationSolver<V extends Pointable,O extends Pointable>(boolean rightToLeft, Predicate<O extends Pointable> opCheck, OperationSolver.TriOperator<V extends Pointable,O extends Pointable> operator) extends Record

When confronted with a pattern of kind <value>[<operator><value>]..., you do not need to completely rewrite a custom pattern, as Parser comes with a tool specifically made for that.

It reads the list (that contains both already parsed sentences for values and pieces for operators) either right to left or left to right (some operators require that, like power “^”), and reduces matching triplets of <value><operator><value> to a single <value> sentence.

When creating a solver, you supply a predicate that defines an operator (to check the type of the operator for the order of operations) and a function that converts the triplet to a sentence.

  • Constructor Details

    • OperationSolver

      public OperationSolver(boolean rightToLeft, Predicate<O> opCheck, OperationSolver.TriOperator<V,O> operator)
      Creates an instance of a OperationSolver record class.
      Parameters:
      rightToLeft - the value for the rightToLeft record component
      opCheck - the value for the opCheck record component
      operator - the value for the operator record component
  • Method Details

    • solve

      public void solve(List<Pointable> list)
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • rightToLeft

      public boolean rightToLeft()
      Returns the value of the rightToLeft record component.
      Returns:
      the value of the rightToLeft record component
    • opCheck

      public Predicate<O> opCheck()
      Returns the value of the opCheck record component.
      Returns:
      the value of the opCheck record component
    • operator

      public OperationSolver.TriOperator<V,O> operator()
      Returns the value of the operator record component.
      Returns:
      the value of the operator record component