001    package railo.runtime.sql.exp.op;
002    
003    import java.util.Iterator;
004    import java.util.List;
005    
006    import railo.runtime.sql.exp.Expression;
007    import railo.runtime.sql.exp.ExpressionSupport;
008    
009    public class OperationN extends ExpressionSupport implements Operation {
010    
011            private String operator;
012            private List operants;
013    
014            public OperationN(String operator, List operants) {
015                    this.operator=operator;
016                    this.operants=operants;
017            }
018    
019            public String toString(boolean noAlias) {
020                    if(!hasIndex() || noAlias) {
021                            StringBuffer sb=new StringBuffer();
022                            sb.append(operator);
023                            sb.append('(');
024                            Iterator it = operants.iterator();
025                            boolean isFirst=true;
026                            while(it.hasNext()) {
027                                    if(!isFirst)sb.append(',');
028                                    Expression exp=(Expression) it.next();
029                                    sb.append(exp.toString(!operator.equalsIgnoreCase("cast")));
030                                    isFirst=false;
031                            }
032                            sb.append(')');
033                            return sb.toString();
034                    }
035                    return toString(true)+" as "+getAlias();
036            }
037    
038            /**
039             * @return the operants
040             */
041            public Expression[] getOperants() {
042                    if(operants==null) return new Expression[0];
043                    return (Expression[]) operants.toArray(new Expression[operants.size()]);
044            }
045    
046            /**
047             * @return the operator
048             */
049            public String getOperator() {
050                    return operator;
051            }
052    }