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.appc.util;
25 import java.util.Collections;
26 import java.util.LinkedHashMap;
27 import java.util.LinkedList;
32 private StringBuilder path = new StringBuilder(128);
34 private LinkedList<Integer> indexes = new LinkedList<>();
35 private Map<String, String> entries = new LinkedHashMap<>();
36 private int offset = 0;
38 private final String delimiter;
44 PathContext(String delimiter) {
45 this.delimiter = delimiter;
48 private void push(String elem, boolean delimit) {
50 throw new IllegalArgumentException();
53 int length = elem.length();
55 if (delimit && !indexes.isEmpty()) {
56 path.append(delimiter);
57 length += delimiter.length();
62 indexes.addLast(Integer.valueOf(length));
66 if (indexes.isEmpty()) {
67 throw new IllegalStateException();
69 offset -= indexes.removeLast();
70 path.setLength(offset);
73 void pushToken(String token) {
81 void pushModifier(String modifier) {
82 push(modifier, false);
90 return path.substring(0, offset);
93 void entry(String name, String value) {
94 entries.put(name, value);
97 Map<String, String> entries() {
98 return Collections.unmodifiableMap(entries);