Use foreach loops 81/57081/3
authorStephen Kitt <skitt@redhat.com>
Mon, 15 May 2017 15:54:41 +0000 (17:54 +0200)
committerTom Pantelis <tompantelis@gmail.com>
Fri, 15 Sep 2017 16:14:36 +0000 (16:14 +0000)
This automatically-generated patch replaces while loops with their
foreach equivalent.

Change-Id: I26a2bf48c7c3337414a69ed852449a1757526076
Signed-off-by: Stephen Kitt <skitt@redhat.com>
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMWriteTransactionAdapter.java
opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizer.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendTransaction.java

index 88c8bf5..c0a7154 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.controller.md.sal.binding.impl;
 
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
@@ -22,6 +21,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 
 import com.google.common.util.concurrent.CheckedFuture;
@@ -52,16 +52,14 @@ class BindingDOMWriteTransactionAdapter<T extends DOMDataWriteTransaction> exten
             final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier normalizedPath, final InstanceIdentifier<?> path) {
         List<PathArgument> currentArguments = new ArrayList<>();
         DataNormalizationOperation<?> currentOp = getCodec().getDataNormalizer().getRootOperation();
-        Iterator<PathArgument> iterator = normalizedPath.getPathArguments().iterator();
-        while (iterator.hasNext()) {
-            PathArgument currentArg = iterator.next();
+        for (PathArgument currentArg : normalizedPath.getPathArguments()) {
             try {
                 currentOp = currentOp.getChild(currentArg);
             } catch (DataNormalizationException e) {
                 throw new IllegalArgumentException(String.format("Invalid child encountered in path %s", path), e);
             }
             currentArguments.add(currentArg);
-            org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier currentPath = org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.create(
+            YangInstanceIdentifier currentPath = YangInstanceIdentifier.create(
                     currentArguments);
 
             getDelegate().merge(store, currentPath, currentOp.createDefault(currentArg));
index 9876a57..10f53f0 100644 (file)
@@ -56,10 +56,9 @@ public class DataNormalizer {
 
     public DataNormalizationOperation<?> getOperation(final YangInstanceIdentifier legacy) throws DataNormalizationException {
         DataNormalizationOperation<?> currentOp = operation;
-        Iterator<PathArgument> arguments = legacy.getPathArguments().iterator();
 
-        while (arguments.hasNext()) {
-            currentOp = currentOp.getChild(arguments.next());
+        for (PathArgument pathArgument : legacy.getPathArguments()) {
+            currentOp = currentOp.getChild(pathArgument);
         }
         return currentOp;
     }
index 2a4aeaa..b25e5da 100644 (file)
@@ -11,7 +11,7 @@ import com.google.common.base.MoreObjects;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Verify;
 import java.util.ArrayDeque;
-import java.util.Iterator;
+import java.util.Optional;
 import java.util.Queue;
 import javax.annotation.Nullable;
 import javax.annotation.concurrent.NotThreadSafe;
@@ -95,16 +95,14 @@ abstract class FrontendTransaction implements Identifiable<TransactionIdentifier
         // machinery is asynchronous, hence a reply may be in the works and not available.
 
         long replaySequence = firstReplaySequence;
-        final Iterator<?> it = replayQueue.iterator();
-        while (it.hasNext()) {
-            final Object replay = it.next();
+        for (Object replay : replayQueue) {
             if (replaySequence == sequence) {
                 if (replay instanceof RequestException) {
                     throw (RequestException) replay;
                 }
 
                 Verify.verify(replay instanceof TransactionSuccess);
-                return java.util.Optional.of((TransactionSuccess<?>) replay);
+                return Optional.of((TransactionSuccess<?>) replay);
             }
 
             replaySequence++;

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.