2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 ONAP
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.ccsdk.sli.core.sli;
23 import java.util.LinkedList;
24 import java.util.List;
26 public class SvcLogicBinaryExpression extends SvcLogicExpression {
29 public enum OperatorType {
45 private OperatorType(String text)
50 public String getText()
55 public static OperatorType fromString(String text)
59 for (OperatorType t : OperatorType.values())
61 if (text.equalsIgnoreCase(t.getText())) {
70 public String toString()
75 private List<OperatorType> operators;
77 public List<OperatorType> getOperators() {
81 public SvcLogicBinaryExpression()
83 operators = new LinkedList<OperatorType>();
86 public void addOperator(String operator)
88 operators.add(OperatorType.fromString(operator));
92 public String toString()
95 List<SvcLogicExpression>operands = getOperands();
96 StringBuffer sbuff = new StringBuffer();
98 sbuff.append(operands.get(0).toString());
99 for (int i = 0 ; i < operators.size(); i++)
102 sbuff.append(operators.get(i));
104 if (i + 1 < operands.size()) {
105 sbuff.append(operands.get(i + 1).toString());
107 // expression incomplete; operand not bound yet
112 return(sbuff.toString());
116 public String asParsedExpr() {
118 List<SvcLogicExpression> operands = getOperands();
120 if (operators.isEmpty()) {
121 return operands.get(0).asParsedExpr();
123 StringBuffer sbuff = new StringBuffer();
124 // operators in reverse order for left associativity
125 for (int i = operators.size() - 1; i >= 0; --i) {
127 sbuff.append(operators.get(i).getText());
130 for (int i = 0; i < operators.size() + 1; ++i) {
131 if (i < operands.size()) {
132 sbuff.append(operands.get(i).asParsedExpr());
134 // expression incomplete; operand not bound yet
140 if (i < operators.size()) {
144 return sbuff.toString();