*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.controller.md.sal.binding.api;
+import com.google.common.collect.Collections2;
import java.util.Collection;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.binding.Augmentation;
import org.opendaylight.yangtools.yang.binding.ChildOf;
+import org.opendaylight.yangtools.yang.binding.ChoiceIn;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.Identifiable;
import org.opendaylight.yangtools.yang.binding.Identifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.Item;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
/**
- * Modified Data Object.
- *
- * Represents modification of Data Object.
+ * Represents a modification of DataObject.
*
+ * @deprecated Use {@link org.opendaylight.mdsal.binding.api.DataObjectModification} instead.
*/
-public interface DataObjectModification<T extends DataObject> extends org.opendaylight.yangtools.concepts.Identifiable<PathArgument> {
+@Deprecated(forRemoval = true)
+public interface DataObjectModification<T extends DataObject>
+ extends org.opendaylight.yangtools.concepts.Identifiable<PathArgument> {
enum ModificationType {
/**
- *
* Child node (direct or indirect) was modified.
*
*/
SUBTREE_MODIFIED,
+
/**
- *
* Node was explicitly created / overwritten.
*
*/
+
WRITE,
/**
- *
* Node was deleted.
*
*/
*
* @return type of modified object.
*/
- @Nonnull Class<T> getDataType();
+ @NonNull Class<T> getDataType();
/**
- *
- * Returns type of modification
+ * Returns type of modification.
*
* @return type Type of performed modification.
*/
- @Nonnull ModificationType getModificationType();
+ @NonNull ModificationType getModificationType();
/**
* Returns before-state of top level container. Implementations are encouraged,
* but not required to provide this state.
*
- * @param root Class representing data container
* @return State of object before modification. Null if subtree was not present,
* or the implementation cannot provide the state.
*/
/**
* Returns after-state of top level container.
*
- * @param root Class representing data container
* @return State of object after modification. Null if subtree is not present.
*/
@Nullable T getDataAfter();
*
* @return unmodifiable collection of modified direct children.
*/
- @Nonnull Collection<DataObjectModification<? extends DataObject>> getModifiedChildren();
+ @NonNull Collection<? extends DataObjectModification<? extends DataObject>> getModifiedChildren();
+
+ /**
+ * Returns child list item modification if {@code child} was modified by this modification. This method should be
+ * used if the child is defined in a grouping brought into a case inside this object.
+ *
+ * @param caseType Case type class
+ * @param childType Type of list item - must be list item with key
+ * @return Modification of {@code child} if {@code child} was modified, null otherwise.
+ * @throws IllegalArgumentException If supplied {@code childType} class is not valid child according
+ * to generated model.
+ */
+ default <H extends ChoiceIn<? super T> & DataObject, C extends ChildOf<? super H>>
+ Collection<DataObjectModification<C>> getModifiedChildren(final @NonNull Class<H> caseType,
+ final @NonNull Class<C> childType) {
+ final Item<C> item = Item.of(caseType, childType);
+ return (Collection<DataObjectModification<C>>) Collections2.filter(getModifiedChildren(),
+ mod -> item.equals(mod.getIdentifier()));
+ }
+
+ /**
+ * Returns container child modification if {@code child} was modified by this modification. This method should be
+ * used if the child is defined in a grouping brought into a case inside this object.
+ *
+ * <p>
+ * For accessing all modified list items consider iterating over {@link #getModifiedChildren()}.
+ *
+ * @param caseType Case type class
+ * @param child Type of child - must be only container
+ * @return Modification of {@code child} if {@code child} was modified, null otherwise.
+ * @throws IllegalArgumentException If supplied {@code child} class is not valid child according
+ * to generated model.
+ */
+ default @Nullable <H extends ChoiceIn<? super T> & DataObject, C extends ChildOf<? super H>>
+ DataObjectModification<C> getModifiedChildContainer(final @NonNull Class<H> caseType,
+ final @NonNull Class<C> child) {
+ return (DataObjectModification<C>) getModifiedChild(Item.of(caseType, child));
+ }
/**
- * Returns container child modification if {@code child} was modified by this
- * modification.
+ * Returns container child modification if {@code child} was modified by this modification.
*
+ * <p>
* For accessing all modified list items consider iterating over {@link #getModifiedChildren()}.
*
* @param child Type of child - must be only container
* @throws IllegalArgumentException If supplied {@code child} class is not valid child according
* to generated model.
*/
- @Nullable <C extends ChildOf<? super T>> DataObjectModification<C> getModifiedChildContainer(@Nonnull Class<C> child);
+ @Nullable <C extends ChildOf<? super T>> DataObjectModification<C> getModifiedChildContainer(
+ @NonNull Class<C> child);
/**
- * Returns augmentation child modification if {@code augmentation} was modified by this
- * modification.
+ * Returns augmentation child modification if {@code augmentation} was modified by this modification.
*
+ * <p>
* For accessing all modified list items consider iterating over {@link #getModifiedChildren()}.
*
* @param augmentation Type of augmentation - must be only container
* @throws IllegalArgumentException If supplied {@code augmentation} class is not valid augmentation
* according to generated model.
*/
- @Nullable <C extends Augmentation<T> & DataObject> DataObjectModification<C> getModifiedAugmentation(@Nonnull Class<C> augmentation);
+ @Nullable <C extends Augmentation<T> & DataObject> DataObjectModification<C> getModifiedAugmentation(
+ @NonNull Class<C> augmentation);
+ /**
+ * Returns child list item modification if {@code child} was modified by this modification.
+ *
+ * @param listItem Type of list item - must be list item with key
+ * @param listKey List item key
+ * @return Modification of {@code child} if {@code child} was modified, null otherwise.
+ * @throws IllegalArgumentException If supplied {@code listItem} class is not valid child according
+ * to generated model.
+ */
+ <N extends Identifiable<K> & ChildOf<? super T>, K extends Identifier<N>> DataObjectModification<N>
+ getModifiedChildListItem(@NonNull Class<N> listItem, @NonNull K listKey);
/**
* Returns child list item modification if {@code child} was modified by this modification.
*
+ * @param caseType Case type class
* @param listItem Type of list item - must be list item with key
* @param listKey List item key
* @return Modification of {@code child} if {@code child} was modified, null otherwise.
* @throws IllegalArgumentException If supplied {@code listItem} class is not valid child according
* to generated model.
*/
- <C extends Identifiable<K> & ChildOf<? super T>, K extends Identifier<C>> DataObjectModification<C> getModifiedChildListItem(
- @Nonnull Class<C> listItem,@Nonnull K listKey);
+ default <H extends ChoiceIn<? super T> & DataObject, C extends Identifiable<K> & ChildOf<? super H>,
+ K extends Identifier<C>> DataObjectModification<C> getModifiedChildListItem(
+ final @NonNull Class<H> caseType, final @NonNull Class<C> listItem, final @NonNull K listKey) {
+ return (DataObjectModification<C>) getModifiedChild(IdentifiableItem.of(caseType, listItem, listKey));
+ }
/**
* Returns a child modification if a node identified by {@code childArgument} was modified by
*
*/
@Nullable DataObjectModification<? extends DataObject> getModifiedChild(PathArgument childArgument);
-
}