Class EquationSolver
left = right (the engine side of the SOLVE operator).
For a given row, the participating columns are the distinct
attribute references in left and right. When exactly one of
them is NULL, it is the unknown u: because each column appears
at most once across the equation (enforced by semantic validation), u
lives in exactly one side and the other side is fully evaluable. The known
side is evaluated to a target value, then the side containing u is
walked top-down, applying the inverse of each arithmetic operation, until
u itself is reached and assigned.
Rows without exactly one NULL participating column are returned
unchanged: a fully-populated row is already complete, and a row with two or
more blanks is underdetermined.
Division precision matches OperandEvaluator: ten fractional digits,
RoundingMode.HALF_UP, trailing zeros stripped; division by zero throws
an EvaluationException.
Instances are stateless apart from the immutable OperandEvaluator
reference and are therefore thread-safe.
-
Constructor Summary
ConstructorsConstructorDescriptionEquationSolver(OperandEvaluator evaluator) Constructs a solver that evaluates the known parts of an equation with the given operand evaluator. -
Method Summary
Modifier and TypeMethodDescriptionReturnsrowwith its singleNULLparticipating column filled by invertingleft = right, orrowunchanged when it does not have exactly oneNULLparticipating column (or the column cannot be located in the row's schema).
-
Constructor Details
-
EquationSolver
Constructs a solver that evaluates the known parts of an equation with the given operand evaluator.- Parameters:
evaluator- the evaluator for fully-known sub-expressions; must not be null
-
-
Method Details
-
solve
Returnsrowwith its singleNULLparticipating column filled by invertingleft = right, orrowunchanged when it does not have exactly oneNULLparticipating column (or the column cannot be located in the row's schema).- Parameters:
left- the left-hand side of the equation; must not be nullright- the right-hand side of the equation; must not be nullrow- the row to complete; must not be null- Returns:
- the completed row, or
rowunchanged - Throws:
EvaluationException- on division by zero or a non-numeric operand
-