2 * Copyright (c) 2015 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.controller.netconf.mdsal.connector.ops;
11 import com.google.common.collect.Lists;
12 import java.util.ArrayDeque;
13 import java.util.ArrayList;
14 import java.util.Deque;
15 import java.util.List;
16 import org.opendaylight.yangtools.yang.data.api.ModifyAction;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20 public class DataTreeChangeTracker {
22 private final ModifyAction defaultAction;
24 private final Deque<ModifyAction> actions;
25 private final Deque<PathArgument> currentPath;
26 private final ArrayList<DataTreeChange> dataTreeChanges;
27 private int deleteOperationTracker = 0;
28 private int removeOperationTracker = 0;
30 public DataTreeChangeTracker(final ModifyAction defaultAction) {
31 this.defaultAction = defaultAction;
32 this.currentPath = new ArrayDeque<>();
33 this.actions = new ArrayDeque<>();
34 this.dataTreeChanges = new ArrayList<>();
37 public void pushAction(final ModifyAction action) {
38 if (ModifyAction.DELETE.equals(action)) {
39 deleteOperationTracker++;
42 if (ModifyAction.REMOVE.equals(action)) {
43 removeOperationTracker++;
45 this.actions.push(action);
48 public ModifyAction peekAction() {
49 return this.actions.peekFirst();
52 public ModifyAction popAction() {
53 final ModifyAction popResult = actions.pop();
54 if (ModifyAction.DELETE.equals(popResult)) {
55 deleteOperationTracker--;
58 if (ModifyAction.REMOVE.equals(popResult)) {
59 removeOperationTracker--;
64 public int getDeleteOperationTracker() {
65 return deleteOperationTracker;
68 public int getRemoveOperationTracker() {
69 return removeOperationTracker;
72 public void addDataTreeChange(final DataTreeChange change) {
73 dataTreeChanges.add(change);
76 public ArrayList<DataTreeChange> getDataTreeChanges() {
77 return dataTreeChanges;
80 public ModifyAction getDefaultAction() {
84 public void pushPath(final PathArgument pathArgument) {
85 currentPath.push(pathArgument);
88 public PathArgument popPath() {
89 return currentPath.pop();
92 public Deque<PathArgument> getCurrentPath() {
97 public static final class DataTreeChange {
99 private final NormalizedNode<?, ?> changeRoot;
100 private final ModifyAction action;
101 private final List<PathArgument> path;
103 public DataTreeChange(final NormalizedNode<?, ?> changeRoot, final ModifyAction action, final ArrayList<PathArgument> path) {
104 this.changeRoot = changeRoot;
105 this.action = action;
106 this.path = Lists.reverse(path);
109 public NormalizedNode<?, ?> getChangeRoot() {
113 public ModifyAction getAction() {
117 public List<PathArgument> getPath() {