checkStyleViolationSeverity=error implemented for mdsal-binding-api module
[mdsal.git] / binding / mdsal-binding-api / src / main / java / org / opendaylight / mdsal / 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
9 package org.opendaylight.mdsal.binding.api;
10
11 import java.util.Collection;
12 import javax.annotation.Nonnull;
13 import javax.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.DataObject;
17 import org.opendaylight.yangtools.yang.binding.Identifiable;
18 import org.opendaylight.yangtools.yang.binding.Identifier;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
20
21 /**
22  * Modified Data Object.
23  *
24  *<p>
25  * Represents modification of Data Object
26  *
27  *<p>
28  * @param <T> Type of modified object
29  *
30  */
31 public interface DataObjectModification<T extends DataObject> extends
32         org.opendaylight.yangtools.concepts.Identifiable<PathArgument> {
33
34     /**
35      * Represents type of modification which has occured.
36      *
37      */
38     enum ModificationType {
39         /**
40          * Child node (direct or indirect) was modified.
41          *
42          */
43         SUBTREE_MODIFIED,
44         /**
45          * Node was explicitly created / overwritten.
46          *
47          */
48         WRITE,
49         /**
50          * Node was deleted.
51          *
52          */
53         DELETE
54     }
55
56     @Override
57     PathArgument getIdentifier();
58
59     /**
60      * Returns type of modified object.
61      *
62      * @return type of modified object.
63      */
64     @Nonnull Class<T> getDataType();
65
66     /**
67      * Returns type of modification.
68      *
69      * @return type Type of performed modification.
70      */
71     @Nonnull ModificationType getModificationType();
72
73     /**
74      * Returns before-state of top level container. Implementations are encouraged, but not required
75      * to provide this state.
76      *
77      * @return State of object before modification. Null if subtree was not present, or the
78      *         implementation cannot provide the state.
79      */
80     @Nullable T getDataBefore();
81
82     /**
83      * Returns after-state of top level container.
84      *
85      * @return State of object after modification. Null if subtree is not present.
86      */
87     @Nullable T getDataAfter();
88
89     /**
90      * Returns unmodifiable collection of modified direct children.
91      *
92      * @return unmodifiable collection of modified direct children.
93      */
94     @Nonnull Collection<DataObjectModification<? extends DataObject>> getModifiedChildren();
95
96     /**
97      * Returns child list item modification if {@code child} was modified by this modification.
98      *
99      * @param childType Type of list item - must be list item with key
100      * @return Modification of {@code child} if {@code child} was modified, null otherwise.
101      * @throws IllegalArgumentException If supplied {@code childType} class is not valid child according
102      *         to generated model.
103      */
104     <C extends ChildOf<? super T>> Collection<DataObjectModification<C>> getModifiedChildren(
105             @Nonnull Class<C> childType);
106
107     /**
108      * Returns container child modification if {@code child} was modified by this
109      * modification.
110      *
111      *<p>
112      * For accessing all modified list items consider iterating over {@link #getModifiedChildren()}.
113      *
114      * @param child Type of child - must be only container
115      * @return Modification of {@code child} if {@code child} was modified, null otherwise.
116      * @throws IllegalArgumentException If supplied {@code child} class is not valid child according
117      *         to generated model.
118      */
119     @Nullable <C extends ChildOf<? super T>> DataObjectModification<C> getModifiedChildContainer(
120             @Nonnull Class<C> child);
121
122     /**
123      * Returns augmentation child modification if {@code augmentation} was modified by this
124      * modification.
125      *
126      *<p>
127      * For accessing all modified list items consider iterating over {@link #getModifiedChildren()}.
128      *
129      * @param augmentation Type of augmentation - must be only container
130      * @return Modification of {@code augmentation} if {@code augmentation} was modified, null otherwise.
131      * @throws IllegalArgumentException If supplied {@code augmentation} class is not valid augmentation
132      *         according to generated model.
133      */
134     @Nullable <C extends Augmentation<T> & DataObject> DataObjectModification<C> getModifiedAugmentation(
135             @Nonnull Class<C> augmentation);
136
137
138     /**
139      * Returns child list item modification if {@code child} was modified by this modification.
140      *
141      * @param listItem Type of list item - must be list item with key
142      * @param listKey List item key
143      * @return Modification of {@code child} if {@code child} was modified, null otherwise.
144      * @throws IllegalArgumentException If supplied {@code listItem} class is not valid child according
145      *         to generated model.
146      */
147     <C extends Identifiable<K> & ChildOf<? super T>, K extends Identifier<C>> DataObjectModification<C>
148             getModifiedChildListItem(@Nonnull Class<C> listItem,@Nonnull  K listKey);
149
150     /**
151      * Returns a child modification if a node identified by {@code childArgument} was modified by
152      * this modification.
153      *
154      * @param childArgument Path Argument of child node
155      * @return Modification of child identified by {@code childArgument} if {@code childArgument}
156      *         was modified, null otherwise.
157      * @throws IllegalArgumentException If supplied path argument is not valid child according to
158      *         generated model.
159      *
160      */
161     @Nullable DataObjectModification<? extends DataObject> getModifiedChild(PathArgument childArgument);
162
163 }