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.io.Serializable;
24 import java.util.LinkedList;
25 import java.util.List;
27 public class SvcLogicAtom extends SvcLogicExpression {
29 public enum AtomType {
37 private AtomType atomType;
41 public SvcLogicAtom(String atomType, String atom)
43 this.atomType = AtomType.valueOf(atomType);
48 public SvcLogicAtom(String atom)
58 if (atom.startsWith("$"))
60 this.atomType = AtomType.CONTEXT_VAR;
61 this.atom = atom.substring(1);
65 if (Character.isDigit(atom.charAt(0)))
67 this.atomType = AtomType.NUMBER;
70 else if (atom.charAt(0) == '\'')
72 this.atomType = AtomType.STRING;
73 this.atom = atom.substring(1, atom.length()-1);
77 this.atomType = AtomType.IDENTIFIER;
86 public AtomType getAtomType() {
90 public void setAtomType(String newType)
92 atomType = AtomType.valueOf(newType);
95 public String getAtom() {
101 public void setAtomType(AtomType atomType) {
102 this.atomType = atomType;
105 public void setAtom(String atom) {
111 public String toString()
113 StringBuffer sbuff = new StringBuffer();
114 switch(getAtomType())
119 boolean needDot = false;
120 for (SvcLogicExpression term: this.getOperands())
126 sbuff.append(term.toString());
129 return(sbuff.toString());
137 public String asParsedExpr()
139 // simplify debugging output for NUMBER type
140 if (atomType == AtomType.NUMBER) {
144 StringBuffer sbuff = new StringBuffer();
146 sbuff.append("(atom");
148 sbuff.append(atomType.toString());
155 for (SvcLogicExpression term : getOperands())
158 sbuff.append(term.asParsedExpr());
168 return(sbuff.toString());