|
| 1 | +/* |
| 2 | + * #%L |
| 3 | + * JSQLParser library |
| 4 | + * %% |
| 5 | + * Copyright (C) 2004 - 2013 JSQLParser |
| 6 | + * %% |
| 7 | + * This program is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU Lesser General Public License as |
| 9 | + * published by the Free Software Foundation, either version 2.1 of the |
| 10 | + * License, or (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Lesser Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Lesser Public |
| 18 | + * License along with this program. If not, see |
| 19 | + * <http://www.gnu.org/licenses/lgpl-2.1.html>. |
| 20 | + * #L% |
| 21 | + */ |
| 22 | +package net.sf.jsqlparser.expression.operators.relational; |
| 23 | + |
| 24 | +import java.util.Arrays; |
| 25 | +import java.util.List; |
| 26 | + |
| 27 | +import net.sf.jsqlparser.expression.Expression; |
| 28 | + |
| 29 | +/** |
| 30 | + * A list of named expressions, as in |
| 31 | + * as in select substr('xyzzy' from 2 for 3) |
| 32 | + */ |
| 33 | +public class NamedExpressionList implements ItemsList { |
| 34 | + |
| 35 | + private List<Expression> expressions; |
| 36 | + private List<String> names; |
| 37 | + |
| 38 | + public NamedExpressionList() { |
| 39 | + } |
| 40 | + |
| 41 | + public NamedExpressionList(List<Expression> expressions) { |
| 42 | + this.expressions = expressions; |
| 43 | + } |
| 44 | + |
| 45 | + public NamedExpressionList(Expression ... expressions) { |
| 46 | + this.expressions = Arrays.asList(expressions); |
| 47 | + } |
| 48 | + |
| 49 | + public List<Expression> getExpressions() { |
| 50 | + return expressions; |
| 51 | + } |
| 52 | + |
| 53 | + public List<String> getNames() { |
| 54 | + return names; |
| 55 | + } |
| 56 | + |
| 57 | + |
| 58 | + public void setExpressions(List<Expression> list) { |
| 59 | + expressions = list; |
| 60 | + } |
| 61 | + |
| 62 | + public void setNames(List<String> list) { |
| 63 | + names = list; |
| 64 | + } |
| 65 | + |
| 66 | + |
| 67 | + @Override |
| 68 | + public void accept(ItemsListVisitor itemsListVisitor) { |
| 69 | + itemsListVisitor.visit(this); |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + public String toString() { |
| 74 | + |
| 75 | + StringBuilder ret = new StringBuilder(); |
| 76 | + ret.append("("); |
| 77 | + for(int i=0; i<expressions.size(); i++){ |
| 78 | + if(i>0){ |
| 79 | + ret.append(" "); |
| 80 | + } |
| 81 | + if(! names.get(i).equals("")){ |
| 82 | + ret.append(names.get(i)).append(" ").append(expressions.get(i)); |
| 83 | + }else{ |
| 84 | + ret.append(expressions.get(i)); |
| 85 | + } |
| 86 | + } |
| 87 | + ret.append(")"); |
| 88 | + |
| 89 | + return ret.toString(); |
| 90 | + } |
| 91 | +} |
0 commit comments