Bumping versions by 0.0.1 for next dev cycle
[mdsal.git] / dom / mdsal-dom-inmemory-datastore / src / main / java / org / opendaylight / mdsal / dom / store / inmemory / ShardDataModificationCursor.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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
9 package org.opendaylight.mdsal.dom.store.inmemory;
10
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;
17
18 class ShardDataModificationCursor implements DOMDataTreeWriteCursor {
19
20     private final Deque<WriteCursorStrategy> stack = new ArrayDeque<>();
21     private final InmemoryDOMDataTreeShardWriteTransaction parent;
22
23     ShardDataModificationCursor(final ShardDataModification root, final InmemoryDOMDataTreeShardWriteTransaction parent) {
24         stack.push(root.createOperation(null));
25         this.parent = Preconditions.checkNotNull(parent);
26     }
27
28     @Override
29     public void enter(final PathArgument child) {
30         WriteCursorStrategy nextOp = getCurrent().enter(child);
31         stack.push(nextOp);
32     }
33
34     private WriteCursorStrategy getCurrent() {
35         return stack.peek();
36     }
37
38     @Override
39     public void enter(final PathArgument... path) {
40         for (PathArgument pathArgument : path) {
41             enter(pathArgument);
42         }
43     }
44
45     @Override
46     public void enter(final Iterable<PathArgument> path) {
47         for (PathArgument pathArgument : path) {
48             enter(pathArgument);
49         }
50     }
51
52     @Override
53     public void exit() {
54         WriteCursorStrategy op = stack.pop();
55         op.exit();
56     }
57
58     @Override
59     public void exit(final int depth) {
60         for (int i = 0; i < depth; i++) {
61             exit();
62         }
63     }
64
65     @Override
66     public void close() {
67         parent.cursorClosed();
68     }
69
70     @Override
71     public void delete(final PathArgument child) {
72         getCurrent().delete(child);
73     }
74
75     @Override
76     public void merge(final PathArgument child, final NormalizedNode<?, ?> data) {
77         getCurrent().merge(child, data);
78     }
79
80     @Override
81     public void write(final PathArgument child, final NormalizedNode<?, ?> data) {
82         getCurrent().write(child, data);
83     }
84
85 }