2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.util;
28 import java.util.Collections;
29 import java.util.LinkedHashMap;
30 import java.util.LinkedList;
35 private StringBuilder path = new StringBuilder(128);
37 private LinkedList<Integer> indexes = new LinkedList<>();
38 private Map<String, String> entries = new LinkedHashMap<>();
39 private int offset = 0;
41 private final String delimiter;
47 PathContext(String delimiter) {
48 this.delimiter = delimiter;
51 private void push(String elem, boolean delimit) {
53 throw new IllegalArgumentException();
56 int length = elem.length();
58 if (delimit && !indexes.isEmpty()) {
59 path.append(delimiter);
60 length += delimiter.length();
65 indexes.addLast(Integer.valueOf(length));
69 if (indexes.isEmpty()) {
70 throw new IllegalStateException();
72 offset -= indexes.removeLast();
73 path.setLength(offset);
76 void pushToken(String token) {
84 void pushModifier(String modifier) {
85 push(modifier, false);
93 return path.substring(0, offset);
96 void entry(String name, String value) {
97 entries.put(name, value);
100 Map<String, String> entries() {
101 return Collections.unmodifiableMap(entries);