Fix sonar warnings in sal-distributed-datastore
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / actors / dds / ClientTransactionCursor.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 package org.opendaylight.controller.cluster.databroker.actors.dds;
9
10 import com.google.common.base.Preconditions;
11 import java.util.Arrays;
12 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
16
17 /**
18  * A {@link DOMDataTreeWriteCursor} tied to a {@link ClientTransaction}.
19  *
20  * @author Robert Varga
21  */
22 final class ClientTransactionCursor implements DOMDataTreeWriteCursor {
23     private YangInstanceIdentifier current = YangInstanceIdentifier.EMPTY;
24     private final ClientTransaction parent;
25
26     ClientTransactionCursor(final ClientTransaction parent) {
27         this.parent = Preconditions.checkNotNull(parent);
28     }
29
30     @Override
31     public void enter(final PathArgument child) {
32         current = current.node(child);
33     }
34
35     @Override
36     public void enter(final PathArgument... path) {
37         enter(Arrays.asList(path));
38     }
39
40     @Override
41     public void enter(final Iterable<PathArgument> path) {
42         path.forEach(this::enter);
43     }
44
45     @Override
46     public void exit() {
47         final YangInstanceIdentifier currentParent = current.getParent();
48         Preconditions.checkState(currentParent != null);
49         current = currentParent;
50     }
51
52     @Override
53     public void exit(final int depth) {
54         for (int i = 0; i < depth; ++i) {
55             exit();
56         }
57     }
58
59     @Override
60     public void close() {
61         parent.closeCursor(this);
62     }
63
64     @Override
65     public void delete(final PathArgument child) {
66         parent.delete(current.node(child));
67     }
68
69     @Override
70     public void merge(final PathArgument child, final NormalizedNode<?, ?> data) {
71         parent.merge(current.node(child), data);
72     }
73
74     @Override
75     public void write(final PathArgument child, final NormalizedNode<?, ?> data) {
76         parent.write(current.node(child), data);
77     }
78 }