Do not pretty-print body class
[yangtools.git] / data / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / ModificationPath.java
1 /*
2  * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
9
10 import static com.google.common.base.Preconditions.checkState;
11 import static java.util.Objects.requireNonNull;
12
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;
18
19 @NonNullByDefault
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);
24
25     private final YangInstanceIdentifier root;
26
27     private PathArgument[] entries = new PathArgument[ALLOC_SIZE];
28     private int used;
29
30     ModificationPath(final YangInstanceIdentifier root) {
31         this.root = requireNonNull(root);
32     }
33
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);
38         }
39         entries[used++] = requireNonNull(arg);
40     }
41
42     void pop() {
43         checkState(used > 0, "No elements left");
44         used--;
45     }
46
47     YangInstanceIdentifier toInstanceIdentifier() {
48         return YangInstanceIdentifier.builder(root).append(Arrays.asList(entries).subList(0, used)).build();
49     }
50
51     @Override
52     public String toString() {
53         return toInstanceIdentifier().toString();
54     }
55 }