Deprecate old MD-SAL APIs for removal
[controller.git] / opendaylight / md-sal / sal-binding-api / src / main / java / org / opendaylight / controller / md / sal / binding / api / DataObjectModification.java
1 /*
2  * Copyright (c) 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 package org.opendaylight.controller.md.sal.binding.api;
9
10 import com.google.common.collect.Collections2;
11 import java.util.Collection;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.yangtools.yang.binding.Augmentation;
15 import org.opendaylight.yangtools.yang.binding.ChildOf;
16 import org.opendaylight.yangtools.yang.binding.ChoiceIn;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18 import org.opendaylight.yangtools.yang.binding.Identifiable;
19 import org.opendaylight.yangtools.yang.binding.Identifier;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.Item;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
23
24 /**
25  * Represents a modification of DataObject.
26  *
27  * @deprecated Use {@link org.opendaylight.mdsal.binding.api.DataObjectModification} instead.
28  */
29 @Deprecated(forRemoval = true)
30 public interface DataObjectModification<T extends DataObject>
31         extends org.opendaylight.yangtools.concepts.Identifiable<PathArgument> {
32
33     enum ModificationType {
34         /**
35          * Child node (direct or indirect) was modified.
36          *
37          */
38         SUBTREE_MODIFIED,
39
40         /**
41          * Node was explicitly created / overwritten.
42          *
43          */
44
45         WRITE,
46         /**
47          * Node was deleted.
48          *
49          */
50         DELETE
51     }
52
53     @Override
54     PathArgument getIdentifier();
55
56     /**
57      * Returns type of modified object.
58      *
59      * @return type of modified object.
60      */
61     @NonNull Class<T> getDataType();
62
63     /**
64      * Returns type of modification.
65      *
66      * @return type Type of performed modification.
67      */
68     @NonNull ModificationType getModificationType();
69
70     /**
71      * Returns before-state of top level container. Implementations are encouraged,
72      * but not required to provide this state.
73      *
74      * @return State of object before modification. Null if subtree was not present,
75      *         or the implementation cannot provide the state.
76      */
77     @Nullable T getDataBefore();
78
79     /**
80      * Returns after-state of top level container.
81      *
82      * @return State of object after modification. Null if subtree is not present.
83      */
84     @Nullable T getDataAfter();
85
86     /**
87      * Returns unmodifiable collection of modified direct children.
88      *
89      * @return unmodifiable collection of modified direct children.
90      */
91     @NonNull Collection<? extends DataObjectModification<? extends DataObject>> getModifiedChildren();
92
93     /**
94      * Returns child list item modification if {@code child} was modified by this modification. This method should be
95      * used if the child is defined in a grouping brought into a case inside this object.
96      *
97      * @param caseType Case type class
98      * @param childType Type of list item - must be list item with key
99      * @return Modification of {@code child} if {@code child} was modified, null otherwise.
100      * @throws IllegalArgumentException If supplied {@code childType} class is not valid child according
101      *         to generated model.
102      */
103     default <H extends ChoiceIn<? super T> & DataObject, C extends ChildOf<? super H>>
104         Collection<DataObjectModification<C>> getModifiedChildren(final @NonNull Class<H> caseType,
105                 final @NonNull Class<C> childType) {
106         final Item<C> item = Item.of(caseType, childType);
107         return (Collection<DataObjectModification<C>>) Collections2.filter(getModifiedChildren(),
108             mod -> item.equals(mod.getIdentifier()));
109     }
110
111     /**
112      * Returns container child modification if {@code child} was modified by this modification. This method should be
113      * used if the child is defined in a grouping brought into a case inside this object.
114      *
115      * <p>
116      * For accessing all modified list items consider iterating over {@link #getModifiedChildren()}.
117      *
118      * @param caseType Case type class
119      * @param child Type of child - must be only container
120      * @return Modification of {@code child} if {@code child} was modified, null otherwise.
121      * @throws IllegalArgumentException If supplied {@code child} class is not valid child according
122      *         to generated model.
123      */
124     default @Nullable <H extends ChoiceIn<? super T> & DataObject, C extends ChildOf<? super H>>
125             DataObjectModification<C> getModifiedChildContainer(final @NonNull Class<H> caseType,
126                     final @NonNull Class<C> child) {
127         return (DataObjectModification<C>) getModifiedChild(Item.of(caseType, child));
128     }
129
130     /**
131      * Returns container child modification if {@code child} was modified by this modification.
132      *
133      * <p>
134      * For accessing all modified list items consider iterating over {@link #getModifiedChildren()}.
135      *
136      * @param child Type of child - must be only container
137      * @return Modification of {@code child} if {@code child} was modified, null otherwise.
138      * @throws IllegalArgumentException If supplied {@code child} class is not valid child according
139      *         to generated model.
140      */
141     @Nullable <C extends ChildOf<? super T>> DataObjectModification<C> getModifiedChildContainer(
142             @NonNull Class<C> child);
143
144     /**
145      * Returns augmentation child modification if {@code augmentation} was modified by this modification.
146      *
147      * <p>
148      * For accessing all modified list items consider iterating over {@link #getModifiedChildren()}.
149      *
150      * @param augmentation Type of augmentation - must be only container
151      * @return Modification of {@code augmentation} if {@code augmentation} was modified, null otherwise.
152      * @throws IllegalArgumentException If supplied {@code augmentation} class is not valid augmentation
153      *         according to generated model.
154      */
155     @Nullable <C extends Augmentation<T> & DataObject> DataObjectModification<C> getModifiedAugmentation(
156             @NonNull Class<C> augmentation);
157
158     /**
159      * Returns child list item modification if {@code child} was modified by this modification.
160      *
161      * @param listItem Type of list item - must be list item with key
162      * @param listKey List item key
163      * @return Modification of {@code child} if {@code child} was modified, null otherwise.
164      * @throws IllegalArgumentException If supplied {@code listItem} class is not valid child according
165      *         to generated model.
166      */
167     <N extends Identifiable<K> & ChildOf<? super T>, K extends Identifier<N>> DataObjectModification<N>
168             getModifiedChildListItem(@NonNull Class<N> listItem, @NonNull K listKey);
169
170     /**
171      * Returns child list item modification if {@code child} was modified by this modification.
172      *
173      * @param caseType Case type class
174      * @param listItem Type of list item - must be list item with key
175      * @param listKey List item key
176      * @return Modification of {@code child} if {@code child} was modified, null otherwise.
177      * @throws IllegalArgumentException If supplied {@code listItem} class is not valid child according
178      *         to generated model.
179      */
180     default <H extends ChoiceIn<? super T> & DataObject, C extends Identifiable<K> & ChildOf<? super H>,
181             K extends Identifier<C>> DataObjectModification<C> getModifiedChildListItem(
182                     final @NonNull Class<H> caseType, final @NonNull Class<C> listItem, final @NonNull K listKey) {
183         return (DataObjectModification<C>) getModifiedChild(IdentifiableItem.of(caseType, listItem, listKey));
184     }
185
186     /**
187      * Returns a child modification if a node identified by {@code childArgument} was modified by
188      * this modification.
189      *
190      * @param childArgument Path Argument of child node
191      * @return Modification of child identified by {@code childArgument} if {@code childArgument}
192      *         was modified, null otherwise.
193      * @throws IllegalArgumentException If supplied path argument is not valid child according to
194      *         generated model.
195      *
196      */
197     @Nullable DataObjectModification<? extends DataObject> getModifiedChild(PathArgument childArgument);
198 }