Revision 45164
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/test/java/org/gvsig/expresionevaluator/impl/TestExpressionBuilder.java | ||
---|---|---|
383 | 383 |
// ); |
384 | 384 |
} |
385 | 385 |
|
386 |
public void testConcat() { |
|
387 |
// CONCAT(precio,' euros') |
|
386 |
public void testConcat1() { |
|
388 | 387 |
ExpressionBuilder builder = createExpressionBuilder(); |
389 | 388 |
builder.set( |
390 | 389 |
builder.concat( |
390 |
builder.constant("Total "), |
|
391 | 391 |
builder.variable("precio"), |
392 | 392 |
builder.constant(" euros") |
393 | 393 |
) |
394 | 394 |
); |
395 | 395 |
|
396 | 396 |
assertEquals( |
397 |
"CONCAT('Total ', \"precio\", ' euros')", |
|
398 |
builder.toString() |
|
399 |
); |
|
400 |
assertEquals( |
|
401 |
"[precio]", |
|
402 |
ArrayUtils.toString(builder.variables_names()) |
|
403 |
); |
|
404 |
assertEquals( |
|
405 |
"[]", |
|
406 |
ArrayUtils.toString(builder.parameters_names()) |
|
407 |
); |
|
408 |
} |
|
409 |
|
|
410 |
public void testConcat2() { |
|
411 |
ExpressionBuilder builder = createExpressionBuilder(); |
|
412 |
builder.set( |
|
413 |
builder.concat( |
|
414 |
builder.variable("precio"), |
|
415 |
builder.constant(" euros") |
|
416 |
) |
|
417 |
); |
|
418 |
|
|
419 |
assertEquals( |
|
397 | 420 |
"\"precio\" || ' euros'", |
398 | 421 |
builder.toString() |
399 | 422 |
); |
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/function/string/ConcatFunction.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.util.Objects; |
4 | 4 |
import org.apache.commons.lang3.Range; |
5 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_CONCAT; |
|
5 | 6 |
import org.gvsig.expressionevaluator.Interpreter; |
6 | 7 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
7 | 8 |
|
8 | 9 |
public class ConcatFunction extends AbstractFunction { |
9 | 10 |
|
10 | 11 |
public ConcatFunction() { |
11 |
super("String", "CONCAT", Range.between(1,Integer.MAX_VALUE));
|
|
12 |
super("String", FUNCTION_CONCAT, Range.between(1,Integer.MAX_VALUE));
|
|
12 | 13 |
} |
13 | 14 |
|
14 | 15 |
@Override |
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/function/operator/UnaryOperator.java | ||
---|---|---|
1 | 1 |
package org.gvsig.expressionevaluator.impl.function.operator; |
2 | 2 |
|
3 |
import org.gvsig.expressionevaluator.Function; |
|
4 | 3 |
import org.gvsig.expressionevaluator.Interpreter; |
5 | 4 |
|
6 | 5 |
|
7 |
public interface UnaryOperator extends Function {
|
|
6 |
public interface UnaryOperator extends Operator {
|
|
8 | 7 |
|
9 | 8 |
public Object call(Interpreter interpreter, Object op); |
10 | 9 |
} |
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/function/operator/Operator.java | ||
---|---|---|
1 |
package org.gvsig.expressionevaluator.impl.function.operator; |
|
2 |
|
|
3 |
import org.gvsig.expressionevaluator.Function; |
|
4 |
import org.gvsig.expressionevaluator.Interpreter; |
|
5 |
|
|
6 |
|
|
7 |
public interface Operator extends Function { |
|
8 |
|
|
9 |
} |
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/function/operator/BinaryOperator.java | ||
---|---|---|
1 | 1 |
package org.gvsig.expressionevaluator.impl.function.operator; |
2 | 2 |
|
3 |
import org.gvsig.expressionevaluator.Function; |
|
4 | 3 |
import org.gvsig.expressionevaluator.Interpreter; |
5 | 4 |
|
6 | 5 |
|
7 |
public interface BinaryOperator extends Function {
|
|
6 |
public interface BinaryOperator extends Operator {
|
|
8 | 7 |
|
9 | 8 |
public Object call(Interpreter interpreter, Object op1, Object op2); |
10 | 9 |
|
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 | ||
---|---|---|
547 | 547 |
} |
548 | 548 |
} |
549 | 549 |
|
550 |
public class BinaryOperatorBase extends AbstractValue implements BinaryOperator {
|
|
550 |
public class BinaryOperatorBase extends FunctionBase implements BinaryOperator {
|
|
551 | 551 |
|
552 |
protected String name; |
|
553 |
protected String format; |
|
554 |
protected Value left; |
|
555 |
protected Value right; |
|
556 |
|
|
552 |
private static final int LEFT = 0; |
|
553 |
private static final int RIGHT = 1; |
|
554 |
|
|
557 | 555 |
public BinaryOperatorBase(String name, String format) { |
558 |
this.name = name; |
|
559 |
this.format = format; |
|
556 |
super(name, format); |
|
557 |
this.parameters = new ArrayList<>(); |
|
558 |
this.parameters.add(null); |
|
559 |
this.parameters.add(null); |
|
560 | 560 |
} |
561 | 561 |
|
562 | 562 |
@Override |
563 |
public String name() {
|
|
564 |
return this.name;
|
|
563 |
public Function parameter(Value parameter) {
|
|
564 |
throw new UnsupportedOperationException("BinaryOperator can support add parameters.");
|
|
565 | 565 |
} |
566 |
|
|
567 |
@Override |
|
568 |
public void replace(Value target, Value replacement) { |
|
569 |
if( target == this.left ) { |
|
570 |
this.left = replacement; |
|
571 |
} else { |
|
572 |
this.left.replace(target, replacement); |
|
573 |
} |
|
574 |
if( target == this.right ) { |
|
575 |
this.right = replacement; |
|
576 |
} else { |
|
577 |
this.right.replace(target, replacement); |
|
578 |
} |
|
579 |
} |
|
580 | 566 |
|
581 | 567 |
@Override |
582 |
public void accept(Visitor visitor, VisitorFilter filter) { |
|
583 |
super.accept(visitor, filter); |
|
584 |
this.left.accept(visitor, filter); |
|
585 |
this.right.accept(visitor, filter); |
|
568 |
public String name() { |
|
569 |
return this.name; |
|
586 | 570 |
} |
587 | 571 |
|
588 | 572 |
@Override |
589 | 573 |
public BinaryOperator left(Value operand) { |
590 |
this.left = operand;
|
|
574 |
this.parameters.set(LEFT, operand);
|
|
591 | 575 |
return this; |
592 | 576 |
} |
593 | 577 |
|
594 | 578 |
@Override |
595 | 579 |
public BinaryOperator right(Value operand) { |
596 |
this.right = operand;
|
|
580 |
this.parameters.set(RIGHT, operand);
|
|
597 | 581 |
return this; |
598 | 582 |
} |
599 | 583 |
|
600 | 584 |
@Override |
601 | 585 |
public Value left() { |
602 |
return this.left;
|
|
586 |
return this.parameters.get(LEFT);
|
|
603 | 587 |
} |
604 | 588 |
|
605 | 589 |
@Override |
606 | 590 |
public Value right() { |
607 |
return this.right;
|
|
591 |
return this.parameters.get(RIGHT);
|
|
608 | 592 |
} |
609 | 593 |
|
610 | 594 |
@Override |
... | ... | |
620 | 604 |
if( this.format==null ) { |
621 | 605 |
StringBuilder builder = new StringBuilder(); |
622 | 606 |
builder.append("("); |
623 |
builder.append(this.left.toString(formatter)); |
|
607 |
builder.append(this.left().toString(formatter));
|
|
624 | 608 |
builder.append(" "); |
625 | 609 |
builder.append(this.name); |
626 | 610 |
builder.append(" "); |
627 |
builder.append(this.right.toString(formatter)); |
|
611 |
builder.append(this.right().toString(formatter));
|
|
628 | 612 |
builder.append(")"); |
629 | 613 |
return builder.toString(); |
630 | 614 |
} else { |
631 | 615 |
return MessageFormat.format( |
632 | 616 |
format, |
633 |
this.left.toString(formatter), |
|
634 |
this.right.toString(formatter) |
|
617 |
this.left().toString(formatter),
|
|
618 |
this.right().toString(formatter)
|
|
635 | 619 |
); |
636 | 620 |
} |
637 | 621 |
} |
... | ... | |
1086 | 1070 |
} |
1087 | 1071 |
|
1088 | 1072 |
@Override |
1089 |
public BinaryOperator concat(Value op1, Value op2) { |
|
1090 |
return binaryOperator(OPERATOR_CONCAT, FORMAT_OPERATOR_CONCAT, op1, op2); |
|
1073 |
public Function concat(Value... values) { |
|
1074 |
if( values.length==2 ) { |
|
1075 |
return binaryOperator(OPERATOR_CONCAT, FORMAT_OPERATOR_CONCAT, values[0], values[1]); |
|
1076 |
} |
|
1077 |
FunctionBase func = new FunctionBase(FUNCTION_CONCAT); |
|
1078 |
for (Value theValue : values) { |
|
1079 |
func.parameter(theValue); |
|
1080 |
} |
|
1081 |
return func; |
|
1091 | 1082 |
} |
1092 |
|
|
1083 |
|
|
1093 | 1084 |
@Override |
1094 | 1085 |
public Function iif(Value condition, Value iftrue, Value iffalse) { |
1095 | 1086 |
return function(FUNCTION_IIF, condition, iftrue, iffalse); |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/ExpressionBuilder.java | ||
---|---|---|
52 | 52 |
public static final String FUNCTION_UPPER = "UPPER"; |
53 | 53 |
public static final String FUNCTION_SPACE = "SPACE"; |
54 | 54 |
public static final String FUNCTION_SUBSTRING = "SUBSTRING"; |
55 |
public static final String FUNCTION_CONCAT = "CONCAT"; |
|
55 | 56 |
public static final String FUNCTION_ABS = "ABS"; |
56 | 57 |
public static final String FUNCTION_ACOS = "ACOS"; |
57 | 58 |
public static final String FUNCTION_ASIN = "ASIN"; |
... | ... | |
188 | 189 |
public Function parameter(Value parameter); |
189 | 190 |
} |
190 | 191 |
|
191 |
public interface BinaryOperator extends Value {
|
|
192 |
public interface BinaryOperator extends Function {
|
|
192 | 193 |
public String name(); |
193 | 194 |
public Value left(); |
194 | 195 |
public Value right(); |
... | ... | |
365 | 366 |
|
366 | 367 |
public BinaryOperator div(Value op1, Value op2); |
367 | 368 |
|
368 |
public BinaryOperator concat(Value op1, Value op2);
|
|
369 |
public Function concat(Value...values);
|
|
369 | 370 |
|
370 | 371 |
public ExpressionBuilder set(Value value); |
371 | 372 |
|
Also available in: Unified diff