2 * Copyright (c) 2016 Cisco 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
9 package org.opendaylight.mdsal.dom.store.inmemory;
11 import com.google.common.base.Preconditions;
12 import java.util.ArrayDeque;
13 import java.util.Deque;
14 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
18 class ShardDataModificationCursor implements DOMDataTreeWriteCursor {
20 private final Deque<WriteCursorStrategy> stack = new ArrayDeque<>();
21 private final InmemoryDOMDataTreeShardWriteTransaction parent;
23 ShardDataModificationCursor(final ShardDataModification root,
24 final InmemoryDOMDataTreeShardWriteTransaction parent) {
25 stack.push(root.createOperation(null));
26 this.parent = Preconditions.checkNotNull(parent);
29 private WriteCursorStrategy getCurrent() {
34 public void enter(final PathArgument child) {
35 WriteCursorStrategy nextOp = getCurrent().enter(child);
40 public void enter(final PathArgument... path) {
41 for (PathArgument pathArgument : path) {
47 public void enter(final Iterable<PathArgument> path) {
48 for (PathArgument pathArgument : path) {
55 WriteCursorStrategy op = stack.pop();
60 public void exit(final int depth) {
61 for (int i = 0; i < depth; i++) {
68 parent.cursorClosed();
72 public void delete(final PathArgument child) {
73 getCurrent().delete(child);
77 public void merge(final PathArgument child, final NormalizedNode<?, ?> data) {
78 getCurrent().merge(child, data);
82 public void write(final PathArgument child, final NormalizedNode<?, ?> data) {
83 getCurrent().write(child, data);