Package net.diversionmc.parser.pattern
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 interfaceOperationSolver.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 aOperationSolverrecord. -
Method Summary
Modifier and Type Method Description booleanequals(java.lang.Object o)Indicates whether some other object is "equal to" this one.inthashCode()Returns a hash code value for this object.java.util.function.Predicate<O>opCheck()Returns the value of theopCheckrecord component.OperationSolver.TriOperator<V,O>operator()Returns the value of theoperatorrecord component.booleanrightToLeft()Returns the value of therightToLeftrecord component.voidsolve(java.util.List<Pointable> list)java.lang.StringtoString()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 aOperationSolverrecord.- Parameters:
rightToLeft- the value for therightToLeftrecord componentopCheck- the value for theopCheckrecord componentoperator- the value for theoperatorrecord component
-
-
Method Details
-
solve
-
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:
toStringin classjava.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:
hashCodein classjava.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 withObjects::equals(Object,Object); primitive components are compared with '=='.- Specified by:
equalsin classjava.lang.Record- Parameters:
o- the object with which to compare- Returns:
trueif this object is the same as theoargument;falseotherwise.
-
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
-