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.util;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static com.google.common.base.Preconditions.checkState;
12 import static com.google.common.base.Verify.verifyNotNull;
14 import com.google.common.annotations.Beta;
15 import java.util.Optional;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModificationCursor;
22 * Abstract {@link DataTreeModificationCursor} which tracks the current path. Subclasses can get the current path
23 * via {@link #current()}. This class is NOT thread-safe.
25 * @author Thomas Pantelis
28 public abstract class AbstractDataTreeModificationCursor implements DataTreeModificationCursor {
29 private YangInstanceIdentifier current = YangInstanceIdentifier.of();
31 protected final YangInstanceIdentifier current() {
36 public final void enter(final PathArgument child) {
37 current = current.node(child);
41 public final void enter(final PathArgument... path) {
42 for (PathArgument arg : path) {
48 public final void enter(final Iterable<PathArgument> path) {
49 for (PathArgument arg : path) {
55 public final void exit() {
56 checkState(!current.isEmpty());
57 current = verifyNotNull(current.getParent());
61 public final void exit(final int depth) {
62 checkArgument(depth >= 0);
64 YangInstanceIdentifier next = current;
65 for (int i = 0; i < depth; ++i) {
66 next = next.getParent();
67 checkState(next != null);
74 public final Optional<NormalizedNode> readNode(final PathArgument child) {
75 throw new UnsupportedOperationException("Not implemented");