Bug 2364: Migrated Binding MD-SAL to not use composites nodes
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / compat / HydrogenDataChangeEvent.java
1 /*
2  * Copyright (c) 2014 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.md.sal.binding.compat;
9
10 import java.util.Collections;
11 import java.util.HashMap;
12 import java.util.Map;
13 import java.util.Set;
14
15 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
16 import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19
20 @Deprecated
21 public abstract class HydrogenDataChangeEvent implements
22         DataChangeEvent<InstanceIdentifier<? extends DataObject>, DataObject> {
23
24     private HydrogenDataChangeEvent() {
25     }
26
27     public static final DataChangeEvent<InstanceIdentifier<?>, DataObject> createOperational(
28             final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
29         return new OperationalChangeEvent(change);
30     }
31
32     public static final DataChangeEvent<InstanceIdentifier<?>, DataObject> createConfiguration(
33             final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
34         return new ConfigurationChangeEvent(change);
35     }
36
37     @Override
38     public Map<InstanceIdentifier<?>, DataObject> getCreatedOperationalData() {
39         return Collections.emptyMap();
40     }
41
42     @Override
43     public Map<InstanceIdentifier<?>, DataObject> getCreatedConfigurationData() {
44         return Collections.emptyMap();
45     }
46
47     @Override
48     public Map<InstanceIdentifier<?>, DataObject> getUpdatedOperationalData() {
49         return Collections.emptyMap();
50     }
51
52     @Override
53     public Map<InstanceIdentifier<?>, DataObject> getUpdatedConfigurationData() {
54         return Collections.emptyMap();
55     }
56
57     @Override
58     public Set<InstanceIdentifier<?>> getRemovedConfigurationData() {
59         return Collections.emptySet();
60     }
61
62     @Override
63     public Set<InstanceIdentifier<?>> getRemovedOperationalData() {
64         return Collections.emptySet();
65     }
66
67     @Override
68     public Map<InstanceIdentifier<?>, DataObject> getOriginalConfigurationData() {
69         return Collections.emptyMap();
70     }
71
72     @Override
73     public Map<InstanceIdentifier<?>, DataObject> getOriginalOperationalData() {
74         return Collections.emptyMap();
75     }
76
77     @Override
78     public DataObject getOriginalConfigurationSubtree() {
79         return null;
80     }
81
82     @Override
83     public DataObject getOriginalOperationalSubtree() {
84         return null;
85     }
86
87     @Override
88     public DataObject getUpdatedConfigurationSubtree() {
89         return null;
90     }
91
92     @Override
93     public DataObject getUpdatedOperationalSubtree() {
94         return null;
95     }
96
97     @SuppressWarnings({ "rawtypes", "unchecked" })
98     private final static class OperationalChangeEvent extends HydrogenDataChangeEvent {
99
100         private final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> delegate;
101         private Map<InstanceIdentifier<?>, DataObject> updatedCache;
102
103         public OperationalChangeEvent(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
104             this.delegate = change;
105         }
106
107         @Override
108         public Map<InstanceIdentifier<?>, DataObject> getCreatedOperationalData() {
109             return delegate.getCreatedData();
110         }
111
112         @Override
113         public Set<InstanceIdentifier<?>> getRemovedOperationalData() {
114             return delegate.getRemovedPaths();
115         }
116
117         @Override
118         public DataObject getOriginalOperationalSubtree() {
119             return delegate.getOriginalSubtree();
120         }
121
122         @Override
123         public DataObject getUpdatedOperationalSubtree() {
124             return delegate.getUpdatedSubtree();
125         }
126
127         @Override
128         public Map<InstanceIdentifier<?>, DataObject> getOriginalOperationalData() {
129             return (Map) delegate.getOriginalData();
130         }
131
132         @Override
133         public Map<InstanceIdentifier<?>, DataObject> getUpdatedOperationalData() {
134             if(updatedCache == null) {
135                 Map<InstanceIdentifier<?>, DataObject> created = delegate.getCreatedData();
136                 Map<InstanceIdentifier<?>, DataObject> updated = delegate.getUpdatedData();
137                 HashMap<InstanceIdentifier<?>, DataObject> updatedComposite = new HashMap<>(created.size() + updated.size());
138                 updatedComposite.putAll(created);
139                 updatedComposite.putAll(updated);
140                 updatedCache = Collections.unmodifiableMap(updatedComposite);
141             }
142             return updatedCache;
143         }
144
145         @Override
146         public String toString() {
147             return "OperationalChangeEvent [delegate=" + delegate + "]";
148         }
149
150     }
151
152     @SuppressWarnings({ "rawtypes", "unchecked" })
153     private final static class ConfigurationChangeEvent extends HydrogenDataChangeEvent {
154
155         private final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> delegate;
156         private Map<InstanceIdentifier<?>, DataObject> updatedCache;
157
158         public ConfigurationChangeEvent(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
159             this.delegate = change;
160         }
161
162         @Override
163         public Map<InstanceIdentifier<?>, DataObject> getCreatedConfigurationData() {
164             return delegate.getCreatedData();
165         }
166
167         @Override
168         public Set<InstanceIdentifier<?>> getRemovedConfigurationData() {
169             return delegate.getRemovedPaths();
170         }
171
172         @Override
173         public DataObject getOriginalConfigurationSubtree() {
174             return delegate.getOriginalSubtree();
175         }
176
177         @Override
178         public DataObject getUpdatedConfigurationSubtree() {
179             return delegate.getUpdatedSubtree();
180         }
181
182         @Override
183         public Map<InstanceIdentifier<?>, DataObject> getOriginalConfigurationData() {
184             return (Map) delegate.getOriginalData();
185         }
186
187         @Override
188         public Map<InstanceIdentifier<?>, DataObject> getUpdatedConfigurationData() {
189             if(updatedCache == null) {
190                 Map<InstanceIdentifier<?>, DataObject> created = delegate.getCreatedData();
191                 Map<InstanceIdentifier<?>, DataObject> updated = delegate.getUpdatedData();
192                 HashMap<InstanceIdentifier<?>, DataObject> updatedComposite = new HashMap<>(created.size() + updated.size());
193                 updatedComposite.putAll(created);
194                 updatedComposite.putAll(updated);
195                 updatedCache = Collections.unmodifiableMap(updatedComposite);
196             }
197             return updatedCache;
198         }
199
200         @Override
201         public String toString() {
202             return "ConfigurationChangeEvent [delegate=" + delegate + "]";
203         }
204
205     }
206
207 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.