2 * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
10 import static com.google.common.base.Preconditions.checkState;
11 import static java.util.Objects.requireNonNull;
13 import java.util.Arrays;
14 import javax.annotation.concurrent.NotThreadSafe;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.opendaylight.yangtools.concepts.Mutable;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
22 final class ModificationPath implements Mutable {
23 private static final int DEFAULT_ALLOC_SIZE = 8;
24 private static final int ALLOC_SIZE = Integer.getInteger(
25 "org.opendaylight.yangtools.yang.data.impl.schema.tree.ModificationPath.ALLOC_SIZE", DEFAULT_ALLOC_SIZE);
27 private final YangInstanceIdentifier root;
29 private PathArgument[] entries = new PathArgument[ALLOC_SIZE];
32 ModificationPath(final YangInstanceIdentifier root) {
33 this.root = requireNonNull(root);
36 void push(final PathArgument arg) {
37 if (entries.length == used) {
38 final int grow = used <= 32 ? used : used / 2;
39 entries = Arrays.copyOf(entries, used + grow);
41 entries[used++] = requireNonNull(arg);
45 checkState(used > 0, "No elements left");
49 YangInstanceIdentifier toInstanceIdentifier() {
50 return YangInstanceIdentifier.builder(root).append(Arrays.asList(entries).subList(0, used)).build();
54 public String toString() {
55 return toInstanceIdentifier().toString();