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 com.google.common.annotations.Beta;
11 import com.google.common.base.Preconditions;
12 import com.google.common.base.Verify;
13 import java.util.Optional;
14 import javax.annotation.Nonnull;
15 import javax.annotation.concurrent.NotThreadSafe;
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.api.schema.tree.DataTreeModificationCursor;
22 * Abstract {@link DataTreeModificationCursor} which tracks the current path. Subclasses can get the current path
23 * via {@link #current()}.
25 * @author Thomas Pantelis
29 public abstract class AbstractDataTreeModificationCursor implements DataTreeModificationCursor {
30 private YangInstanceIdentifier current = YangInstanceIdentifier.EMPTY;
32 protected final YangInstanceIdentifier current() {
37 public final void enter(@Nonnull final PathArgument child) {
38 current = current.node(child);
42 public final void enter(@Nonnull final PathArgument... path) {
43 for (PathArgument arg : path) {
49 public final void enter(@Nonnull final Iterable<PathArgument> path) {
50 for (PathArgument arg : path) {
56 public final void exit() {
57 Preconditions.checkState(!current.isEmpty());
58 current = Verify.verifyNotNull(current.getParent());
62 public final void exit(final int depth) {
63 Preconditions.checkArgument(depth >= 0);
65 YangInstanceIdentifier next = current;
66 for (int i = 0; i < depth; ++i) {
67 next = next.getParent();
68 Preconditions.checkState(next != null);
75 public final Optional<NormalizedNode<?, ?>> readNode(@Nonnull final PathArgument child) {
76 throw new UnsupportedOperationException("Not implemented");