Record 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, java.util.function.Predicate<O extends Pointable> opCheck, OperationSolver.TriOperator<V extends Pointable,​O extends Pointable> operator)
extends java.lang.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.

  • Nested Class Summary

    Nested Classes
    Modifier and Type Class Description
    static interface  OperationSolver.TriOperator<T,​O>
    Operation between two values and an operator.
  • Constructor Summary

    Constructors
    Constructor Description
    OperationSolver​(boolean rightToLeft, java.util.function.Predicate<O> opCheck, OperationSolver.TriOperator<V,​O> operator)
    Creates an instance of a OperationSolver record.
  • Method Summary

    Modifier and Type Method Description
    boolean equals​(java.lang.Object o)
    Indicates whether some other object is "equal to" this one.
    int hashCode()
    Returns a hash code value for this object.
    java.util.function.Predicate<O> opCheck()
    Returns the value of the opCheck record component.
    OperationSolver.TriOperator<V,​O> operator()
    Returns the value of the operator record component.
    boolean rightToLeft()
    Returns the value of the rightToLeft record component.
    void solve​(java.util.List<Pointable> list)  
    java.lang.String toString()
    Returns a string representation of this record.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • OperationSolver

      public OperationSolver​(boolean rightToLeft, java.util.function.Predicate<O> opCheck, OperationSolver.TriOperator<V,​O> operator)
      Creates an instance of a OperationSolver record.
      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​(java.util.List<Pointable> list)
    • toString

      public final java.lang.String toString()
      Returns a string representation of this record. The representation contains the name of the type, followed by the name and value of each of the record components.
      Specified by:
      toString in class java.lang.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 java.lang.Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals​(java.lang.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 java.lang.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 java.util.function.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