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 public interface DataObjectModification<T extends DataObject>
28 extends org.opendaylight.yangtools.concepts.Identifiable<PathArgument> {
30 enum ModificationType {
32 * Child node (direct or indirect) was modified.
38 * Node was explicitly created / overwritten.
51 PathArgument getIdentifier();
54 * Returns type of modified object.
56 * @return type of modified object.
58 @NonNull Class<T> getDataType();
61 * Returns type of modification.
63 * @return type Type of performed modification.
65 @NonNull ModificationType getModificationType();
68 * Returns before-state of top level container. Implementations are encouraged,
69 * but not required to provide this state.
71 * @return State of object before modification. Null if subtree was not present,
72 * or the implementation cannot provide the state.
74 @Nullable T getDataBefore();
77 * Returns after-state of top level container.
79 * @return State of object after modification. Null if subtree is not present.
81 @Nullable T getDataAfter();
84 * Returns unmodifiable collection of modified direct children.
86 * @return unmodifiable collection of modified direct children.
88 @NonNull Collection<? extends DataObjectModification<? extends DataObject>> getModifiedChildren();
91 * Returns child list item modification if {@code child} was modified by this modification. This method should be
92 * used if the child is defined in a grouping brought into a case inside this object.
94 * @param caseType Case type class
95 * @param childType Type of list item - must be list item with key
96 * @return Modification of {@code child} if {@code child} was modified, null otherwise.
97 * @throws IllegalArgumentException If supplied {@code childType} class is not valid child according
100 default <H extends ChoiceIn<? super T> & DataObject, C extends ChildOf<? super H>>
101 Collection<DataObjectModification<C>> getModifiedChildren(final @NonNull Class<H> caseType,
102 final @NonNull Class<C> childType) {
103 final Item<C> item = Item.of(caseType, childType);
104 return (Collection<DataObjectModification<C>>) Collections2.filter(getModifiedChildren(),
105 mod -> item.equals(mod.getIdentifier()));
109 * Returns container child modification if {@code child} was modified by this modification. This method should be
110 * used if the child is defined in a grouping brought into a case inside this object.
113 * For accessing all modified list items consider iterating over {@link #getModifiedChildren()}.
115 * @param caseType Case type class
116 * @param child Type of child - must be only container
117 * @return Modification of {@code child} if {@code child} was modified, null otherwise.
118 * @throws IllegalArgumentException If supplied {@code child} class is not valid child according
119 * to generated model.
121 default @Nullable <H extends ChoiceIn<? super T> & DataObject, C extends ChildOf<? super H>>
122 DataObjectModification<C> getModifiedChildContainer(final @NonNull Class<H> caseType,
123 final @NonNull Class<C> child) {
124 return (DataObjectModification<C>) getModifiedChild(Item.of(caseType, child));
128 * Returns container child modification if {@code child} was modified by this modification.
131 * For accessing all modified list items consider iterating over {@link #getModifiedChildren()}.
133 * @param child Type of child - must be only container
134 * @return Modification of {@code child} if {@code child} was modified, null otherwise.
135 * @throws IllegalArgumentException If supplied {@code child} class is not valid child according
136 * to generated model.
138 @Nullable <C extends ChildOf<? super T>> DataObjectModification<C> getModifiedChildContainer(
139 @NonNull Class<C> child);
142 * Returns augmentation child modification if {@code augmentation} was modified by this modification.
145 * For accessing all modified list items consider iterating over {@link #getModifiedChildren()}.
147 * @param augmentation Type of augmentation - must be only container
148 * @return Modification of {@code augmentation} if {@code augmentation} was modified, null otherwise.
149 * @throws IllegalArgumentException If supplied {@code augmentation} class is not valid augmentation
150 * according to generated model.
152 @Nullable <C extends Augmentation<T> & DataObject> DataObjectModification<C> getModifiedAugmentation(
153 @NonNull Class<C> augmentation);
156 * Returns child list item modification if {@code child} was modified by this modification.
158 * @param listItem Type of list item - must be list item with key
159 * @param listKey List item key
160 * @return Modification of {@code child} if {@code child} was modified, null otherwise.
161 * @throws IllegalArgumentException If supplied {@code listItem} class is not valid child according
162 * to generated model.
164 <N extends Identifiable<K> & ChildOf<? super T>, K extends Identifier<N>> DataObjectModification<N>
165 getModifiedChildListItem(@NonNull Class<N> listItem, @NonNull K listKey);
168 * Returns child list item modification if {@code child} was modified by this modification.
170 * @param caseType Case type class
171 * @param listItem Type of list item - must be list item with key
172 * @param listKey List item key
173 * @return Modification of {@code child} if {@code child} was modified, null otherwise.
174 * @throws IllegalArgumentException If supplied {@code listItem} class is not valid child according
175 * to generated model.
177 default <H extends ChoiceIn<? super T> & DataObject, C extends Identifiable<K> & ChildOf<? super H>,
178 K extends Identifier<C>> DataObjectModification<C> getModifiedChildListItem(
179 final @NonNull Class<H> caseType, final @NonNull Class<C> listItem, final @NonNull K listKey) {
180 return (DataObjectModification<C>) getModifiedChild(IdentifiableItem.of(caseType, listItem, listKey));
184 * Returns a child modification if a node identified by {@code childArgument} was modified by
187 * @param childArgument Path Argument of child node
188 * @return Modification of child identified by {@code childArgument} if {@code childArgument}
189 * was modified, null otherwise.
190 * @throws IllegalArgumentException If supplied path argument is not valid child according to
194 @Nullable DataObjectModification<? extends DataObject> getModifiedChild(PathArgument childArgument);