29a86de89bcea6712d38fc70db59bf547e89a4a6
[aaf/authz.git] / misc / rosetta / src / main / java / org / onap / aaf / misc / rosetta / Parsed.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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====================================================
19  *
20  */
21
22 package org.onap.aaf.misc.rosetta;
23
24
25 public class Parsed<S> {
26     public static final String EXTENSION_TAG="extension";
27     
28     public boolean isString;
29     
30     public StringBuilder sb;
31     public char event;
32     public String name;
33     public S state;
34
35     public Parsed() {
36         this(null);
37     }
38
39     // Package on purpose
40     Parsed(S theState) {
41         sb = new StringBuilder();
42         isString = false;
43         event = Parse.NONE;
44         name = "";
45         state = theState;
46     }
47
48     public boolean valid() {
49         return event!=Parse.NONE;
50     }
51     
52     public Parsed<S> reuse() {
53         isString=false;
54         sb.setLength(0);
55         event = Parse.NONE;
56         name = "";
57         // don't touch T...
58         return this;
59     }
60
61     public void dataIsName() {
62         name = sb.toString();
63         sb.setLength(0);
64     }
65
66     public boolean hasName() {
67         return name.length()>0;
68     }
69
70     public boolean hasData() {
71         return sb.length()>0;
72     }
73     
74     public String toString() {
75         StringBuilder sb2 = new StringBuilder();
76         if (event<40)sb2.append((int)event);
77         else sb2.append(event);
78         sb2.append(" - ");
79         sb2.append(name);
80         if (sb.length()>0) {
81             sb2.append(" : ");
82             if (isString)sb2.append('"');
83             sb2.append(sb);
84             if (isString)sb2.append('"');
85         }
86         return sb2.toString();
87     }
88
89 }