刘光辉
4 小时以前 06f314545ac3514d7ce28939920866ae8188d31c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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;
        }
    }
}