checkStyleViolationSeverity=error implemented for mdsal-dom-inmemory-datastore
[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,
24             final InmemoryDOMDataTreeShardWriteTransaction parent) {
25         stack.push(root.createOperation(null));
26         this.parent = Preconditions.checkNotNull(parent);
27     }
28
29     private WriteCursorStrategy getCurrent() {
30         return stack.peek();
31     }
32
33     @Override
34     public void enter(final PathArgument child) {
35         WriteCursorStrategy nextOp = getCurrent().enter(child);
36         stack.push(nextOp);
37     }
38
39     @Override
40     public void enter(final PathArgument... path) {
41         for (PathArgument pathArgument : path) {
42             enter(pathArgument);
43         }
44     }
45
46     @Override
47     public void enter(final Iterable<PathArgument> path) {
48         for (PathArgument pathArgument : path) {
49             enter(pathArgument);
50         }
51     }
52
53     @Override
54     public void exit() {
55         WriteCursorStrategy op = stack.pop();
56         op.exit();
57     }
58
59     @Override
60     public void exit(final int depth) {
61         for (int i = 0; i < depth; i++) {
62             exit();
63         }
64     }
65
66     @Override
67     public void close() {
68         parent.cursorClosed();
69     }
70
71     @Override
72     public void delete(final PathArgument child) {
73         getCurrent().delete(child);
74     }
75
76     @Override
77     public void merge(final PathArgument child, final NormalizedNode<?, ?> data) {
78         getCurrent().merge(child, data);
79     }
80
81     @Override
82     public void write(final PathArgument child, final NormalizedNode<?, ?> data) {
83         getCurrent().write(child, data);
84     }
85
86 }