2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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 * ============LICENSE_END=========================================================
24 package org.onap.appc.util;
27 import java.util.Collections;
28 import java.util.LinkedHashMap;
29 import java.util.LinkedList;
34 private StringBuilder path = new StringBuilder(128);
36 private LinkedList<Integer> indexes = new LinkedList<>();
37 private Map<String, String> entries = new LinkedHashMap<>();
38 private int offset = 0;
40 private final String delimiter;
46 PathContext(String delimiter) {
47 this.delimiter = delimiter;
50 private void push(String elem, boolean delimit) {
52 throw new IllegalArgumentException();
55 int length = elem.length();
57 if (delimit && !indexes.isEmpty()) {
58 path.append(delimiter);
59 length += delimiter.length();
64 indexes.addLast(Integer.valueOf(length));
68 if (indexes.isEmpty()) {
69 throw new IllegalStateException();
71 offset -= indexes.removeLast();
72 path.setLength(offset);
75 void pushToken(String token) {
83 void pushModifier(String modifier) {
84 push(modifier, false);
92 return path.substring(0, offset);
95 void entry(String name, String value) {
96 entries.put(name, value);
99 Map<String, String> entries() {
100 return Collections.unmodifiableMap(entries);