刘光辉
119 分钟以前 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package jnpf.elnFormula;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
 
public final class FormulaAst {
 
    private FormulaAst() {
    }
 
    public interface Node {
        int getStartOffset();
 
        int getEndOffset();
    }
 
    public enum LiteralKind {
        DECIMAL,
        TEXT,
        BOOLEAN,
        NULL
    }
 
    private abstract static class BaseNode implements Node {
        private final int startOffset;
        private final int endOffset;
 
        private BaseNode(int startOffset, int endOffset) {
            this.startOffset = startOffset;
            this.endOffset = endOffset;
        }
 
        @Override
        public final int getStartOffset() {
            return startOffset;
        }
 
        @Override
        public final int getEndOffset() {
            return endOffset;
        }
    }
 
    public static final class Literal extends BaseNode {
        private final LiteralKind kind;
        private final Object value;
 
        public Literal(int startOffset, int endOffset, LiteralKind kind, Object value) {
            super(startOffset, endOffset);
            this.kind = kind;
            this.value = value;
        }
 
        public LiteralKind getKind() {
            return kind;
        }
 
        public Object getValue() {
            return value;
        }
 
        public BigDecimal getDecimalValue() {
            return (BigDecimal) value;
        }
    }
 
    public static final class Parameter extends BaseNode {
        private final String code;
 
        public Parameter(int startOffset, int endOffset, String code) {
            super(startOffset, endOffset);
            this.code = code;
        }
 
        public String getCode() {
            return code;
        }
    }
 
    public static final class Unary extends BaseNode {
        private final String operator;
        private final Node operand;
 
        public Unary(int startOffset, int endOffset, String operator, Node operand) {
            super(startOffset, endOffset);
            this.operator = operator;
            this.operand = operand;
        }
 
        public String getOperator() {
            return operator;
        }
 
        public Node getOperand() {
            return operand;
        }
    }
 
    public static final class Binary extends BaseNode {
        private final String operator;
        private final Node left;
        private final Node right;
 
        public Binary(int startOffset, int endOffset, String operator, Node left, Node right) {
            super(startOffset, endOffset);
            this.operator = operator;
            this.left = left;
            this.right = right;
        }
 
        public String getOperator() {
            return operator;
        }
 
        public Node getLeft() {
            return left;
        }
 
        public Node getRight() {
            return right;
        }
    }
 
    public static final class FunctionCall extends BaseNode {
        private final String name;
        private final List<Node> arguments;
 
        public FunctionCall(int startOffset, int endOffset, String name, List<Node> arguments) {
            super(startOffset, endOffset);
            this.name = name;
            this.arguments = Collections.unmodifiableList(new ArrayList<>(arguments));
        }
 
        public String getName() {
            return name;
        }
 
        public List<Node> getArguments() {
            return arguments;
        }
    }
}