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 org.eclipse.jdt.annotation.NonNullByDefault;
15 import org.opendaylight.yangtools.concepts.Mutable;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
20 final class ModificationPath implements Mutable {
21 private static final int DEFAULT_ALLOC_SIZE = 8;
22 private static final int ALLOC_SIZE = Integer.getInteger(
23 "org.opendaylight.yangtools.yang.data.impl.schema.tree.ModificationPath.ALLOC_SIZE", DEFAULT_ALLOC_SIZE);
25 private final YangInstanceIdentifier root;
27 private PathArgument[] entries = new PathArgument[ALLOC_SIZE];
30 ModificationPath(final YangInstanceIdentifier root) {
31 this.root = requireNonNull(root);
34 void push(final PathArgument arg) {
35 if (entries.length == used) {
36 final int grow = used <= 32 ? used : used / 2;
37 entries = Arrays.copyOf(entries, used + grow);
39 entries[used++] = requireNonNull(arg);
43 checkState(used > 0, "No elements left");
47 YangInstanceIdentifier toInstanceIdentifier() {
48 return YangInstanceIdentifier.builder(root).append(Arrays.asList(entries).subList(0, used)).build();
52 public String toString() {
53 return toInstanceIdentifier().toString();