Simplify AbstractNodeContainerModificationStrategy 59/89959/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 26 May 2020 11:37:29 +0000 (13:37 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 26 May 2020 12:36:55 +0000 (14:36 +0200)
Since we have NormalizedNodeContainer and we know this type, we
can eliminate a few casts, checks and warning suppressions by
retaining proper type safety.

Change-Id: I6e2d0f9fbb20cfe9fdb996544b8328a18576ca3d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit f29dd56fe28f082931273163b0d80b09a28d1b30)

yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractNodeContainerModificationStrategy.java

index 2d6985a17201ed64020300167ab4a2ad0f1c3af5..2dc1edeca219e75bf12bb1f55ca5bcb22b9ea57b 100644 (file)
@@ -112,16 +112,14 @@ abstract class AbstractNodeContainerModificationStrategy<T extends WithStatus>
     final void verifyValueChildren(final NormalizedNode<?, ?> writtenValue) {
         if (verifyChildrenStructure) {
             final NormalizedNodeContainer<?, ?, ?> container = (NormalizedNodeContainer<?, ?, ?>) writtenValue;
-            for (final Object child : container.getValue()) {
-                checkArgument(child instanceof NormalizedNode);
-                final NormalizedNode<?, ?> castedChild = (NormalizedNode<?, ?>) child;
-                final Optional<ModificationApplyOperation> childOp = getChild(castedChild.getIdentifier());
+            for (final NormalizedNode<?, ?> child : container.getValue()) {
+                final Optional<ModificationApplyOperation> childOp = getChild(child.getIdentifier());
                 if (childOp.isPresent()) {
-                    childOp.get().fullVerifyStructure(castedChild);
+                    childOp.get().fullVerifyStructure(child);
                 } else {
                     throw new SchemaValidationFailedException(String.format(
                             "Node %s is not a valid child of %s according to the schema.",
-                            castedChild.getIdentifier(), container.getIdentifier()));
+                            child.getIdentifier(), container.getIdentifier()));
                 }
             }
 
@@ -153,17 +151,15 @@ abstract class AbstractNodeContainerModificationStrategy<T extends WithStatus>
     @Override
     protected final void recursivelyVerifyStructure(final NormalizedNode<?, ?> value) {
         final NormalizedNodeContainer<?, ?, ?> container = (NormalizedNodeContainer<?, ?, ?>) value;
-        for (final Object child : container.getValue()) {
-            checkArgument(child instanceof NormalizedNode);
-            final NormalizedNode<?, ?> castedChild = (NormalizedNode<?, ?>) child;
-            final Optional<ModificationApplyOperation> childOp = getChild(castedChild.getIdentifier());
+        for (final NormalizedNode<?, ?> child : container.getValue()) {
+            final Optional<ModificationApplyOperation> childOp = getChild(child.getIdentifier());
             if (!childOp.isPresent()) {
                 throw new SchemaValidationFailedException(
                     String.format("Node %s is not a valid child of %s according to the schema.",
-                        castedChild.getIdentifier(), container.getIdentifier()));
+                        child.getIdentifier(), container.getIdentifier()));
             }
 
-            childOp.get().recursivelyVerifyStructure(castedChild);
+            childOp.get().recursivelyVerifyStructure(child);
         }
     }
 
@@ -248,9 +244,7 @@ abstract class AbstractNodeContainerModificationStrategy<T extends WithStatus>
         final NormalizedNode<?, ?> value = modification.getWrittenValue();
 
         Verify.verify(value instanceof NormalizedNodeContainer, "Attempted to merge non-container %s", value);
-        @SuppressWarnings({"unchecked", "rawtypes"})
-        final Collection<NormalizedNode<?, ?>> children = ((NormalizedNodeContainer) value).getValue();
-        for (final NormalizedNode<?, ?> c : children) {
+        for (final NormalizedNode<?, ?> c : ((NormalizedNodeContainer<?, ?, ?>) value).getValue()) {
             final PathArgument id = c.getIdentifier();
             modification.modifyChild(id, resolveChildOperation(id), version);
         }
@@ -258,7 +252,7 @@ abstract class AbstractNodeContainerModificationStrategy<T extends WithStatus>
     }
 
     private void mergeChildrenIntoModification(final ModifiedNode modification,
-            final Collection<NormalizedNode<?, ?>> children, final Version version) {
+            final Collection<? extends NormalizedNode<?, ?>> children, final Version version) {
         for (final NormalizedNode<?, ?> c : children) {
             final ModificationApplyOperation childOp = resolveChildOperation(c.getIdentifier());
             final ModifiedNode childNode = modification.modifyChild(c.getIdentifier(), childOp, version);
@@ -269,8 +263,8 @@ abstract class AbstractNodeContainerModificationStrategy<T extends WithStatus>
     @Override
     final void mergeIntoModifiedNode(final ModifiedNode modification, final NormalizedNode<?, ?> value,
             final Version version) {
-        @SuppressWarnings({ "unchecked", "rawtypes" })
-        final Collection<NormalizedNode<?, ?>> children = ((NormalizedNodeContainer)value).getValue();
+        final Collection<? extends NormalizedNode<?, ?>> children =
+                ((NormalizedNodeContainer<?, ?, ?>)value).getValue();
 
         switch (modification.getOperation()) {
             case NONE: