Package net.diversionmc.parser.pattern
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceOperation between two values and an operator. -
Constructor Summary
ConstructorsConstructorDescriptionOperationSolver(boolean rightToLeft, Predicate<O> opCheck, OperationSolver.TriOperator<V, O> operator) Creates an instance of aOperationSolverrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.opCheck()Returns the value of theopCheckrecord component.operator()Returns the value of theoperatorrecord component.booleanReturns the value of therightToLeftrecord component.voidfinal StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
OperationSolver
public OperationSolver(boolean rightToLeft, Predicate<O> opCheck, OperationSolver.TriOperator<V, O> operator) Creates an instance of aOperationSolverrecord class.- Parameters:
rightToLeft- the value for therightToLeftrecord componentopCheck- the value for theopCheckrecord componentoperator- the value for theoperatorrecord component
-
-
Method Details
-
solve
-
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
rightToLeft
public boolean rightToLeft()Returns the value of therightToLeftrecord component.- Returns:
- the value of the
rightToLeftrecord component
-
opCheck
Returns the value of theopCheckrecord component.- Returns:
- the value of the
opCheckrecord component
-
operator
Returns the value of theoperatorrecord component.- Returns:
- the value of the
operatorrecord component
-