2 * Copyright (c) 2016 Brocade Communications Systems, Inc. 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.controller.cluster.datastore.utils;
10 import com.google.common.base.Optional;
11 import com.google.common.base.Preconditions;
12 import java.util.ArrayDeque;
13 import java.util.Deque;
14 import javax.annotation.Nonnull;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModificationCursor;
21 * Base class for a DataTreeModificationCursor.
23 * @author Thomas Pantelis
25 public abstract class AbstractDataTreeModificationCursor implements DataTreeModificationCursor {
26 private final Deque<YangInstanceIdentifier> stack = new ArrayDeque<>();
28 protected AbstractDataTreeModificationCursor() {
29 stack.push(YangInstanceIdentifier.EMPTY);
32 protected YangInstanceIdentifier next(@Nonnull final PathArgument child) {
33 return stack.peek().node(child);
37 public void enter(@Nonnull final PathArgument child) {
38 stack.push(stack.peek().node(child));
42 public void enter(@Nonnull final PathArgument... path) {
43 for (PathArgument arg : path) {
49 public void enter(@Nonnull final Iterable<PathArgument> path) {
50 for (PathArgument arg : path) {
61 public void exit(final int depth) {
62 Preconditions.checkArgument(depth < stack.size(), "Stack holds only %s elements, cannot exit %s levels", stack.size(), depth);
63 for (int i = 0; i < depth; ++i) {
69 public Optional<NormalizedNode<?, ?>> readNode(@Nonnull final PathArgument child) {
70 throw new UnsupportedOperationException("Not implemented");