2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.md.sal.binding.api;
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;
25 * Represents a modification of DataObject.
27 * @deprecated Use {@link org.opendaylight.mdsal.binding.api.DataObjectModification} instead.
30 public interface DataObjectModification<T extends DataObject>
31 extends org.opendaylight.yangtools.concepts.Identifiable<PathArgument> {
33 enum ModificationType {
35 * Child node (direct or indirect) was modified.
41 * Node was explicitly created / overwritten.
54 PathArgument getIdentifier();
57 * Returns type of modified object.
59 * @return type of modified object.
61 @NonNull Class<T> getDataType();
64 * Returns type of modification.
66 * @return type Type of performed modification.
68 @NonNull ModificationType getModificationType();
71 * Returns before-state of top level container. Implementations are encouraged,
72 * but not required to provide this state.
74 * @return State of object before modification. Null if subtree was not present,
75 * or the implementation cannot provide the state.
77 @Nullable T getDataBefore();
80 * Returns after-state of top level container.
82 * @return State of object after modification. Null if subtree is not present.
84 @Nullable T getDataAfter();
87 * Returns unmodifiable collection of modified direct children.
89 * @return unmodifiable collection of modified direct children.
91 @NonNull Collection<? extends DataObjectModification<? extends DataObject>> getModifiedChildren();
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.
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.
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()));
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.
116 * For accessing all modified list items consider iterating over {@link #getModifiedChildren()}.
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.
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));
131 * Returns container child modification if {@code child} was modified by this modification.
134 * For accessing all modified list items consider iterating over {@link #getModifiedChildren()}.
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.
141 @Nullable <C extends ChildOf<? super T>> DataObjectModification<C> getModifiedChildContainer(
142 @NonNull Class<C> child);
145 * Returns augmentation child modification if {@code augmentation} was modified by this modification.
148 * For accessing all modified list items consider iterating over {@link #getModifiedChildren()}.
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.
155 @Nullable <C extends Augmentation<T> & DataObject> DataObjectModification<C> getModifiedAugmentation(
156 @NonNull Class<C> augmentation);
159 * Returns child list item modification if {@code child} was modified by this modification.
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.
167 <N extends Identifiable<K> & ChildOf<? super T>, K extends Identifier<N>> DataObjectModification<N>
168 getModifiedChildListItem(@NonNull Class<N> listItem, @NonNull K listKey);
171 * Returns child list item modification if {@code child} was modified by this modification.
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.
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));
187 * Returns a child modification if a node identified by {@code childArgument} was modified by
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
197 @Nullable DataObjectModification<? extends DataObject> getModifiedChild(PathArgument childArgument);