2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.openecomp.sdnc.sli;
24 import java.util.LinkedList;
25 import java.util.List;
27 public class SvcLogicBinaryExpression extends SvcLogicExpression {
30 public enum OperatorType {
46 private OperatorType(String text)
51 public String getText()
56 public static OperatorType fromString(String text)
60 for (OperatorType t : OperatorType.values())
62 if (text.equalsIgnoreCase(t.getText())) {
71 public String toString()
76 private List<OperatorType> operators;
78 public List<OperatorType> getOperators() {
82 public SvcLogicBinaryExpression()
84 operators = new LinkedList<OperatorType>();
87 public void addOperator(String operator)
89 operators.add(OperatorType.fromString(operator));
93 public String toString()
96 List<SvcLogicExpression>operands = getOperands();
97 StringBuffer sbuff = new StringBuffer();
99 sbuff.append(operands.get(0).toString());
100 for (int i = 0 ; i < operators.size(); i++)
103 sbuff.append(operators.get(i));
105 if (i + 1 < operands.size()) {
106 sbuff.append(operands.get(i + 1).toString());
108 // expression incomplete; operand not bound yet
113 return(sbuff.toString());
117 public String asParsedExpr() {
119 List<SvcLogicExpression> operands = getOperands();
121 if (operators.isEmpty()) {
122 return operands.get(0).asParsedExpr();
124 StringBuffer sbuff = new StringBuffer();
125 // operators in reverse order for left associativity
126 for (int i = operators.size() - 1; i >= 0; --i) {
128 sbuff.append(operators.get(i).getText());
131 for (int i = 0; i < operators.size() + 1; ++i) {
132 if (i < operands.size()) {
133 sbuff.append(operands.get(i).asParsedExpr());
135 // expression incomplete; operand not bound yet
141 if (i < operators.size()) {
145 return sbuff.toString();