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 sbuff.append(operands.get(i+1).toString());
108 return(sbuff.toString());
112 public String asParsedExpr()
115 List<SvcLogicExpression>operands = getOperands();
116 StringBuffer sbuff = new StringBuffer();
117 StringBuffer closeParens = new StringBuffer();
119 for (OperatorType operator : operators)
122 sbuff.append(operator.getText());
124 sbuff.append(operands.get(i++).asParsedExpr());
125 closeParens.append(")");
128 if (i < operands.size())
130 sbuff.append(operands.get(i).asParsedExpr());
134 sbuff.append("__MISSING_OPERAND__");
136 sbuff.append(closeParens.toString());
137 return(sbuff.toString());