43536b77cdc00032c8c7c856aac8cde4486d374e
[controller.git] / opendaylight / md-sal / sal-common-impl / src / main / java / org / opendaylight / controller / md / sal / common / impl / service / RootedChangeSet.java
1 /*
2  * Copyright (c) 2014, 2015 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.controller.md.sal.common.impl.service;
10
11 import java.util.HashMap;
12 import java.util.HashSet;
13 import java.util.Map;
14 import java.util.Map.Entry;
15 import java.util.Set;
16
17 import org.opendaylight.yangtools.concepts.Path;
18
19 public class RootedChangeSet<P extends Path<P>,D> {
20
21     private final P root;
22     private final Map<P,D> original;
23     private final Map<P,D> created = new HashMap<>();
24     private final Map<P,D> updated = new HashMap<>();
25     private final Set<P> removed = new HashSet<>();
26
27
28
29     public RootedChangeSet(P root,Map<P, D> original) {
30         super();
31         this.root = root;
32         this.original = original;
33     }
34
35     protected P getRoot() {
36         return root;
37     }
38
39     protected Map<P, D> getOriginal() {
40         return original;
41     }
42
43     protected Map<P, D> getCreated() {
44         return created;
45     }
46
47     protected Map<P, D> getUpdated() {
48         return updated;
49     }
50
51     protected Set<P> getRemoved() {
52         return removed;
53     }
54
55     public void addCreated(Map<P,D> created) {
56         this.created.putAll(created);
57     }
58
59     public void addCreated(Entry<P,D> entry) {
60         created.put(entry.getKey(), entry.getValue());
61     }
62
63     public void addUpdated(Entry<P,D> entry) {
64         updated.put(entry.getKey(), entry.getValue());
65     }
66
67     public void addRemoval(P path) {
68         removed.add(path);
69     }
70
71     public boolean isChange() {
72         return !created.isEmpty() || !updated.isEmpty() || !removed.isEmpty();
73     }
74 }