/
Parameters.java
185 lines (161 loc) · 6.21 KB
/
Parameters.java
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package net.aufdemrand.denizen.utilities.javaluator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
/** The parameters of an evaluator.
* <br>An evaluator may have different parameters as the supported operators, the supported functions, etc ...
* @author Jean-Marc Astesana
* @see <a href="../../../license.html">License information</a>
*/
public class Parameters {
private String functionSeparator;
private final ArrayList<Operator> operators;
private final ArrayList<Function> functions;
private final ArrayList<Constant> constants;
private final Map<String, String> translations;
private final ArrayList<BracketPair> expressionBrackets;
private final ArrayList<BracketPair> functionBrackets;
/** Constructor.
* <br>This method builds an instance with no operator, no function, no constant, no translation and no bracket
* <br>Function argument separator is set to ','.
*/
public Parameters() {
this.operators = new ArrayList<Operator>();
this.functions = new ArrayList<Function>();
this.constants = new ArrayList<Constant>();
this.translations = new HashMap<String, String>();
this.expressionBrackets = new ArrayList<BracketPair>();
this.functionBrackets = new ArrayList<BracketPair>();
setFunctionArgumentSeparator(',');
}
/** Gets the supported operators.
* @return a Collection of operators.
*/
public Collection<Operator> getOperators() {
return this.operators;
}
/** Gets the supported functions.
* @return a Collection of functions.
*/
public Collection<Function> getFunctions() {
return this.functions;
}
/** Gets the supported constants.
* @return a Collection of constants.
*/
public Collection<Constant> getConstants() {
return this.constants;
}
/** Gets the supported bracket pairs for expressions.
* @return a Collection of bracket pairs.
*/
public Collection<BracketPair> getExpressionBrackets() {
return this.expressionBrackets;
}
/** Gets the supported bracket pairs for functions.
* @return a Collection of bracket pairs.
*/
public Collection<BracketPair> getFunctionBrackets() {
return this.functionBrackets;
}
/** Adds operators to the supported ones.
* @param operators The operators to be added.
*/
public void addOperators(Collection<Operator> operators) {
this.operators.addAll(operators);
}
/** Adds an operator to the supported ones.
* @param operator The added operator
*/
public void add(Operator operator) {
this.operators.add(operator);
}
/** Adds functions to the supported ones.
* @param functions The functions to be added.
*/
public void addFunctions(Collection<Function> functions) {
this.functions.addAll(functions);
}
/** Adds a function to the supported ones.
* @param function The added function
*/
public void add(Function function) {
this.functions.add(function);
}
/** Adds constants to the supported ones.
* @param constants The constants to be added.
*/
public void addConstants(Collection<Constant> constants) {
this.constants.addAll(constants);
}
/** Adds a constant to the supported ones.
* @param constant The added constant
*/
public void add(Constant constant) {
this.constants.add(constant);
}
/** Adds a new bracket pair to the expression bracket list.
* @param pair A bracket pair
*/
public void addExpressionBracket(BracketPair pair) {
this.expressionBrackets.add(pair);
}
/** Adds bracket pairs to the expression bracket list.
* @param brackets The brackets to be added.
*/
public void addExpressionBrackets(Collection<BracketPair> brackets) {
this.expressionBrackets.addAll(brackets);
}
/** Adds a new bracket pair to the function bracket list.
* @param pair A bracket pair
*/
public void addFunctionBracket(BracketPair pair) {
this.functionBrackets.add(pair);
}
/** Adds bracket pairs to the function bracket list.
* @param brackets The brackets to be added.
*/
public void addFunctionBrackets(Collection<BracketPair> brackets) {
this.functionBrackets.addAll(brackets);
}
/** Sets the translated term for a function.
* <br>Using this method, you can localize the names of some built-in functions. For instance,
* for french people,you can use this method to use "somme" instead of "sum" with the SUM built-in
* function of DoubleEvaluator.
* @param function The function you want to translate the name
* @param translatedName The translated name
* @see DoubleEvaluator#SUM
*/
public void setTranslation(Function function, String translatedName) {
setTranslation(function.getName(), translatedName);
}
/** Sets the translated term for a constant.
* @param constant The constant you want to translate the name
* @param translatedName The translated name
* @see #setTranslation(Function, String)
*/
public void setTranslation(Constant constant, String translatedName) {
setTranslation(constant.getName(), translatedName);
}
private void setTranslation(String name, String translatedName) {
this.translations.put(name, translatedName);
}
String getTranslation(String originalName) {
String translation = this.translations.get(originalName);
return translation==null?originalName:translation;
}
/** Sets the function argument separator.
* <br>Its default value is ','.
* @param separator The new separator
*/
public void setFunctionArgumentSeparator(char separator) {
this.functionSeparator = new String(new char[]{separator});
}
/** Gets the function argument separator.
* @return a string
*/
public String getFunctionArgumentSeparator() {
return this.functionSeparator;
}
}