package jnpf.elnService.formula;
|
|
import jnpf.elnFormula.FormulaDiagnostic;
|
import jnpf.elnFormula.FormulaType;
|
|
import java.util.ArrayList;
|
import java.util.Collections;
|
import java.util.List;
|
|
public interface FormulaValidationService {
|
|
ValidationResult validate(FormulaValidationRequest request);
|
|
final class FormulaValidationRequest {
|
private final String expression;
|
private final List<ParameterSlot> parameters;
|
private final FormulaType resultType;
|
private final Integer roundScale;
|
private final String roundMode;
|
|
public FormulaValidationRequest(String expression, List<ParameterSlot> parameters,
|
FormulaType resultType, Integer roundScale, String roundMode) {
|
this.expression = expression;
|
this.parameters = parameters == null ? null
|
: Collections.unmodifiableList(new ArrayList<>(parameters));
|
this.resultType = resultType;
|
this.roundScale = roundScale;
|
this.roundMode = roundMode;
|
}
|
|
public String getExpression() {
|
return expression;
|
}
|
|
public List<ParameterSlot> getParameters() {
|
return parameters;
|
}
|
|
public FormulaType getResultType() {
|
return resultType;
|
}
|
|
public Integer getRoundScale() {
|
return roundScale;
|
}
|
|
public String getRoundMode() {
|
return roundMode;
|
}
|
}
|
|
final class ParameterSlot {
|
private final String code;
|
private final String displayName;
|
private final FormulaType type;
|
|
public ParameterSlot(String code, String displayName, FormulaType type) {
|
this.code = code;
|
this.displayName = displayName;
|
this.type = type;
|
}
|
|
public String getCode() {
|
return code;
|
}
|
|
public String getDisplayName() {
|
return displayName;
|
}
|
|
public FormulaType getType() {
|
return type;
|
}
|
}
|
|
final class ValidationResult {
|
private final List<FormulaDiagnostic> diagnostics;
|
private final String latex;
|
private final FormulaType inferredType;
|
|
public ValidationResult(List<FormulaDiagnostic> diagnostics, String latex,
|
FormulaType inferredType) {
|
this.diagnostics = Collections.unmodifiableList(new ArrayList<>(diagnostics));
|
this.latex = latex;
|
this.inferredType = inferredType;
|
}
|
|
public List<FormulaDiagnostic> getDiagnostics() {
|
return diagnostics;
|
}
|
|
public String getLatex() {
|
return latex;
|
}
|
|
public FormulaType getInferredType() {
|
return inferredType;
|
}
|
|
public boolean hasErrors() {
|
for (FormulaDiagnostic diagnostic : diagnostics) {
|
if (diagnostic.getSeverity() == FormulaDiagnostic.Severity.ERROR) {
|
return true;
|
}
|
}
|
return false;
|
}
|
}
|
}
|