X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fbinding%2Fapi%2FDataObjectModification.java;h=c9df98bf040731ee7d85888e052bf1b1f89eb201;hp=3dc6e4030f56953620ab8762ecae7c32d4ffbd74;hb=aaea3e9a92ae9d6fac04c4a065db4b35cbca9ed0;hpb=a54ec60368110d22794602343c934902f6833c65 diff --git a/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/DataObjectModification.java b/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/DataObjectModification.java index 3dc6e4030f..c9df98bf04 100644 --- a/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/DataObjectModification.java +++ b/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/DataObjectModification.java @@ -3,43 +3,47 @@ * * 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 extends org.opendaylight.yangtools.concepts.Identifiable { +@Deprecated(forRemoval = true) +public interface DataObjectModification + extends org.opendaylight.yangtools.concepts.Identifiable { enum ModificationType { /** - * * Child node (direct or indirect) was modified. * */ SUBTREE_MODIFIED, + /** - * * Node was explicitly created / overwritten. * */ + WRITE, /** - * * Node was deleted. * */ @@ -54,21 +58,19 @@ public interface DataObjectModification extends org.openda * * @return type of modified object. */ - @Nonnull Class getDataType(); + @NonNull Class 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. */ @@ -77,7 +79,6 @@ public interface DataObjectModification extends org.openda /** * 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(); @@ -87,12 +88,49 @@ public interface DataObjectModification extends org.openda * * @return unmodifiable collection of modified direct children. */ - @Nonnull Collection> getModifiedChildren(); + @NonNull Collection> 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 & DataObject, C extends ChildOf> + Collection> getModifiedChildren(final @NonNull Class caseType, + final @NonNull Class childType) { + final Item item = Item.of(caseType, childType); + return (Collection>) 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. + * + *

+ * 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 & DataObject, C extends ChildOf> + DataObjectModification getModifiedChildContainer(final @NonNull Class caseType, + final @NonNull Class child) { + return (DataObjectModification) 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. * + *

* For accessing all modified list items consider iterating over {@link #getModifiedChildren()}. * * @param child Type of child - must be only container @@ -100,12 +138,13 @@ public interface DataObjectModification extends org.openda * @throws IllegalArgumentException If supplied {@code child} class is not valid child according * to generated model. */ - @Nullable > DataObjectModification getModifiedChildContainer(@Nonnull Class child); + @Nullable > DataObjectModification getModifiedChildContainer( + @NonNull Class 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. * + *

* For accessing all modified list items consider iterating over {@link #getModifiedChildren()}. * * @param augmentation Type of augmentation - must be only container @@ -113,20 +152,36 @@ public interface DataObjectModification extends org.openda * @throws IllegalArgumentException If supplied {@code augmentation} class is not valid augmentation * according to generated model. */ - @Nullable & DataObject> DataObjectModification getModifiedAugmentation(@Nonnull Class augmentation); + @Nullable & DataObject> DataObjectModification getModifiedAugmentation( + @NonNull Class 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. + */ + & ChildOf, K extends Identifier> DataObjectModification + getModifiedChildListItem(@NonNull Class 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. */ - & ChildOf, K extends Identifier> DataObjectModification getModifiedChildListItem( - @Nonnull Class listItem,@Nonnull K listKey); + default & DataObject, C extends Identifiable & ChildOf, + K extends Identifier> DataObjectModification getModifiedChildListItem( + final @NonNull Class caseType, final @NonNull Class listItem, final @NonNull K listKey) { + return (DataObjectModification) getModifiedChild(IdentifiableItem.of(caseType, listItem, listKey)); + } /** * Returns a child modification if a node identified by {@code childArgument} was modified by @@ -140,5 +195,4 @@ public interface DataObjectModification extends org.openda * */ @Nullable DataObjectModification getModifiedChild(PathArgument childArgument); - }