8f50d0ad2e0788a822ac7d5364e10ab3e4ca5d62
[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 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
15 import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18
19 @Deprecated
20 public abstract class HydrogenDataChangeEvent implements
21         DataChangeEvent<InstanceIdentifier<? extends DataObject>, DataObject> {
22
23     private HydrogenDataChangeEvent() {
24     }
25
26     public static final DataChangeEvent<InstanceIdentifier<?>, DataObject> createOperational(
27             final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
28         return new OperationalChangeEvent(change);
29     }
30
31     public static final DataChangeEvent<InstanceIdentifier<?>, DataObject> createConfiguration(
32             final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
33         return new ConfigurationChangeEvent(change);
34     }
35
36     @Override
37     public Map<InstanceIdentifier<?>, DataObject> getCreatedOperationalData() {
38         return Collections.emptyMap();
39     }
40
41     @Override
42     public Map<InstanceIdentifier<?>, DataObject> getCreatedConfigurationData() {
43         return Collections.emptyMap();
44     }
45
46     @Override
47     public Map<InstanceIdentifier<?>, DataObject> getUpdatedOperationalData() {
48         return Collections.emptyMap();
49     }
50
51     @Override
52     public Map<InstanceIdentifier<?>, DataObject> getUpdatedConfigurationData() {
53         return Collections.emptyMap();
54     }
55
56     @Override
57     public Set<InstanceIdentifier<?>> getRemovedConfigurationData() {
58         return Collections.emptySet();
59     }
60
61     @Override
62     public Set<InstanceIdentifier<?>> getRemovedOperationalData() {
63         return Collections.emptySet();
64     }
65
66     @Override
67     public Map<InstanceIdentifier<?>, DataObject> getOriginalConfigurationData() {
68         return Collections.emptyMap();
69     }
70
71     @Override
72     public Map<InstanceIdentifier<?>, DataObject> getOriginalOperationalData() {
73         return Collections.emptyMap();
74     }
75
76     @Override
77     public DataObject getOriginalConfigurationSubtree() {
78         return null;
79     }
80
81     @Override
82     public DataObject getOriginalOperationalSubtree() {
83         return null;
84     }
85
86     @Override
87     public DataObject getUpdatedConfigurationSubtree() {
88         return null;
89     }
90
91     @Override
92     public DataObject getUpdatedOperationalSubtree() {
93         return null;
94     }
95
96     @SuppressWarnings({ "rawtypes", "unchecked" })
97     private static final class OperationalChangeEvent extends HydrogenDataChangeEvent {
98
99         private final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> delegate;
100         private Map<InstanceIdentifier<?>, DataObject> updatedCache;
101
102         public OperationalChangeEvent(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
103             this.delegate = change;
104         }
105
106         @Override
107         public Map<InstanceIdentifier<?>, DataObject> getCreatedOperationalData() {
108             return delegate.getCreatedData();
109         }
110
111         @Override
112         public Set<InstanceIdentifier<?>> getRemovedOperationalData() {
113             return delegate.getRemovedPaths();
114         }
115
116         @Override
117         public DataObject getOriginalOperationalSubtree() {
118             return delegate.getOriginalSubtree();
119         }
120
121         @Override
122         public DataObject getUpdatedOperationalSubtree() {
123             return delegate.getUpdatedSubtree();
124         }
125
126         @Override
127         public Map<InstanceIdentifier<?>, DataObject> getOriginalOperationalData() {
128             return (Map) delegate.getOriginalData();
129         }
130
131         @Override
132         public Map<InstanceIdentifier<?>, DataObject> getUpdatedOperationalData() {
133             if(updatedCache == null) {
134                 final Map<InstanceIdentifier<?>, DataObject> created = delegate.getCreatedData();
135                 final Map<InstanceIdentifier<?>, DataObject> updated = delegate.getUpdatedData();
136                 final Map<InstanceIdentifier<?>, DataObject> updatedComposite =
137                         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 static final 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                 final Map<InstanceIdentifier<?>, DataObject> created = delegate.getCreatedData();
191                 final Map<InstanceIdentifier<?>, DataObject> updated = delegate.getUpdatedData();
192                 final Map<InstanceIdentifier<?>, DataObject> updatedComposite =
193                         new HashMap<>(created.size() + updated.size());
194                 updatedComposite.putAll(created);
195                 updatedComposite.putAll(updated);
196                 updatedCache = Collections.unmodifiableMap(updatedComposite);
197             }
198             return updatedCache;
199         }
200
201         @Override
202         public String toString() {
203             return "ConfigurationChangeEvent [delegate=" + delegate + "]";
204         }
205
206     }
207
208 }

©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.