Revision 45164 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

View differences:

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);

Also available in: Unified diff