Added type-safe DataObjectModification#getModifiedChildren 52/27352/5
authorTony Tkacik <ttkacik@cisco.com>
Wed, 23 Sep 2015 13:00:14 +0000 (15:00 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Sat, 26 Sep 2015 06:30:37 +0000 (06:30 +0000)
Change-Id: I0489a1dd41c825f74f9fc1f9c8af38ab8c5d8830
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/DataObjectModification.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/LazyDataObjectModification.java

index f902bb3922c0131e140be7a95ccf6129805ca4dc..26e9f40c1cb3a631028f577c0c131e1d66b26f59 100644 (file)
@@ -21,11 +21,17 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
 /**
  * Modified Data Object.
  *
- * Represents modification of Data Object.
+ * Represents modification of Data Object
+ * .
+ * @param <T> Type of modified object
  *
  */
 public interface DataObjectModification<T extends DataObject> extends org.opendaylight.yangtools.concepts.Identifiable<PathArgument> {
 
+    /**
+     * Represents type of modification which has occured.
+     *
+     */
     enum ModificationType {
         /**
          *
@@ -69,7 +75,7 @@ public interface DataObjectModification<T extends DataObject> extends org.openda
      * Returns before-state of top level container. Implementations are encouraged, but not required
      * to provide this state.
      *
-     * 
+     *
      * @return State of object before modification. Null if subtree was not present, or the
      *         implementation cannot provide the state.
      */
@@ -89,6 +95,16 @@ public interface DataObjectModification<T extends DataObject> extends org.openda
      */
     @Nonnull Collection<DataObjectModification<? extends DataObject>> getModifiedChildren();
 
+    /**
+     * Returns child list item modification if {@code child} was modified by this modification.
+     *
+     * @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.
+     */
+    <C extends ChildOf<? super T>> Collection<DataObjectModification<C>> getModifiedChildren(@Nonnull Class<C> childType);
+
     /**
      * Returns container child modification if {@code child} was modified by this
      * modification.
index e7046162c4ba1724a701e96b1a79ab82349c3a9e..14b76522f6be0e1397e87a22d141bafd76fa5f48 100644 (file)
@@ -7,14 +7,13 @@
  */
 package org.opendaylight.mdsal.binding.dom.adapter;
 
-import org.opendaylight.mdsal.binding.api.DataObjectModification;
-
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
+import org.opendaylight.mdsal.binding.api.DataObjectModification;
 import org.opendaylight.yangtools.binding.data.codec.api.BindingCodecTreeNode;
 import org.opendaylight.yangtools.yang.binding.Augmentation;
 import org.opendaylight.yangtools.yang.binding.ChildOf;
@@ -162,6 +161,18 @@ final class LazyDataObjectModification<T extends DataObject> implements DataObje
         return childNodesCache;
     }
 
+    @SuppressWarnings("unchecked")
+    @Override
+    public <C extends ChildOf<? super T>> Collection<DataObjectModification<C>> getModifiedChildren(Class<C> childType) {
+        List<DataObjectModification<C>> children = new ArrayList<>();
+        for (DataObjectModification<? extends DataObject> potential : getModifiedChildren()) {
+            if (childType.isAssignableFrom(potential.getDataType())) {
+                children.add((DataObjectModification<C>) potential);
+            }
+        }
+        return children;
+    }
+
     @Override
     public DataObjectModification<? extends DataObject> getModifiedChild(final PathArgument arg) {
         final List<YangInstanceIdentifier.PathArgument> domArgumentList = new ArrayList<>();