Simplify AbstractNodeContainerModificationStrategy
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / AbstractNodeContainerModificationStrategy.java
index c4d8afbdc94f91fde1fe08e42cd417773494f925..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,23 +151,21 @@ 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);
         }
     }
 
     @Override
     protected TreeNode applyWrite(final ModifiedNode modification, final NormalizedNode<?, ?> newValue,
-            final Optional<TreeNode> currentMeta, final Version version) {
+            final Optional<? extends TreeNode> currentMeta, final Version version) {
         final TreeNode newValueMeta = TreeNodeFactory.createTreeNode(newValue, version);
 
         if (modification.getChildren().isEmpty()) {
@@ -221,9 +217,9 @@ abstract class AbstractNodeContainerModificationStrategy<T extends WithStatus>
 
         for (final ModifiedNode mod : modifications) {
             final PathArgument id = mod.getIdentifier();
-            final Optional<TreeNode> cm = meta.getChild(id);
+            final Optional<? extends TreeNode> cm = meta.getChild(id);
 
-            final Optional<TreeNode> result = resolveChildOperation(id).apply(mod, cm, nodeVersion);
+            final Optional<? extends TreeNode> result = resolveChildOperation(id).apply(mod, cm, nodeVersion);
             if (result.isPresent()) {
                 final TreeNode tn = result.get();
                 meta.addChild(tn);
@@ -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:
@@ -302,7 +296,7 @@ abstract class AbstractNodeContainerModificationStrategy<T extends WithStatus>
                 // and then append any child entries.
                 if (!modification.getChildren().isEmpty()) {
                     // Version does not matter here as we'll throw it out
-                    final Optional<TreeNode> current = apply(modification, modification.getOriginal(),
+                    final Optional<? extends TreeNode> current = apply(modification, modification.getOriginal(),
                         Version.initial());
                     if (current.isPresent()) {
                         modification.updateValue(LogicalOperation.WRITE, current.get().getData());
@@ -364,7 +358,7 @@ abstract class AbstractNodeContainerModificationStrategy<T extends WithStatus>
 
     @Override
     protected final void checkTouchApplicable(final ModificationPath path, final NodeModification modification,
-            final Optional<TreeNode> current, final Version version) throws DataValidationFailedException {
+            final Optional<? extends TreeNode> current, final Version version) throws DataValidationFailedException {
         final TreeNode currentNode;
         if (!current.isPresent()) {
             currentNode = defaultTreeNode();
@@ -402,7 +396,7 @@ abstract class AbstractNodeContainerModificationStrategy<T extends WithStatus>
 
     @Override
     protected final void checkMergeApplicable(final ModificationPath path, final NodeModification modification,
-            final Optional<TreeNode> current, final Version version) throws DataValidationFailedException {
+            final Optional<? extends TreeNode> current, final Version version) throws DataValidationFailedException {
         if (current.isPresent()) {
             checkChildPreconditions(path, modification, current.get(), version);
         }
@@ -419,7 +413,7 @@ abstract class AbstractNodeContainerModificationStrategy<T extends WithStatus>
             final TreeNode current, final Version version) throws DataValidationFailedException {
         for (final NodeModification childMod : modification.getChildren()) {
             final PathArgument childId = childMod.getIdentifier();
-            final Optional<TreeNode> childMeta = current.getChild(childId);
+            final Optional<? extends TreeNode> childMeta = current.getChild(childId);
 
             path.push(childId);
             try {