svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.lib / org.gvsig.expressionevaluator.lib.impl / src / main / java / org / gvsig / expressionevaluator / impl / DefaultExpressionBuilder.java @ 46050
History | View | Annotate | Download (45.9 KB)
1 | 44006 | jjdelcerro | package org.gvsig.expressionevaluator.impl; |
---|---|---|---|
2 | 43020 | jjdelcerro | |
3 | 45523 | jjdelcerro | import java.awt.Color; |
4 | 43020 | jjdelcerro | import java.text.MessageFormat; |
5 | 44763 | jjdelcerro | import java.text.ParseException; |
6 | import java.text.SimpleDateFormat; |
||
7 | 43020 | jjdelcerro | import java.util.ArrayList; |
8 | import java.util.Collections; |
||
9 | 44763 | jjdelcerro | import java.util.Date; |
10 | 43020 | jjdelcerro | import java.util.HashSet; |
11 | import java.util.List; |
||
12 | 46050 | omartinez | import java.util.Map; |
13 | 43020 | jjdelcerro | import java.util.Objects; |
14 | import java.util.Set; |
||
15 | import org.apache.commons.lang3.StringUtils; |
||
16 | 44198 | jjdelcerro | import org.gvsig.expressionevaluator.Code; |
17 | 44274 | jjdelcerro | import org.gvsig.expressionevaluator.Expression; |
18 | 43020 | jjdelcerro | |
19 | 44006 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionBuilder; |
20 | 44644 | jjdelcerro | import static org.gvsig.expressionevaluator.ExpressionBuilder.PARAMETER_TYPE_CONSTANT; |
21 | import static org.gvsig.expressionevaluator.ExpressionBuilder.PARAMETER_TYPE_VARIABLE; |
||
22 | 44759 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
23 | 44644 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
24 | 44198 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionUtils; |
25 | import org.gvsig.expressionevaluator.Formatter; |
||
26 | 44759 | jjdelcerro | import org.gvsig.expressionevaluator.ReprMethod; |
27 | 44790 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
28 | import org.gvsig.tools.dataTypes.Coercion; |
||
29 | import org.gvsig.tools.dataTypes.DataTypesManager; |
||
30 | 46050 | omartinez | import org.gvsig.tools.util.PropertiesSupportHelper; |
31 | 43093 | jjdelcerro | |
32 | 44198 | jjdelcerro | @SuppressWarnings({"UseSpecificCatch" ,"OverridableMethodCallInConstructor"}) |
33 | 44006 | jjdelcerro | public class DefaultExpressionBuilder implements ExpressionBuilder { |
34 | 44198 | jjdelcerro | |
35 | private static final String FORMAT_QUOTE_FOR_STRINGS = "'"; |
||
36 | private static final String FORMAT_QUOTE_FOR_IDENTIFIERS = "\""; |
||
37 | 44006 | jjdelcerro | |
38 | 44198 | jjdelcerro | private static final String FORMAT_TRUE = "TRUE"; |
39 | private static final String FORMAT_FALSE = "FALSE"; |
||
40 | 43020 | jjdelcerro | |
41 | 44198 | jjdelcerro | private static final String FORMAT_GROUP = "( {0} )"; |
42 | 43093 | jjdelcerro | |
43 | 44198 | jjdelcerro | private static final String FORMAT_ISNULL = "( ({0}) IS NULL )"; |
44 | 44361 | jjdelcerro | private static final String FORMAT_NOTISNULL = "( ({0}) IS NOT NULL )"; |
45 | 44198 | jjdelcerro | private static final String FORMAT_OPERATOR_NOT = "( NOT ({0}) )"; |
46 | 43093 | jjdelcerro | |
47 | 44262 | jjdelcerro | private static final String FORMAT_OPERATOR_AND = "({0} AND {1})"; |
48 | 45327 | omartinez | private static final String FORMAT_OPERATOR_OR = "({0} OR {1})"; |
49 | // private static final String FORMAT_OPERATOR_OR2 = "{0} OR {1}";
|
||
50 | // private static final String FORMAT_OPERATOR_OR2 = "({0}) OR ({1})";
|
||
51 | 44198 | jjdelcerro | private static final String FORMAT_OPERATOR_EQ = "( ({0}) = ({1}) )"; |
52 | private static final String FORMAT_OPERATOR_NE = "( ({0}) <> ({1}) )"; |
||
53 | private static final String FORMAT_OPERATOR_GT = "( ({0}) > ({1}) )"; |
||
54 | private static final String FORMAT_OPERATOR_GE = "( ({0}) >= ({1}) )"; |
||
55 | private static final String FORMAT_OPERATOR_LT = "( ({0}) < ({1}) )"; |
||
56 | private static final String FORMAT_OPERATOR_LE = "( ({0}) <= ({1}) )"; |
||
57 | private static final String FORMAT_OPERATOR_LIKE = "( ({0}) LIKE ({1}) )"; |
||
58 | private static final String FORMAT_OPERATOR_ILIKE = "( ({0}) ILIKE ({1}) )"; |
||
59 | private static final String FORMAT_OPERATOR_ADD = "{0} + {1}"; |
||
60 | private static final String FORMAT_OPERATOR_SUBST = "{0} - {1}"; |
||
61 | 44262 | jjdelcerro | private static final String FORMAT_OPERATOR_MULT = "({0} * {1})"; |
62 | private static final String FORMAT_OPERATOR_DIV = "({0} / {1})"; |
||
63 | 44198 | jjdelcerro | private static final String FORMAT_OPERATOR_CONCAT = "{0} || {1}"; |
64 | 46050 | omartinez | private final PropertiesSupportHelper propertiesHelper; |
65 | 43093 | jjdelcerro | |
66 | 44769 | jjdelcerro | public class GroupBase extends AbstractValue implements Group { |
67 | 43093 | jjdelcerro | |
68 | 43020 | jjdelcerro | protected Value value;
|
69 | 43093 | jjdelcerro | |
70 | 43020 | jjdelcerro | public GroupBase(Value value) {
|
71 | this.value = value;
|
||
72 | } |
||
73 | |||
74 | @Override
|
||
75 | 44198 | jjdelcerro | public Value value() {
|
76 | 43020 | jjdelcerro | return value;
|
77 | } |
||
78 | |||
79 | @Override
|
||
80 | public void accept(Visitor visitor, VisitorFilter filter) { |
||
81 | 43093 | jjdelcerro | super.accept(visitor, filter);
|
82 | this.value.accept(visitor, filter);
|
||
83 | 43020 | jjdelcerro | } |
84 | 43093 | jjdelcerro | |
85 | 43020 | jjdelcerro | @Override
|
86 | 44376 | jjdelcerro | public void replace(Value target, Value replacement) { |
87 | if( this.value == target ) { |
||
88 | this.value = replacement;
|
||
89 | } else {
|
||
90 | this.value.replace(target, replacement);
|
||
91 | } |
||
92 | } |
||
93 | |||
94 | @Override
|
||
95 | 43020 | jjdelcerro | public String toString() { |
96 | 44769 | jjdelcerro | return this.toString(formatter()); |
97 | 43020 | jjdelcerro | } |
98 | 44198 | jjdelcerro | |
99 | @Override
|
||
100 | public String toString(Formatter<Value> formatter) { |
||
101 | 44296 | jjdelcerro | if( formatter!=null && formatter.canApply(this) ) { |
102 | 44198 | jjdelcerro | return formatter.format(this); |
103 | } |
||
104 | return MessageFormat.format(FORMAT_GROUP, this.value.toString()); |
||
105 | } |
||
106 | 43020 | jjdelcerro | } |
107 | |||
108 | 44769 | jjdelcerro | public class VariableBase extends AbstractValue implements Variable { |
109 | 43093 | jjdelcerro | |
110 | 43020 | jjdelcerro | protected String name; |
111 | 44644 | jjdelcerro | protected ExpressionBuilder builder;
|
112 | |||
113 | public VariableBase(ExpressionBuilder builder, String name) { |
||
114 | 43020 | jjdelcerro | this.name = name;
|
115 | 44644 | jjdelcerro | this.builder = builder;
|
116 | 43020 | jjdelcerro | } |
117 | 43093 | jjdelcerro | |
118 | 43020 | jjdelcerro | @Override
|
119 | 44198 | jjdelcerro | public String name() { |
120 | 43020 | jjdelcerro | return this.name; |
121 | } |
||
122 | |||
123 | @Override
|
||
124 | public String toString() { |
||
125 | 44769 | jjdelcerro | return this.toString(formatter()); |
126 | 44198 | jjdelcerro | } |
127 | |||
128 | @Override
|
||
129 | public String toString(Formatter<Value> formatter) { |
||
130 | 44296 | jjdelcerro | if( formatter!=null && formatter.canApply(this) ) { |
131 | 44198 | jjdelcerro | return formatter.format(this); |
132 | } |
||
133 | 44644 | jjdelcerro | return this.builder.identifier(this.name); |
134 | 43020 | jjdelcerro | } |
135 | |||
136 | @Override
|
||
137 | public int compareTo(Variable o) { |
||
138 | 44198 | jjdelcerro | return this.name.compareTo(o.name()); |
139 | 43020 | jjdelcerro | } |
140 | |||
141 | @Override
|
||
142 | public boolean equals(Object obj) { |
||
143 | 43093 | jjdelcerro | if (!(obj instanceof Variable)) { |
144 | 43020 | jjdelcerro | return false; |
145 | } |
||
146 | 44198 | jjdelcerro | return this.name.equals(((Variable) obj).name()); |
147 | 43020 | jjdelcerro | } |
148 | |||
149 | @Override
|
||
150 | public int hashCode() { |
||
151 | int hash = 7; |
||
152 | hash = 37 * hash + Objects.hashCode(this.name); |
||
153 | return hash;
|
||
154 | } |
||
155 | } |
||
156 | |||
157 | 44769 | jjdelcerro | public class ParameterBase extends AbstractValue implements Parameter { |
158 | 43093 | jjdelcerro | |
159 | protected String name; |
||
160 | 43020 | jjdelcerro | protected Object value; |
161 | 44644 | jjdelcerro | protected int type; |
162 | 43093 | jjdelcerro | |
163 | public ParameterBase() {
|
||
164 | 44644 | jjdelcerro | this.type = PARAMETER_TYPE_CONSTANT;
|
165 | 43093 | jjdelcerro | this.name = null; |
166 | this.value = null; |
||
167 | 43020 | jjdelcerro | } |
168 | |||
169 | @Override
|
||
170 | public Parameter as_constant() {
|
||
171 | 44644 | jjdelcerro | this.type = PARAMETER_TYPE_CONSTANT;
|
172 | 43093 | jjdelcerro | if (this.value == null && this.name != null) { |
173 | this.value = this.name; |
||
174 | } |
||
175 | 43020 | jjdelcerro | return this; |
176 | } |
||
177 | 43093 | jjdelcerro | |
178 | 43020 | jjdelcerro | @Override
|
179 | public Parameter as_variable() {
|
||
180 | 44644 | jjdelcerro | this.type = PARAMETER_TYPE_VARIABLE;
|
181 | 43093 | jjdelcerro | if (this.value != null && this.name == null) { |
182 | this.name = (String) this.value; |
||
183 | } |
||
184 | 43020 | jjdelcerro | return this; |
185 | } |
||
186 | 44644 | jjdelcerro | |
187 | 43020 | jjdelcerro | @Override
|
188 | 44198 | jjdelcerro | public String name() { |
189 | 43093 | jjdelcerro | switch (this.type) { |
190 | 44644 | jjdelcerro | case PARAMETER_TYPE_VARIABLE:
|
191 | 43093 | jjdelcerro | return this.name; |
192 | 44644 | jjdelcerro | case PARAMETER_TYPE_CONSTANT:
|
193 | 43093 | jjdelcerro | if (this.value == null) { |
194 | return null; |
||
195 | } |
||
196 | return this.value.toString(); |
||
197 | 43020 | jjdelcerro | default:
|
198 | 43093 | jjdelcerro | if (this.name != null) { |
199 | return this.name; |
||
200 | } |
||
201 | if (this.value != null) { |
||
202 | return this.value.toString(); |
||
203 | } |
||
204 | 43020 | jjdelcerro | return null; |
205 | } |
||
206 | } |
||
207 | |||
208 | @Override
|
||
209 | 44644 | jjdelcerro | public int type() { |
210 | return this.type; |
||
211 | 43020 | jjdelcerro | } |
212 | |||
213 | @Override
|
||
214 | 44644 | jjdelcerro | public boolean is_constant() { |
215 | return this.type == PARAMETER_TYPE_CONSTANT; |
||
216 | 43020 | jjdelcerro | } |
217 | |||
218 | @Override
|
||
219 | public boolean is_variable() { |
||
220 | 44644 | jjdelcerro | return this.type == PARAMETER_TYPE_VARIABLE; |
221 | 43020 | jjdelcerro | } |
222 | |||
223 | @Override
|
||
224 | 43093 | jjdelcerro | public Parameter value(Object value) { |
225 | this.value = value;
|
||
226 | return this; |
||
227 | } |
||
228 | |||
229 | @Override
|
||
230 | public Parameter name(String name) { |
||
231 | 44644 | jjdelcerro | this.type = PARAMETER_TYPE_VARIABLE;
|
232 | 43093 | jjdelcerro | this.name = name;
|
233 | return this; |
||
234 | } |
||
235 | |||
236 | @Override
|
||
237 | 44198 | jjdelcerro | public Object value() { |
238 | 43020 | jjdelcerro | try {
|
239 | 43093 | jjdelcerro | switch (this.type) { |
240 | 44644 | jjdelcerro | case PARAMETER_TYPE_CONSTANT:
|
241 | 43020 | jjdelcerro | return this.value; |
242 | 44644 | jjdelcerro | case PARAMETER_TYPE_VARIABLE:
|
243 | 43020 | jjdelcerro | default:
|
244 | 44652 | jjdelcerro | return this.value; |
245 | 43020 | jjdelcerro | } |
246 | 43093 | jjdelcerro | } catch (Exception ex) { |
247 | throw new RuntimeException("Can't get value from parameter.", ex); |
||
248 | 43020 | jjdelcerro | } |
249 | } |
||
250 | |||
251 | @Override
|
||
252 | public String toString() { |
||
253 | 44769 | jjdelcerro | return this.toString(formatter()); |
254 | 44198 | jjdelcerro | } |
255 | |||
256 | @Override
|
||
257 | public String toString(Formatter<Value> formatter) { |
||
258 | 44296 | jjdelcerro | if( formatter!=null && formatter.canApply(this) ) { |
259 | 44198 | jjdelcerro | return formatter.format(this); |
260 | } |
||
261 | 43093 | jjdelcerro | switch (this.type) { |
262 | 44644 | jjdelcerro | case PARAMETER_TYPE_CONSTANT:
|
263 | return Objects.toString(this.value); |
||
264 | |||
265 | case PARAMETER_TYPE_VARIABLE:
|
||
266 | 43020 | jjdelcerro | default:
|
267 | return "?"; |
||
268 | } |
||
269 | 43093 | jjdelcerro | } |
270 | 43020 | jjdelcerro | } |
271 | |||
272 | 44769 | jjdelcerro | public class ConstantBase extends AbstractValue implements Constant { |
273 | 43093 | jjdelcerro | |
274 | 43020 | jjdelcerro | protected Object value; |
275 | 44644 | jjdelcerro | protected ExpressionBuilder builder;
|
276 | |||
277 | public ConstantBase(ExpressionBuilder builder, Object value) { |
||
278 | 43020 | jjdelcerro | this.value = value;
|
279 | 44644 | jjdelcerro | this.builder = builder;
|
280 | 43020 | jjdelcerro | } |
281 | 43093 | jjdelcerro | |
282 | 43020 | jjdelcerro | @Override
|
283 | 44198 | jjdelcerro | public Object value() { |
284 | 43020 | jjdelcerro | return this.value; |
285 | } |
||
286 | |||
287 | @Override
|
||
288 | public String toString() { |
||
289 | 44769 | jjdelcerro | return this.toString(formatter()); |
290 | 44198 | jjdelcerro | } |
291 | |||
292 | @Override
|
||
293 | public String toString(Formatter<Value> formatter) { |
||
294 | 44296 | jjdelcerro | if( formatter!=null && formatter.canApply(this) ) { |
295 | 44198 | jjdelcerro | return formatter.format(this); |
296 | } |
||
297 | if( this.value==null ) { |
||
298 | return "NULL"; |
||
299 | } |
||
300 | if( this.value instanceof byte[] ) { |
||
301 | 44644 | jjdelcerro | return "DECODE('"+this.builder.bytearray_hex((byte[])this.value)+"','hex')"; |
302 | 44198 | jjdelcerro | } |
303 | 43093 | jjdelcerro | if (this.value instanceof String) { |
304 | 44644 | jjdelcerro | return this.builder.string((String) this.value); |
305 | 43020 | jjdelcerro | } |
306 | 43093 | jjdelcerro | if (this.value instanceof Boolean) { |
307 | if (((Boolean) this.value)) { |
||
308 | 44198 | jjdelcerro | return FORMAT_TRUE;
|
309 | 43020 | jjdelcerro | } else {
|
310 | 44198 | jjdelcerro | return FORMAT_FALSE;
|
311 | 43020 | jjdelcerro | } |
312 | } |
||
313 | 44759 | jjdelcerro | ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
314 | ReprMethod repr = manager.getReprMethod(this.value);
|
||
315 | return repr.repr(value);
|
||
316 | 43020 | jjdelcerro | } |
317 | 46010 | jjdelcerro | |
318 | public ExpressionBuilder builder() {
|
||
319 | return this.builder; // Ojo, no esta en el API. |
||
320 | } |
||
321 | 43020 | jjdelcerro | } |
322 | |||
323 | 44769 | jjdelcerro | public class CustomBase extends AbstractValue implements Custom { |
324 | 43093 | jjdelcerro | |
325 | 43020 | jjdelcerro | protected Object value; |
326 | 43093 | jjdelcerro | |
327 | 43020 | jjdelcerro | // Esto es para permitir declarar parametros y columnas en una seccion
|
328 | // custom.
|
||
329 | protected List<Value> values; |
||
330 | 43093 | jjdelcerro | |
331 | 43020 | jjdelcerro | public CustomBase(Object value) { |
332 | this.value = value;
|
||
333 | } |
||
334 | |||
335 | @Override
|
||
336 | public void accept(Visitor visitor, VisitorFilter filter) { |
||
337 | super.accept(visitor, filter);
|
||
338 | 43093 | jjdelcerro | if (this.values != null) { |
339 | 44006 | jjdelcerro | for (Value theValue : values) {
|
340 | theValue.accept(visitor, filter); |
||
341 | 43020 | jjdelcerro | } |
342 | } |
||
343 | } |
||
344 | 43093 | jjdelcerro | |
345 | 43020 | jjdelcerro | @Override
|
346 | 44376 | jjdelcerro | public void replace(Value target, Value replacement) { |
347 | if( this.values == null ) { |
||
348 | return;
|
||
349 | } |
||
350 | for (int i = 0; i < values.size(); i++) { |
||
351 | Value theValue = values.get(i); |
||
352 | if( target == theValue ) {
|
||
353 | values.set(i, replacement); |
||
354 | } else {
|
||
355 | theValue.replace(target, replacement); |
||
356 | } |
||
357 | } |
||
358 | } |
||
359 | |||
360 | @Override
|
||
361 | 44198 | jjdelcerro | public Object value() { |
362 | 43020 | jjdelcerro | return this.value; |
363 | } |
||
364 | |||
365 | @Override
|
||
366 | public Custom add(Variable variable) {
|
||
367 | 43093 | jjdelcerro | if (this.values == null) { |
368 | 43020 | jjdelcerro | this.values = new ArrayList<>(); |
369 | } |
||
370 | this.values.add(variable);
|
||
371 | return this; |
||
372 | } |
||
373 | |||
374 | @Override
|
||
375 | public Custom add(Parameter parameter) {
|
||
376 | 43093 | jjdelcerro | if (this.values == null) { |
377 | 43020 | jjdelcerro | this.values = new ArrayList<>(); |
378 | } |
||
379 | this.values.add(parameter);
|
||
380 | return this; |
||
381 | } |
||
382 | |||
383 | @Override
|
||
384 | public String toString() { |
||
385 | 44769 | jjdelcerro | return this.toString(formatter()); |
386 | 43020 | jjdelcerro | } |
387 | 44198 | jjdelcerro | |
388 | 43020 | jjdelcerro | @Override
|
389 | 44198 | jjdelcerro | public String toString(Formatter<Value> formatter) { |
390 | 44296 | jjdelcerro | if( formatter!=null && formatter.canApply(this) ) { |
391 | 44198 | jjdelcerro | return formatter.format(this); |
392 | 43020 | jjdelcerro | } |
393 | 44198 | jjdelcerro | return Objects.toString(this.value, ""); |
394 | 43020 | jjdelcerro | } |
395 | 43093 | jjdelcerro | } |
396 | 43020 | jjdelcerro | |
397 | 44769 | jjdelcerro | public class FunctionBase extends AbstractValue implements Function { |
398 | 43020 | jjdelcerro | |
399 | protected String name; |
||
400 | protected String format; |
||
401 | 44750 | jjdelcerro | protected List<Value> parameters; |
402 | 43093 | jjdelcerro | |
403 | 43020 | jjdelcerro | public FunctionBase(String name, String format) { |
404 | this.name = name;
|
||
405 | this.format = format;
|
||
406 | } |
||
407 | 43093 | jjdelcerro | |
408 | 44020 | jjdelcerro | public FunctionBase(String name) { |
409 | this(name,null); |
||
410 | } |
||
411 | 44748 | jjdelcerro | |
412 | 43020 | jjdelcerro | @Override
|
413 | 44750 | jjdelcerro | public List<Value> parameters() { |
414 | 43093 | jjdelcerro | if (this.parameters == null) { |
415 | 43020 | jjdelcerro | this.parameters = new ArrayList<>(); |
416 | } |
||
417 | return this.parameters; |
||
418 | 43093 | jjdelcerro | } |
419 | 43020 | jjdelcerro | |
420 | @Override
|
||
421 | 44769 | jjdelcerro | public Function format(String format) { |
422 | this.format = format;
|
||
423 | return this; |
||
424 | } |
||
425 | |||
426 | @Override
|
||
427 | 43020 | jjdelcerro | public Function parameter(Value parameter) {
|
428 | 44750 | jjdelcerro | this.parameters().add(parameter);
|
429 | 43020 | jjdelcerro | return this; |
430 | } |
||
431 | |||
432 | @Override
|
||
433 | 44198 | jjdelcerro | public String name() { |
434 | 43020 | jjdelcerro | return this.name; |
435 | } |
||
436 | |||
437 | @Override
|
||
438 | public void accept(Visitor visitor, VisitorFilter filter) { |
||
439 | 43093 | jjdelcerro | super.accept(visitor, filter);
|
440 | 44644 | jjdelcerro | if( this.parameters!=null ) { |
441 | 44750 | jjdelcerro | for (Value argument : this.parameters) { |
442 | 44748 | jjdelcerro | if( argument!=null ) { |
443 | 44750 | jjdelcerro | argument.accept(visitor, filter); |
444 | 44644 | jjdelcerro | } |
445 | } |
||
446 | 43020 | jjdelcerro | } |
447 | } |
||
448 | |||
449 | @Override
|
||
450 | 44376 | jjdelcerro | public void replace(Value target, Value replacement) { |
451 | 44750 | jjdelcerro | if( this.parameters!=null ) { |
452 | 44376 | jjdelcerro | for (int i = 0; i < parameters.size(); i++) { |
453 | 44750 | jjdelcerro | Value argument = parameters.get(i); |
454 | if( argument == target ) {
|
||
455 | parameters.set(i, replacement); |
||
456 | 44376 | jjdelcerro | } else {
|
457 | 44750 | jjdelcerro | argument.replace(target, replacement); |
458 | 44376 | jjdelcerro | } |
459 | } |
||
460 | 44750 | jjdelcerro | } |
461 | 44376 | jjdelcerro | } |
462 | |||
463 | @Override
|
||
464 | 43020 | jjdelcerro | public String toString() { |
465 | 44769 | jjdelcerro | return this.toString(formatter()); |
466 | 44198 | jjdelcerro | } |
467 | |||
468 | @Override
|
||
469 | public String toString(Formatter<Value> formatter) { |
||
470 | 44296 | jjdelcerro | if( formatter!=null && formatter.canApply(this) ) { |
471 | 44198 | jjdelcerro | return formatter.format(this); |
472 | } |
||
473 | 44020 | jjdelcerro | if( this.format==null ) { |
474 | StringBuilder builder = new StringBuilder(); |
||
475 | builder.append(name); |
||
476 | builder.append("(");
|
||
477 | if (this.parameters != null && !this.parameters.isEmpty()) { |
||
478 | boolean first = true; |
||
479 | 44750 | jjdelcerro | for (Value argument : this.parameters) { |
480 | 44020 | jjdelcerro | if( first ) {
|
481 | first=false;
|
||
482 | 44750 | jjdelcerro | builder.append(argument.toString(formatter)); |
483 | 44020 | jjdelcerro | } else {
|
484 | builder.append(", ");
|
||
485 | 44750 | jjdelcerro | builder.append(argument.toString(formatter)); |
486 | 44020 | jjdelcerro | } |
487 | } |
||
488 | } |
||
489 | builder.append(")");
|
||
490 | return builder.toString();
|
||
491 | } |
||
492 | 43093 | jjdelcerro | if (this.parameters != null && !this.parameters.isEmpty()) { |
493 | 43020 | jjdelcerro | List<String> values = new ArrayList<>(); |
494 | 44750 | jjdelcerro | for (Value argument : this.parameters) { |
495 | values.add(argument.toString(formatter)); |
||
496 | 43020 | jjdelcerro | } |
497 | return MessageFormat.format(format, values.toArray()); |
||
498 | } else {
|
||
499 | return this.format; |
||
500 | } |
||
501 | } |
||
502 | } |
||
503 | 43093 | jjdelcerro | |
504 | 44198 | jjdelcerro | public class MethodBase extends FunctionBase implements Method { |
505 | |||
506 | 44376 | jjdelcerro | private Value instance;
|
507 | 44198 | jjdelcerro | |
508 | public MethodBase(Value instance, String name) { |
||
509 | super(name);
|
||
510 | this.instance = instance;
|
||
511 | } |
||
512 | |||
513 | @Override
|
||
514 | public Value instance() {
|
||
515 | return this.instance; |
||
516 | } |
||
517 | |||
518 | @Override
|
||
519 | public void accept(Visitor visitor, VisitorFilter filter) { |
||
520 | this.instance.accept(visitor, filter);
|
||
521 | super.accept(visitor, filter);
|
||
522 | } |
||
523 | 44376 | jjdelcerro | |
524 | @Override
|
||
525 | public void replace(Value target, Value replacement) { |
||
526 | if( this.instance == target ) { |
||
527 | this.instance = replacement;
|
||
528 | } else {
|
||
529 | this.instance.replace(target, replacement);
|
||
530 | } |
||
531 | } |
||
532 | 44198 | jjdelcerro | |
533 | @Override
|
||
534 | public String toString(Formatter<Value> formatter) { |
||
535 | 44296 | jjdelcerro | if( formatter!=null && formatter.canApply(this) ) { |
536 | 44198 | jjdelcerro | return formatter.format(this); |
537 | } |
||
538 | StringBuilder builder = new StringBuilder(); |
||
539 | builder.append(this.instance.toString(formatter));
|
||
540 | builder.append("->");
|
||
541 | builder.append(this.name());
|
||
542 | builder.append("(");
|
||
543 | if (this.parameters != null && !this.parameters.isEmpty()) { |
||
544 | boolean first = true; |
||
545 | 44750 | jjdelcerro | for (Value argument : this.parameters) { |
546 | 44198 | jjdelcerro | if( first ) {
|
547 | first=false;
|
||
548 | 44750 | jjdelcerro | builder.append(argument.toString(formatter)); |
549 | 44198 | jjdelcerro | } else {
|
550 | builder.append(", ");
|
||
551 | 44750 | jjdelcerro | builder.append(argument.toString(formatter)); |
552 | 44198 | jjdelcerro | } |
553 | } |
||
554 | } |
||
555 | builder.append(")");
|
||
556 | return builder.toString();
|
||
557 | } |
||
558 | } |
||
559 | |||
560 | 45164 | jjdelcerro | public class BinaryOperatorBase extends FunctionBase implements BinaryOperator { |
561 | 43020 | jjdelcerro | |
562 | 45164 | jjdelcerro | private static final int LEFT = 0; |
563 | private static final int RIGHT = 1; |
||
564 | |||
565 | 43020 | jjdelcerro | public BinaryOperatorBase(String name, String format) { |
566 | 45164 | jjdelcerro | super(name, format);
|
567 | this.parameters = new ArrayList<>(); |
||
568 | this.parameters.add(null); |
||
569 | this.parameters.add(null); |
||
570 | 43020 | jjdelcerro | } |
571 | 43093 | jjdelcerro | |
572 | 43020 | jjdelcerro | @Override
|
573 | 45164 | jjdelcerro | public Function parameter(Value parameter) {
|
574 | throw new UnsupportedOperationException("BinaryOperator can support add parameters."); |
||
575 | 43020 | jjdelcerro | } |
576 | 44376 | jjdelcerro | |
577 | @Override
|
||
578 | 45164 | jjdelcerro | public String name() { |
579 | return this.name; |
||
580 | 43020 | jjdelcerro | } |
581 | |||
582 | @Override
|
||
583 | 44198 | jjdelcerro | public BinaryOperator left(Value operand) {
|
584 | 45164 | jjdelcerro | this.parameters.set(LEFT, operand);
|
585 | 43020 | jjdelcerro | return this; |
586 | } |
||
587 | |||
588 | @Override
|
||
589 | 44198 | jjdelcerro | public BinaryOperator right(Value operand) {
|
590 | 45164 | jjdelcerro | this.parameters.set(RIGHT, operand);
|
591 | 43020 | jjdelcerro | return this; |
592 | } |
||
593 | |||
594 | @Override
|
||
595 | 44198 | jjdelcerro | public Value left() {
|
596 | 45164 | jjdelcerro | return this.parameters.get(LEFT); |
597 | 43020 | jjdelcerro | } |
598 | |||
599 | @Override
|
||
600 | 44198 | jjdelcerro | public Value right() {
|
601 | 45164 | jjdelcerro | return this.parameters.get(RIGHT); |
602 | 43020 | jjdelcerro | } |
603 | 43093 | jjdelcerro | |
604 | 43020 | jjdelcerro | @Override
|
605 | public String toString() { |
||
606 | 44769 | jjdelcerro | return this.toString(formatter()); |
607 | 43020 | jjdelcerro | } |
608 | 44198 | jjdelcerro | |
609 | @Override
|
||
610 | public String toString(Formatter<Value> formatter) { |
||
611 | 44296 | jjdelcerro | if( formatter!=null && formatter.canApply(this) ) { |
612 | 44198 | jjdelcerro | return formatter.format(this); |
613 | } |
||
614 | if( this.format==null ) { |
||
615 | StringBuilder builder = new StringBuilder(); |
||
616 | builder.append("(");
|
||
617 | 45164 | jjdelcerro | builder.append(this.left().toString(formatter));
|
618 | 44198 | jjdelcerro | builder.append(" ");
|
619 | builder.append(this.name);
|
||
620 | builder.append(" ");
|
||
621 | 45164 | jjdelcerro | builder.append(this.right().toString(formatter));
|
622 | 44198 | jjdelcerro | builder.append(")");
|
623 | return builder.toString();
|
||
624 | } else {
|
||
625 | return MessageFormat.format( |
||
626 | format, |
||
627 | 45164 | jjdelcerro | this.left().toString(formatter),
|
628 | this.right().toString(formatter)
|
||
629 | 44198 | jjdelcerro | ); |
630 | } |
||
631 | } |
||
632 | 43020 | jjdelcerro | } |
633 | |||
634 | protected Value value;
|
||
635 | 44644 | jjdelcerro | protected ExpressionEvaluatorManager manager;
|
636 | 44769 | jjdelcerro | protected Formatter<ExpressionBuilder.Value> formatter; |
637 | 43093 | jjdelcerro | |
638 | 44644 | jjdelcerro | public DefaultExpressionBuilder(ExpressionEvaluatorManager manager) {
|
639 | this.manager = manager;
|
||
640 | 46050 | omartinez | this.propertiesHelper = new PropertiesSupportHelper(); |
641 | 43020 | jjdelcerro | } |
642 | 44769 | jjdelcerro | |
643 | 46050 | omartinez | @Override
|
644 | public Object getProperty(String name) { |
||
645 | return this.propertiesHelper.getProperty(name); |
||
646 | } |
||
647 | |||
648 | 44769 | jjdelcerro | @Override
|
649 | 46050 | omartinez | public void setProperty(String name, Object value) { |
650 | this.propertiesHelper.setProperty(name, value);
|
||
651 | } |
||
652 | |||
653 | @Override
|
||
654 | public Map<String, Object> getProperties() { |
||
655 | return this.propertiesHelper.getProperties(); |
||
656 | } |
||
657 | |||
658 | @Override
|
||
659 | public void setProperties(Class filter, final Object... values) { |
||
660 | for (int i = 0; i < values.length; i+=2) { |
||
661 | propertiesHelper.setProperty((String) values[i], values[i+1]); |
||
662 | } |
||
663 | this.accept(new Visitor() { |
||
664 | @Override
|
||
665 | public void visit(Visitable v) { |
||
666 | for (int i = 0; i < values.length; i+=2) { |
||
667 | ((Value)v).setProperty((String) values[i], values[i+1]); |
||
668 | } |
||
669 | } |
||
670 | }, new ClassVisitorFilter(filter) );
|
||
671 | } |
||
672 | |||
673 | @Override
|
||
674 | 44769 | jjdelcerro | public Formatter<ExpressionBuilder.Value> formatter() { |
675 | if( this.formatter == null ) { |
||
676 | this.formatter = this.manager.getExpressionBuilderFormatter(); |
||
677 | } |
||
678 | return this.formatter; |
||
679 | } |
||
680 | 43020 | jjdelcerro | |
681 | @Override
|
||
682 | 44259 | jjdelcerro | public boolean isEmpty() { |
683 | return value == null; |
||
684 | } |
||
685 | |||
686 | @Override
|
||
687 | 43020 | jjdelcerro | public ExpressionBuilder createExpressionBuilder() {
|
688 | 44644 | jjdelcerro | return new DefaultExpressionBuilder(this.manager); |
689 | 43020 | jjdelcerro | } |
690 | 43093 | jjdelcerro | |
691 | 43020 | jjdelcerro | @Override
|
692 | 44198 | jjdelcerro | public Value value() {
|
693 | 43020 | jjdelcerro | return this.value; |
694 | } |
||
695 | 43093 | jjdelcerro | |
696 | 43020 | jjdelcerro | @Override
|
697 | 44198 | jjdelcerro | public ExpressionBuilder value(Value value) {
|
698 | 43020 | jjdelcerro | this.value = value;
|
699 | return this; |
||
700 | } |
||
701 | |||
702 | @Override
|
||
703 | public String toString() { |
||
704 | 44889 | omartinez | if (this.value == null) { |
705 | return ""; |
||
706 | } |
||
707 | 43020 | jjdelcerro | return this.value.toString(); |
708 | } |
||
709 | |||
710 | @Override
|
||
711 | 44198 | jjdelcerro | public String toString(Formatter<Value> formatter) { |
712 | 44889 | omartinez | if (this.value == null) { |
713 | return ""; |
||
714 | } |
||
715 | 44198 | jjdelcerro | return this.value.toString(formatter); |
716 | } |
||
717 | 44889 | omartinez | |
718 | @Override
|
||
719 | public String build() { |
||
720 | if (this.value == null) { |
||
721 | return null; |
||
722 | } |
||
723 | return this.value.toString(); |
||
724 | } |
||
725 | |||
726 | @Override
|
||
727 | public String build(Formatter<Value> formatter) { |
||
728 | if (this.value == null) { |
||
729 | return null; |
||
730 | } |
||
731 | return this.value.toString(formatter); |
||
732 | } |
||
733 | 44198 | jjdelcerro | |
734 | @Override
|
||
735 | public Value toValue(String expression) { |
||
736 | try {
|
||
737 | Code code = ExpressionUtils.compile(expression); |
||
738 | return code.toValue(this); |
||
739 | } catch(Throwable ex) { |
||
740 | return custom(expression);
|
||
741 | } |
||
742 | } |
||
743 | |||
744 | @Override
|
||
745 | 43020 | jjdelcerro | public void accept(Visitor visitor, VisitorFilter filter) { |
746 | 43093 | jjdelcerro | if( this.value == null) { |
747 | return;
|
||
748 | } |
||
749 | 43020 | jjdelcerro | this.value.accept(visitor, filter);
|
750 | } |
||
751 | 43093 | jjdelcerro | |
752 | 43020 | jjdelcerro | @Override
|
753 | 44198 | jjdelcerro | public String quote_for_identifiers() { |
754 | return FORMAT_QUOTE_FOR_IDENTIFIERS;
|
||
755 | 43020 | jjdelcerro | } |
756 | 44198 | jjdelcerro | |
757 | 43020 | jjdelcerro | @Override
|
758 | 44198 | jjdelcerro | public String quote_for_strings() { |
759 | return FORMAT_QUOTE_FOR_STRINGS;
|
||
760 | 43020 | jjdelcerro | } |
761 | 44198 | jjdelcerro | |
762 | 43020 | jjdelcerro | @Override
|
763 | public String string(String s) { |
||
764 | 44198 | jjdelcerro | String quote = this.quote_for_strings(); |
765 | 43034 | jjdelcerro | // No se porque no esta disponible wrapIfMissing
|
766 | // return StringUtils.wrapIfMissing(s,quote);
|
||
767 | 43020 | jjdelcerro | if (s.startsWith(quote)) {
|
768 | return s;
|
||
769 | } |
||
770 | 44198 | jjdelcerro | return quote + StringUtils.replace(s,quote,quote+quote) + quote;
|
771 | 43020 | jjdelcerro | } |
772 | 43093 | jjdelcerro | |
773 | 43020 | jjdelcerro | @Override
|
774 | public String identifier(String id) { |
||
775 | 44198 | jjdelcerro | String quote = this.quote_for_identifiers(); |
776 | 43034 | jjdelcerro | // No se porque no esta disponible wrapIfMissing
|
777 | // return StringUtils.wrapIfMissing(id,quote);
|
||
778 | 43020 | jjdelcerro | if (id.startsWith(quote)) {
|
779 | return id;
|
||
780 | } |
||
781 | return quote + id + quote;
|
||
782 | } |
||
783 | |||
784 | @Override
|
||
785 | 44006 | jjdelcerro | public String bytearray_hex(byte[] data) { |
786 | 43020 | jjdelcerro | StringBuilder builder = new StringBuilder(); |
787 | for (byte abyte : data) { |
||
788 | int v = abyte & 0xff; |
||
789 | builder.append(String.format("%02x", v)); |
||
790 | } |
||
791 | return builder.toString();
|
||
792 | } |
||
793 | |||
794 | 44006 | jjdelcerro | @Override
|
795 | public String bytearray_0x(byte[] data) { |
||
796 | 43355 | jjdelcerro | return "0x" + bytearray_hex(data); |
797 | } |
||
798 | |||
799 | 44006 | jjdelcerro | @Override
|
800 | public String bytearray_x(byte[] data) { |
||
801 | 43355 | jjdelcerro | return "x'" + bytearray_hex(data) + "'"; |
802 | 43302 | jjdelcerro | } |
803 | |||
804 | 43093 | jjdelcerro | |
805 | 43020 | jjdelcerro | @Override
|
806 | 44198 | jjdelcerro | public Constant bytearray(byte[] data) { |
807 | 44644 | jjdelcerro | return new ConstantBase(this, data); |
808 | 44198 | jjdelcerro | } |
809 | |||
810 | @Override
|
||
811 | 43020 | jjdelcerro | public Variable variable(String name) { |
812 | 44644 | jjdelcerro | return new VariableBase(this, name); |
813 | 43020 | jjdelcerro | } |
814 | |||
815 | @Override
|
||
816 | public Variable column(String name) { |
||
817 | 44644 | jjdelcerro | return new VariableBase(this, name); |
818 | 43020 | jjdelcerro | } |
819 | 44855 | jjdelcerro | |
820 | 43020 | jjdelcerro | @Override
|
821 | 44855 | jjdelcerro | public Value column(String tableName, String columnName) { |
822 | return getattr(tableName,columnName);
|
||
823 | } |
||
824 | |||
825 | @Override
|
||
826 | 43093 | jjdelcerro | public Parameter parameter(String name) { |
827 | 44198 | jjdelcerro | List<Parameter> parameters = this.parameters(); |
828 | for (Parameter parameter : parameters) {
|
||
829 | if( StringUtils.equalsIgnoreCase(name, parameter.name()) ) {
|
||
830 | return parameter;
|
||
831 | } |
||
832 | 43093 | jjdelcerro | } |
833 | 44198 | jjdelcerro | Parameter parameter = this.parameter();
|
834 | 43093 | jjdelcerro | parameter.name(name); |
835 | return parameter;
|
||
836 | 43020 | jjdelcerro | } |
837 | 43093 | jjdelcerro | |
838 | 43687 | jjdelcerro | @Override
|
839 | 43093 | jjdelcerro | public Parameter parameter() {
|
840 | return new ParameterBase(); |
||
841 | } |
||
842 | |||
843 | 43020 | jjdelcerro | @Override
|
844 | public Constant constant(Object value) { |
||
845 | 44644 | jjdelcerro | return new ConstantBase(this, value); |
846 | 43020 | jjdelcerro | } |
847 | |||
848 | @Override
|
||
849 | 44790 | jjdelcerro | public Constant constant(Object value, Class theClass) { |
850 | try {
|
||
851 | DataTypesManager dataTypeManager = ToolsLocator.getDataTypesManager(); |
||
852 | Coercion coercion = dataTypeManager.getDataType(theClass).getCoercion(); |
||
853 | return this.constant(coercion.coerce(value)); |
||
854 | } catch (Exception ex) { |
||
855 | throw new RuntimeException("Can't coerce value ("+Objects.toString(value)+") to "+theClass.getSimpleName()+".", ex); |
||
856 | } |
||
857 | } |
||
858 | |||
859 | @Override
|
||
860 | public Constant constant(Object value, int type) { |
||
861 | try {
|
||
862 | DataTypesManager dataTypeManager = ToolsLocator.getDataTypesManager(); |
||
863 | Coercion coercion = dataTypeManager.getCoercion(type); |
||
864 | return this.constant(coercion.coerce(value)); |
||
865 | } catch (Exception ex) { |
||
866 | throw new RuntimeException("Can't coerce value ("+Objects.toString(value)+") to "+type+".", ex); |
||
867 | } |
||
868 | } |
||
869 | |||
870 | @Override
|
||
871 | 43020 | jjdelcerro | public Group group(Value value) { |
872 | return new GroupBase(value); |
||
873 | } |
||
874 | 43093 | jjdelcerro | |
875 | 43020 | jjdelcerro | @Override
|
876 | public Custom custom(Object value) { |
||
877 | return new CustomBase(value); |
||
878 | } |
||
879 | |||
880 | 44198 | jjdelcerro | @Override
|
881 | public Method method(Value instance, String name, Value... values) { |
||
882 | MethodBase method = new MethodBase(instance, name);
|
||
883 | for (Value theValue : values) {
|
||
884 | method.parameter(theValue); |
||
885 | } |
||
886 | return method;
|
||
887 | } |
||
888 | |||
889 | @Override
|
||
890 | 44020 | jjdelcerro | public Function function(String name, Value... values) { |
891 | FunctionBase func = new FunctionBase(name);
|
||
892 | for (Value theValue : values) {
|
||
893 | func.parameter(theValue); |
||
894 | } |
||
895 | return func;
|
||
896 | } |
||
897 | |||
898 | public Function builtin_function(String name, String format, Value... values) { |
||
899 | 43093 | jjdelcerro | FunctionBase func = new FunctionBase(name, format);
|
900 | 44006 | jjdelcerro | for (Value theValue : values) {
|
901 | func.parameter(theValue); |
||
902 | 43020 | jjdelcerro | } |
903 | return func;
|
||
904 | } |
||
905 | 43093 | jjdelcerro | |
906 | 44198 | jjdelcerro | @Override
|
907 | public BinaryOperator binaryOperator(String name, Value leftOperand, Value rightOperand) { |
||
908 | return binaryOperator(name, null, leftOperand, rightOperand); |
||
909 | } |
||
910 | |||
911 | 43020 | jjdelcerro | public BinaryOperator binaryOperator(String name, String format, Value leftOperand, Value rightOperand) { |
912 | 43093 | jjdelcerro | BinaryOperator operator = new BinaryOperatorBase(name, format);
|
913 | 44198 | jjdelcerro | operator.left(leftOperand); |
914 | operator.right(rightOperand); |
||
915 | 43020 | jjdelcerro | return operator;
|
916 | } |
||
917 | 43093 | jjdelcerro | |
918 | 43020 | jjdelcerro | @Override
|
919 | 44198 | jjdelcerro | public List<Variable> variables() { |
920 | 43020 | jjdelcerro | final Set<Variable> vars = new HashSet<>(); |
921 | 44748 | jjdelcerro | this.accept((Visitable value1) -> {
|
922 | if (!vars.contains((Variable) value1)) {
|
||
923 | vars.add((Variable) value1); |
||
924 | } |
||
925 | 43093 | jjdelcerro | }, new ClassVisitorFilter(Variable.class));
|
926 | 43020 | jjdelcerro | List<Variable> lvars = new ArrayList<>(vars); |
927 | Collections.sort(lvars);
|
||
928 | return lvars;
|
||
929 | } |
||
930 | 43093 | jjdelcerro | |
931 | 43020 | jjdelcerro | @Override
|
932 | 44198 | jjdelcerro | public List<Parameter> parameters() { |
933 | final List<Parameter> params = new ArrayList<>(); |
||
934 | 44748 | jjdelcerro | this.accept((Visitable value1) -> {
|
935 | params.add((Parameter) value1); |
||
936 | 43093 | jjdelcerro | }, new ClassVisitorFilter(Parameter.class));
|
937 | 43020 | jjdelcerro | return params;
|
938 | } |
||
939 | 44198 | jjdelcerro | |
940 | 43020 | jjdelcerro | @Override
|
941 | 44198 | jjdelcerro | public List<String> parameters_names() { |
942 | List<String> params = new ArrayList<>(); |
||
943 | for (Parameter param : parameters()) {
|
||
944 | Object theValue = param.value();
|
||
945 | String s;
|
||
946 | switch(param.type()) {
|
||
947 | 44644 | jjdelcerro | case PARAMETER_TYPE_CONSTANT:
|
948 | 44198 | jjdelcerro | if( theValue==null ) { |
949 | s = "NULL";
|
||
950 | } else if( theValue instanceof String ) { |
||
951 | s = "'" + (String)theValue + "'"; |
||
952 | |||
953 | } else if( theValue instanceof byte[] ) { |
||
954 | s = bytearray_0x((byte[]) theValue); |
||
955 | |||
956 | } else {
|
||
957 | s = theValue.toString(); |
||
958 | } |
||
959 | break;
|
||
960 | 44644 | jjdelcerro | case PARAMETER_TYPE_VARIABLE:
|
961 | 44198 | jjdelcerro | default:
|
962 | s = "\"" + param.name() + "\""; |
||
963 | } |
||
964 | // if( !params.contains(s) ) { // Ojo que deben ir todos, incluso duplicados.
|
||
965 | params.add(s); |
||
966 | // }
|
||
967 | } |
||
968 | // Collections.sort(params); Ojo, no deben ordenarse.
|
||
969 | return params;
|
||
970 | 43020 | jjdelcerro | } |
971 | 44198 | jjdelcerro | |
972 | @Override
|
||
973 | public List<String> variables_names() { |
||
974 | List<String> vars = new ArrayList<>(); |
||
975 | for (Variable var : this.variables()) { |
||
976 | vars.add(var.name()); |
||
977 | } |
||
978 | Collections.sort(vars);
|
||
979 | return vars;
|
||
980 | } |
||
981 | |||
982 | @Override
|
||
983 | 43020 | jjdelcerro | public ExpressionBuilder set(Value value) {
|
984 | this.value = value;
|
||
985 | return this; |
||
986 | } |
||
987 | |||
988 | @Override
|
||
989 | public ExpressionBuilder and(Value value) {
|
||
990 | 43093 | jjdelcerro | if (this.value == null) { |
991 | 43020 | jjdelcerro | return this.set(value); |
992 | } |
||
993 | 44198 | jjdelcerro | BinaryOperator operator = binaryOperator(OPERATOR_AND, FORMAT_OPERATOR_AND, this.value, value);
|
994 | 43020 | jjdelcerro | this.value = operator;
|
995 | return this; |
||
996 | } |
||
997 | |||
998 | @Override
|
||
999 | public ExpressionBuilder or(Value value) {
|
||
1000 | 43093 | jjdelcerro | if (this.value == null) { |
1001 | 43020 | jjdelcerro | return this.set(value); |
1002 | } |
||
1003 | 44198 | jjdelcerro | BinaryOperator operator = binaryOperator(OPERATOR_OR, FORMAT_OPERATOR_OR, this.value, value);
|
1004 | 43020 | jjdelcerro | this.value = operator;
|
1005 | return this; |
||
1006 | } |
||
1007 | |||
1008 | @Override
|
||
1009 | 44198 | jjdelcerro | public Function is_null(Value value) {
|
1010 | return builtin_function("IS NULL", FORMAT_ISNULL, value); |
||
1011 | 43020 | jjdelcerro | } |
1012 | |||
1013 | @Override
|
||
1014 | 44198 | jjdelcerro | public Function not_is_null(Value value) {
|
1015 | 44361 | jjdelcerro | return builtin_function("IS NOT NULL", FORMAT_NOTISNULL, value); |
1016 | 43020 | jjdelcerro | } |
1017 | |||
1018 | @Override
|
||
1019 | public Function not(Value value) {
|
||
1020 | 44198 | jjdelcerro | return builtin_function(OPERATOR_NOT, FORMAT_OPERATOR_NOT, value);
|
1021 | 43020 | jjdelcerro | } |
1022 | |||
1023 | @Override
|
||
1024 | public BinaryOperator and(Value leftOperand, Value rightOperand) {
|
||
1025 | 44198 | jjdelcerro | return binaryOperator(OPERATOR_AND, FORMAT_OPERATOR_AND, leftOperand, rightOperand);
|
1026 | 43020 | jjdelcerro | } |
1027 | |||
1028 | @Override
|
||
1029 | 44274 | jjdelcerro | public BinaryOperator and(Expression leftOperand, Expression rightOperand) { |
1030 | return binaryOperator(
|
||
1031 | OPERATOR_AND, |
||
1032 | FORMAT_OPERATOR_AND, |
||
1033 | leftOperand.getCode().toValue(), |
||
1034 | rightOperand.getCode().toValue() |
||
1035 | ); |
||
1036 | } |
||
1037 | |||
1038 | @Override
|
||
1039 | public BinaryOperator and(Expression leftOperand, Value rightOperand) { |
||
1040 | return binaryOperator(
|
||
1041 | OPERATOR_AND, |
||
1042 | FORMAT_OPERATOR_AND, |
||
1043 | leftOperand.getCode().toValue(), |
||
1044 | rightOperand |
||
1045 | ); |
||
1046 | } |
||
1047 | |||
1048 | @Override
|
||
1049 | 43020 | jjdelcerro | public BinaryOperator or(Value leftOperand, Value rightOperand) {
|
1050 | 44198 | jjdelcerro | return binaryOperator(OPERATOR_OR, FORMAT_OPERATOR_OR, leftOperand, rightOperand);
|
1051 | 43020 | jjdelcerro | } |
1052 | |||
1053 | @Override
|
||
1054 | public BinaryOperator eq(Value leftOperand, Value rightOperand) {
|
||
1055 | 44198 | jjdelcerro | return binaryOperator("=", FORMAT_OPERATOR_EQ, leftOperand, rightOperand); |
1056 | 43020 | jjdelcerro | } |
1057 | 43093 | jjdelcerro | |
1058 | 43020 | jjdelcerro | @Override
|
1059 | public BinaryOperator ne(Value leftOperand, Value rightOperand) {
|
||
1060 | 44198 | jjdelcerro | return binaryOperator("<>", FORMAT_OPERATOR_NE, leftOperand, rightOperand); |
1061 | 43093 | jjdelcerro | } |
1062 | 43020 | jjdelcerro | |
1063 | @Override
|
||
1064 | public BinaryOperator gt(Value op1, Value op2) {
|
||
1065 | 44198 | jjdelcerro | return binaryOperator(">", FORMAT_OPERATOR_GT, op1, op2); |
1066 | 43020 | jjdelcerro | } |
1067 | |||
1068 | @Override
|
||
1069 | public BinaryOperator ge(Value op1, Value op2) {
|
||
1070 | 44198 | jjdelcerro | return binaryOperator(">=", FORMAT_OPERATOR_GE, op1, op2); |
1071 | 43020 | jjdelcerro | } |
1072 | |||
1073 | @Override
|
||
1074 | public BinaryOperator lt(Value op1, Value op2) {
|
||
1075 | 44198 | jjdelcerro | return binaryOperator("<", FORMAT_OPERATOR_LT, op1, op2); |
1076 | 43020 | jjdelcerro | } |
1077 | |||
1078 | @Override
|
||
1079 | public BinaryOperator le(Value op1, Value op2) {
|
||
1080 | 44198 | jjdelcerro | return binaryOperator("<=", FORMAT_OPERATOR_LE, op1, op2); |
1081 | 43020 | jjdelcerro | } |
1082 | |||
1083 | @Override
|
||
1084 | public BinaryOperator like(Value op1, Value op2) {
|
||
1085 | 44198 | jjdelcerro | return binaryOperator(OPERATOR_LIKE, FORMAT_OPERATOR_LIKE, op1, op2);
|
1086 | 43020 | jjdelcerro | } |
1087 | |||
1088 | @Override
|
||
1089 | public BinaryOperator ilike(Value op1, Value op2) {
|
||
1090 | 44198 | jjdelcerro | return binaryOperator(OPERATOR_ILIKE, FORMAT_OPERATOR_ILIKE, op1, op2);
|
1091 | 43020 | jjdelcerro | } |
1092 | |||
1093 | @Override
|
||
1094 | public BinaryOperator add(Value op1, Value op2) {
|
||
1095 | 44198 | jjdelcerro | return binaryOperator(OPERATOR_ADD, FORMAT_OPERATOR_ADD, op1, op2);
|
1096 | 43020 | jjdelcerro | } |
1097 | |||
1098 | @Override
|
||
1099 | public BinaryOperator subst(Value op1, Value op2) {
|
||
1100 | 44198 | jjdelcerro | return binaryOperator(OPERATOR_SUBST, FORMAT_OPERATOR_SUBST, op1, op2);
|
1101 | 43020 | jjdelcerro | } |
1102 | |||
1103 | @Override
|
||
1104 | public BinaryOperator mult(Value op1, Value op2) {
|
||
1105 | 44198 | jjdelcerro | return binaryOperator(OPERATOR_MULT, FORMAT_OPERATOR_MULT, op1, op2);
|
1106 | 43020 | jjdelcerro | } |
1107 | |||
1108 | @Override
|
||
1109 | public BinaryOperator div(Value op1, Value op2) {
|
||
1110 | 44198 | jjdelcerro | return binaryOperator(OPERATOR_DIV, FORMAT_OPERATOR_DIV, op1, op2);
|
1111 | 43020 | jjdelcerro | } |
1112 | |||
1113 | @Override
|
||
1114 | 45164 | jjdelcerro | public Function concat(Value... values) {
|
1115 | if( values.length==2 ) { |
||
1116 | return binaryOperator(OPERATOR_CONCAT, FORMAT_OPERATOR_CONCAT, values[0], values[1]); |
||
1117 | } |
||
1118 | FunctionBase func = new FunctionBase(FUNCTION_CONCAT);
|
||
1119 | for (Value theValue : values) {
|
||
1120 | func.parameter(theValue); |
||
1121 | } |
||
1122 | return func;
|
||
1123 | 43020 | jjdelcerro | } |
1124 | 45164 | jjdelcerro | |
1125 | 44051 | omartinez | @Override
|
1126 | 44038 | jjdelcerro | public Function iif(Value condition, Value iftrue, Value iffalse) {
|
1127 | 44198 | jjdelcerro | return function(FUNCTION_IIF, condition, iftrue, iffalse);
|
1128 | 44038 | jjdelcerro | } |
1129 | |||
1130 | 44051 | omartinez | @Override
|
1131 | 44038 | jjdelcerro | public Function ifnull(Value value, Value iftrue, Value iffalse) {
|
1132 | 44198 | jjdelcerro | return function(FUNCTION_IFNULL, value, iftrue, iffalse);
|
1133 | 44038 | jjdelcerro | } |
1134 | 44051 | omartinez | |
1135 | @Override
|
||
1136 | public Function left(Value str, Value size) {
|
||
1137 | 44198 | jjdelcerro | return function(FUNCTION_LEFT, str, size);
|
1138 | 44051 | omartinez | } |
1139 | |||
1140 | @Override
|
||
1141 | public Function right(Value str, Value len) {
|
||
1142 | 44198 | jjdelcerro | return function(FUNCTION_RIGHT, str, len);
|
1143 | 44051 | omartinez | } |
1144 | |||
1145 | @Override
|
||
1146 | public Function locate(Value search, Value str, Value start) {
|
||
1147 | 44198 | jjdelcerro | return function(FUNCTION_LOCATE, search, str, start);
|
1148 | 44051 | omartinez | } |
1149 | |||
1150 | @Override
|
||
1151 | public Function position(Value search, Value str) {
|
||
1152 | 44198 | jjdelcerro | return function(FUNCTION_POSITION, search, str);
|
1153 | 44051 | omartinez | } |
1154 | |||
1155 | @Override
|
||
1156 | public Function lpad(Value str, Value len, Value padstr) {
|
||
1157 | 44198 | jjdelcerro | return function(FUNCTION_LPAD, str, len, padstr);
|
1158 | 44051 | omartinez | } |
1159 | |||
1160 | @Override
|
||
1161 | public Function rpad(Value str, Value len, Value padstr) {
|
||
1162 | 44198 | jjdelcerro | return function(FUNCTION_RPAD, str, len, padstr);
|
1163 | 44051 | omartinez | } |
1164 | |||
1165 | @Override
|
||
1166 | public Function ltrim(Value str) {
|
||
1167 | 44198 | jjdelcerro | return function(FUNCTION_LTRIM, str);
|
1168 | 44051 | omartinez | } |
1169 | |||
1170 | @Override
|
||
1171 | public Function rtrim(Value str) {
|
||
1172 | 44198 | jjdelcerro | return function(FUNCTION_RTRIM, str);
|
1173 | 44051 | omartinez | } |
1174 | |||
1175 | @Override
|
||
1176 | public Function trim(Value str) {
|
||
1177 | 44198 | jjdelcerro | return function(FUNCTION_TRIM, str);
|
1178 | 44051 | omartinez | } |
1179 | |||
1180 | @Override
|
||
1181 | public Function repeat(Value str, Value size) {
|
||
1182 | 44198 | jjdelcerro | return function(FUNCTION_REPEAT, str, size);
|
1183 | 44051 | omartinez | } |
1184 | |||
1185 | @Override
|
||
1186 | public Function replace(Value str, Value search, Value replstr) {
|
||
1187 | 44198 | jjdelcerro | return function(FUNCTION_REPLACE, str, search, replstr);
|
1188 | 44051 | omartinez | } |
1189 | |||
1190 | @Override
|
||
1191 | public Function ascii(Value str) {
|
||
1192 | 44198 | jjdelcerro | return function(FUNCTION_ASCII, str);
|
1193 | 44051 | omartinez | } |
1194 | |||
1195 | @Override
|
||
1196 | public Function lenght(Value str) {
|
||
1197 | 44198 | jjdelcerro | return function(FUNCTION_LENGHT, str);
|
1198 | 44051 | omartinez | } |
1199 | |||
1200 | @Override
|
||
1201 | public Function instr(Value str, Value search, Value start) {
|
||
1202 | 44198 | jjdelcerro | return function(FUNCTION_INSTR, str, search, start);
|
1203 | 44051 | omartinez | } |
1204 | |||
1205 | @Override
|
||
1206 | public Function lower(Value str) {
|
||
1207 | 44198 | jjdelcerro | return function(FUNCTION_LOWER, str);
|
1208 | 44051 | omartinez | } |
1209 | |||
1210 | @Override
|
||
1211 | public Function upper(Value str) {
|
||
1212 | 44198 | jjdelcerro | return function(FUNCTION_UPPER, str);
|
1213 | 44051 | omartinez | } |
1214 | |||
1215 | @Override
|
||
1216 | public Function space(Value size) {
|
||
1217 | 44198 | jjdelcerro | return function(FUNCTION_SPACE, size);
|
1218 | 44051 | omartinez | } |
1219 | |||
1220 | @Override
|
||
1221 | public Function substring(Value str, Value start, Value len) {
|
||
1222 | 44198 | jjdelcerro | return function(FUNCTION_SUBSTRING, str, start, len);
|
1223 | 44051 | omartinez | } |
1224 | |||
1225 | @Override
|
||
1226 | public Function acos(Value num) {
|
||
1227 | 44198 | jjdelcerro | return function(FUNCTION_ACOS, num);
|
1228 | 44051 | omartinez | } |
1229 | |||
1230 | @Override
|
||
1231 | public Function asin(Value num) {
|
||
1232 | 44198 | jjdelcerro | return function(FUNCTION_ASIN, num);
|
1233 | 44051 | omartinez | } |
1234 | |||
1235 | @Override
|
||
1236 | public Function atan(Value num) {
|
||
1237 | 44198 | jjdelcerro | return function(FUNCTION_ATAN, num);
|
1238 | 44051 | omartinez | } |
1239 | |||
1240 | @Override
|
||
1241 | public Function cos(Value num) {
|
||
1242 | 44198 | jjdelcerro | return function(FUNCTION_COS, num);
|
1243 | 44051 | omartinez | } |
1244 | |||
1245 | @Override
|
||
1246 | public Function cosh(Value num) {
|
||
1247 | 44198 | jjdelcerro | return function(FUNCTION_COSH, num);
|
1248 | 44051 | omartinez | } |
1249 | |||
1250 | @Override
|
||
1251 | public Function cot(Value num) {
|
||
1252 | 44198 | jjdelcerro | return function(FUNCTION_COT, num);
|
1253 | 44051 | omartinez | } |
1254 | |||
1255 | @Override
|
||
1256 | public Function bitand(Value num1, Value num2) {
|
||
1257 | 44198 | jjdelcerro | return function(FUNCTION_BITAND, num1, num2);
|
1258 | 44051 | omartinez | } |
1259 | |||
1260 | @Override
|
||
1261 | public Function bitor(Value num1, Value num2) {
|
||
1262 | 44198 | jjdelcerro | return function(FUNCTION_BITOR, num1, num2);
|
1263 | 44051 | omartinez | } |
1264 | |||
1265 | @Override
|
||
1266 | public Function bitxor(Value num1, Value num2) {
|
||
1267 | 44198 | jjdelcerro | return function(FUNCTION_BITXOR, num1, num2);
|
1268 | 44051 | omartinez | } |
1269 | |||
1270 | @Override
|
||
1271 | public Function ceil(Value num) {
|
||
1272 | 44198 | jjdelcerro | return function(FUNCTION_CEIL, num);
|
1273 | 44051 | omartinez | } |
1274 | |||
1275 | @Override
|
||
1276 | public Function degrees(Value num) {
|
||
1277 | 44198 | jjdelcerro | return function(FUNCTION_DEGREES, num);
|
1278 | 44051 | omartinez | } |
1279 | |||
1280 | @Override
|
||
1281 | public Function exp(Value num) {
|
||
1282 | 44198 | jjdelcerro | return function(FUNCTION_EXP, num);
|
1283 | 44051 | omartinez | } |
1284 | |||
1285 | @Override
|
||
1286 | public Function floor(Value num) {
|
||
1287 | 44198 | jjdelcerro | return function(FUNCTION_FLOOR, num);
|
1288 | 44051 | omartinez | } |
1289 | |||
1290 | @Override
|
||
1291 | public Function log(Value num) {
|
||
1292 | 44198 | jjdelcerro | return function(FUNCTION_LOG, num);
|
1293 | 44051 | omartinez | } |
1294 | |||
1295 | @Override
|
||
1296 | public Function log10(Value num) {
|
||
1297 | 44198 | jjdelcerro | return function(FUNCTION_LOG10, num);
|
1298 | 44051 | omartinez | } |
1299 | |||
1300 | @Override
|
||
1301 | 44644 | jjdelcerro | public Function pi() {
|
1302 | return function(FUNCTION_PI);
|
||
1303 | 44051 | omartinez | } |
1304 | |||
1305 | @Override
|
||
1306 | 44644 | jjdelcerro | public Function abs(Value num) {
|
1307 | return function(FUNCTION_ABS, num);
|
||
1308 | } |
||
1309 | |||
1310 | @Override
|
||
1311 | 44051 | omartinez | public Function power(Value num) {
|
1312 | 44198 | jjdelcerro | return function(FUNCTION_POWER, num);
|
1313 | 44051 | omartinez | } |
1314 | |||
1315 | @Override
|
||
1316 | public Function radians(Value num) {
|
||
1317 | 44198 | jjdelcerro | return function(FUNCTION_RADIANS, num);
|
1318 | 44051 | omartinez | } |
1319 | |||
1320 | @Override
|
||
1321 | public Function rand(Value num) {
|
||
1322 | 44198 | jjdelcerro | return function(FUNCTION_RAND, num);
|
1323 | 44051 | omartinez | } |
1324 | |||
1325 | @Override
|
||
1326 | public Function round(Value num) {
|
||
1327 | 44198 | jjdelcerro | return function(FUNCTION_ROUND, num);
|
1328 | 44051 | omartinez | } |
1329 | |||
1330 | @Override
|
||
1331 | public Function sqrt(Value num) {
|
||
1332 | 44198 | jjdelcerro | return function(FUNCTION_SQRT, num);
|
1333 | 44051 | omartinez | } |
1334 | |||
1335 | @Override
|
||
1336 | public Function sign(Value num) {
|
||
1337 | 44198 | jjdelcerro | return function(FUNCTION_SIGN, num);
|
1338 | 44051 | omartinez | } |
1339 | |||
1340 | @Override
|
||
1341 | public Function sin(Value num) {
|
||
1342 | 44198 | jjdelcerro | return function(FUNCTION_SIN, num);
|
1343 | 44051 | omartinez | } |
1344 | |||
1345 | @Override
|
||
1346 | public Function sinh(Value num) {
|
||
1347 | 44198 | jjdelcerro | return function(FUNCTION_SINH, num);
|
1348 | 44051 | omartinez | } |
1349 | |||
1350 | @Override
|
||
1351 | public Function tan(Value num) {
|
||
1352 | 44198 | jjdelcerro | return function(FUNCTION_TAN, num);
|
1353 | 44051 | omartinez | } |
1354 | @Override
|
||
1355 | public Function tanh(Value num) {
|
||
1356 | 44198 | jjdelcerro | return function(FUNCTION_TANH, num);
|
1357 | 44051 | omartinez | } |
1358 | |||
1359 | @Override
|
||
1360 | public Function zero() {
|
||
1361 | 44198 | jjdelcerro | return function(FUNCTION_ZERO);
|
1362 | 44051 | omartinez | } |
1363 | 44053 | omartinez | |
1364 | @Override
|
||
1365 | public Function chr(Value num) {
|
||
1366 | 44198 | jjdelcerro | return function(FUNCTION_CHR, num);
|
1367 | } |
||
1368 | |||
1369 | @Override
|
||
1370 | public Function cast(Value object, Value typeName) {
|
||
1371 | return function(FUNCTION_CAST, object, typeName);
|
||
1372 | } |
||
1373 | |||
1374 | @Override
|
||
1375 | public Function decode(Value value, Value format) {
|
||
1376 | return function(FUNCTION_DECODE, value, format);
|
||
1377 | } |
||
1378 | |||
1379 | @Override
|
||
1380 | public Function toDouble(Value num) {
|
||
1381 | return function(FUNCTION_TODOUBLE, num);
|
||
1382 | } |
||
1383 | |||
1384 | @Override
|
||
1385 | public Function toFloat(Value num) {
|
||
1386 | return function(FUNCTION_TOFLOAT, num);
|
||
1387 | } |
||
1388 | |||
1389 | @Override
|
||
1390 | public Function toLong(Value num) {
|
||
1391 | return function(FUNCTION_TOLONG, num);
|
||
1392 | } |
||
1393 | |||
1394 | @Override
|
||
1395 | public Function toInteger(Value num) {
|
||
1396 | return function(FUNCTION_TOINTEGER, num);
|
||
1397 | } |
||
1398 | |||
1399 | @Override
|
||
1400 | public Function toStr(Value object) {
|
||
1401 | return function(FUNCTION_TOSTR, object);
|
||
1402 | } |
||
1403 | |||
1404 | 44253 | jjdelcerro | @Override
|
1405 | 44262 | jjdelcerro | public Function list() {
|
1406 | return function(FUNCTION_LIST);
|
||
1407 | } |
||
1408 | 44376 | jjdelcerro | |
1409 | @Override
|
||
1410 | public Function tuple() {
|
||
1411 | return function(FUNCTION_TUPLE);
|
||
1412 | } |
||
1413 | |||
1414 | @Override
|
||
1415 | 44838 | jjdelcerro | public Function tuple(Object... values) { |
1416 | 44376 | jjdelcerro | Function fn = function(FUNCTION_TUPLE); |
1417 | 44838 | jjdelcerro | for (Object theValue : values) { |
1418 | if( theValue instanceof ExpressionBuilder.Value ) { |
||
1419 | fn.parameter((Value) theValue); |
||
1420 | } else {
|
||
1421 | fn.parameter(constant(theValue)); |
||
1422 | } |
||
1423 | 44376 | jjdelcerro | } |
1424 | return fn;
|
||
1425 | } |
||
1426 | |||
1427 | 44644 | jjdelcerro | @Override
|
1428 | public String repr(Object value) { |
||
1429 | return this.manager.getReprMethod(value).repr(value); |
||
1430 | } |
||
1431 | 44748 | jjdelcerro | |
1432 | @Override
|
||
1433 | 44750 | jjdelcerro | public Function getattr(String objectId, String attributeId) { |
1434 | 44748 | jjdelcerro | Function fn = function(FUNCTION_GETATTR); |
1435 | 44750 | jjdelcerro | fn.parameter(variable(objectId)); |
1436 | fn.parameter(variable(attributeId)); |
||
1437 | 44748 | jjdelcerro | return fn;
|
1438 | } |
||
1439 | |||
1440 | 44750 | jjdelcerro | @Override
|
1441 | 44763 | jjdelcerro | public Function date(Date date) { |
1442 | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
||
1443 | return function(FUNCTION_DATE, constant(df.format(date)));
|
||
1444 | } |
||
1445 | |||
1446 | @Override
|
||
1447 | public Function time(Date time) { |
||
1448 | SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss"); |
||
1449 | return function(FUNCTION_TIME, constant(df.format(time)));
|
||
1450 | } |
||
1451 | |||
1452 | @Override
|
||
1453 | public Function timestamp(Date timestamp) { |
||
1454 | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
||
1455 | return function(FUNCTION_TIMESTAMP, constant(df.format(timestamp)));
|
||
1456 | } |
||
1457 | |||
1458 | @Override
|
||
1459 | public Function date(String date) { |
||
1460 | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
||
1461 | Date d;
|
||
1462 | try {
|
||
1463 | d = df.parse(date); |
||
1464 | } catch (ParseException ex) { |
||
1465 | throw new IllegalArgumentException("Can't parse argument '"+date+"' as date.", ex); |
||
1466 | } |
||
1467 | return function(FUNCTION_DATE, constant(df.format(d)));
|
||
1468 | } |
||
1469 | |||
1470 | @Override
|
||
1471 | public Function time(String time) { |
||
1472 | SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss"); |
||
1473 | Date t;
|
||
1474 | try {
|
||
1475 | t = df.parse(time); |
||
1476 | } catch (ParseException ex) { |
||
1477 | throw new IllegalArgumentException("Can't parse argument '"+time+"' as date.", ex); |
||
1478 | } |
||
1479 | return function(FUNCTION_TIME, constant(df.format(t)));
|
||
1480 | } |
||
1481 | |||
1482 | @Override
|
||
1483 | public Function timestamp(String timestamp) { |
||
1484 | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
||
1485 | Date ts;
|
||
1486 | try {
|
||
1487 | ts = df.parse(timestamp); |
||
1488 | } catch (ParseException ex) { |
||
1489 | throw new IllegalArgumentException("Can't parse argument '"+timestamp+"' as date.", ex); |
||
1490 | } |
||
1491 | return function(FUNCTION_TIMESTAMP, constant(df.format(ts)));
|
||
1492 | } |
||
1493 | |||
1494 | @Override
|
||
1495 | 45523 | jjdelcerro | public Function color(Color color) { |
1496 | return function(FUNCTION_COLOR, constant(color.getRed()), constant(color.getGreen()), constant(color.getBlue()), constant(color.getAlpha()));
|
||
1497 | } |
||
1498 | |||
1499 | @Override
|
||
1500 | public Function color(Value red, Value green, Value blue, Value alfa) {
|
||
1501 | return function(FUNCTION_COLOR, red, green, blue, alfa);
|
||
1502 | } |
||
1503 | |||
1504 | @Override
|
||
1505 | 44750 | jjdelcerro | public Function date(Value date) {
|
1506 | return function(FUNCTION_DATE, date);
|
||
1507 | } |
||
1508 | |||
1509 | @Override
|
||
1510 | public Function time(Value time) {
|
||
1511 | return function(FUNCTION_TIME, time);
|
||
1512 | } |
||
1513 | |||
1514 | @Override
|
||
1515 | public Function timestamp(Value timestamp) {
|
||
1516 | return function(FUNCTION_TIMESTAMP, timestamp);
|
||
1517 | } |
||
1518 | |||
1519 | @Override
|
||
1520 | public Function current_date() {
|
||
1521 | return function(FUNCTION_CURRENT_DATE);
|
||
1522 | } |
||
1523 | |||
1524 | @Override
|
||
1525 | public Function current_time() {
|
||
1526 | return function(FUNCTION_CURRENT_TIME);
|
||
1527 | } |
||
1528 | |||
1529 | @Override
|
||
1530 | public Function current_timestamp() {
|
||
1531 | return function(FUNCTION_CURRENT_TIMESTAMP);
|
||
1532 | } |
||
1533 | |||
1534 | @Override
|
||
1535 | public Function date_add(Value datefield, Value valueToAdd, Value date) {
|
||
1536 | return function(FUNCTION_DATEADD, datefield, valueToAdd, date);
|
||
1537 | } |
||
1538 | |||
1539 | @Override
|
||
1540 | public Function date_diff(Value datefield, Value valueToSubst, Value date) {
|
||
1541 | return function(FUNCTION_DATEDIFF, datefield, valueToSubst, date);
|
||
1542 | } |
||
1543 | |||
1544 | @Override
|
||
1545 | public Function to_date(Value date, Value format) {
|
||
1546 | return function(FUNCTION_TO_DATE, date, format);
|
||
1547 | } |
||
1548 | |||
1549 | @Override
|
||
1550 | public Function to_timestamp(Value timestamp, Value format) {
|
||
1551 | return function(FUNCTION_TO_TIMESTAMP, timestamp, format);
|
||
1552 | } |
||
1553 | |||
1554 | @Override
|
||
1555 | public Function extract(Value datefield, Value source) {
|
||
1556 | return function(FUNCTION_EXTRACT, datefield, source);
|
||
1557 | } |
||
1558 | |||
1559 | 43020 | jjdelcerro | } |