From adcf2e2e80c6a05ea5e43be15dc7a2576fd2bbb4 Mon Sep 17 00:00:00 2001 From: Ahmed Ashour Date: Fri, 29 Sep 2017 14:14:05 +0200 Subject: Use enhanced for loop instead of Iterator. (#10100) --- uitest/src/main/java/com/vaadin/tests/TestBench.java | 19 ++++--------------- .../vaadin/tests/components/accordion/RemoveTabs.java | 11 +++-------- .../tests/components/composite/CompositeChainUI.java | 7 +++---- .../vaadin/tests/components/tabsheet/RemoveTabs.java | 11 +++-------- .../FragmentHandlingAndAsynchUIUpdate.java | 6 +----- 5 files changed, 14 insertions(+), 40 deletions(-) (limited to 'uitest') diff --git a/uitest/src/main/java/com/vaadin/tests/TestBench.java b/uitest/src/main/java/com/vaadin/tests/TestBench.java index 388a113768..2c5634ab32 100644 --- a/uitest/src/main/java/com/vaadin/tests/TestBench.java +++ b/uitest/src/main/java/com/vaadin/tests/TestBench.java @@ -21,7 +21,6 @@ import java.net.URL; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Set; @@ -138,9 +137,7 @@ public class TestBench extends com.vaadin.server.LegacyApplication // try to find a proper test class // exact match - Iterator iterator = menu.getItemIds().iterator(); - while (iterator.hasNext()) { - Object next = iterator.next(); + for (Object next : menu.getItemIds()) { if (next instanceof Class) { Class c = (Class) next; String string = c.getName(); @@ -153,9 +150,7 @@ public class TestBench extends com.vaadin.server.LegacyApplication } // simple name match - iterator = menu.getItemIds().iterator(); - while (iterator.hasNext()) { - Object next = iterator.next(); + for (Object next : menu.getItemIds()) { if (next instanceof Class) { Class c = (Class) next; String string = c.getSimpleName(); @@ -167,9 +162,7 @@ public class TestBench extends com.vaadin.server.LegacyApplication } } // ticket match - iterator = menu.getItemIds().iterator(); - while (iterator.hasNext()) { - Object next = iterator.next(); + for (Object next : menu.getItemIds()) { if (next instanceof Class) { Class c = (Class) next; String string = c.getSimpleName(); @@ -183,9 +176,7 @@ public class TestBench extends com.vaadin.server.LegacyApplication } // just partly mach lowercase - iterator = menu.getItemIds().iterator(); - while (iterator.hasNext()) { - Object next = iterator.next(); + for (Object next : menu.getItemIds()) { if (next instanceof Class) { Class c = (Class) next; String string = c.getSimpleName(); @@ -200,9 +191,7 @@ public class TestBench extends com.vaadin.server.LegacyApplication getMainWindow().showNotification( "No potential matc for #" + fragment); - } - } }); diff --git a/uitest/src/main/java/com/vaadin/tests/components/accordion/RemoveTabs.java b/uitest/src/main/java/com/vaadin/tests/components/accordion/RemoveTabs.java index 7ca7185500..c86d1b2682 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/accordion/RemoveTabs.java +++ b/uitest/src/main/java/com/vaadin/tests/components/accordion/RemoveTabs.java @@ -1,7 +1,6 @@ package com.vaadin.tests.components.accordion; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import com.vaadin.tests.components.TestBase; @@ -96,11 +95,9 @@ public class RemoveTabs extends TestBase { } private void closeLastTab() { - Iterator i = accordion.iterator(); Component last = null; - while (i.hasNext()) { - last = i.next(); - + for (Component c : accordion) { + last = c; } accordion.removeComponent(last); } @@ -110,9 +107,7 @@ public class RemoveTabs extends TestBase { if (container != null) { List c = new ArrayList<>(); - Iterator i = container.iterator(); - while (i.hasNext()) { - Component comp = i.next(); + for (Component comp : container) { c.add(comp); } container.removeAllComponents(); diff --git a/uitest/src/main/java/com/vaadin/tests/components/composite/CompositeChainUI.java b/uitest/src/main/java/com/vaadin/tests/components/composite/CompositeChainUI.java index 481f7c958f..bfb3bf0bfc 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/composite/CompositeChainUI.java +++ b/uitest/src/main/java/com/vaadin/tests/components/composite/CompositeChainUI.java @@ -82,10 +82,9 @@ public class CompositeChainUI extends AbstractTestUIWithLog { String msg = component.getClass().getSimpleName(); if (component instanceof HasComponents) { - Iterator iterator = ((HasComponents) component) - .iterator(); - if (iterator.hasNext()) { - Component content = iterator.next(); + Iterator it = ((HasComponents) component).iterator(); + if (it.hasNext()) { + Component content = it.next(); if (content != null) { msg += " -> " + getHierarchy(content); } diff --git a/uitest/src/main/java/com/vaadin/tests/components/tabsheet/RemoveTabs.java b/uitest/src/main/java/com/vaadin/tests/components/tabsheet/RemoveTabs.java index 3dd2d0cd0a..4a04ff669c 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tabsheet/RemoveTabs.java +++ b/uitest/src/main/java/com/vaadin/tests/components/tabsheet/RemoveTabs.java @@ -1,7 +1,6 @@ package com.vaadin.tests.components.tabsheet; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import com.vaadin.tests.components.TestBase; @@ -120,11 +119,9 @@ public class RemoveTabs extends TestBase { } private void closeLastTab() { - Iterator i = tabsheet.getComponentIterator(); Component last = null; - while (i.hasNext()) { - last = i.next(); - + for (Component c : tabsheet) { + last = c; } tabsheet.removeComponent(last); } @@ -134,9 +131,7 @@ public class RemoveTabs extends TestBase { if (container != null) { List c = new ArrayList<>(); - Iterator i = container.getComponentIterator(); - while (i.hasNext()) { - Component comp = i.next(); + for (Component comp : container) { c.add(comp); } container.removeAllComponents(); diff --git a/uitest/src/main/java/com/vaadin/tests/urifragments/FragmentHandlingAndAsynchUIUpdate.java b/uitest/src/main/java/com/vaadin/tests/urifragments/FragmentHandlingAndAsynchUIUpdate.java index b808a3d973..bdc021868d 100644 --- a/uitest/src/main/java/com/vaadin/tests/urifragments/FragmentHandlingAndAsynchUIUpdate.java +++ b/uitest/src/main/java/com/vaadin/tests/urifragments/FragmentHandlingAndAsynchUIUpdate.java @@ -1,7 +1,5 @@ package com.vaadin.tests.urifragments; -import java.util.Iterator; - import com.vaadin.server.Page; import com.vaadin.server.Page.UriFragmentChangedEvent; import com.vaadin.server.Page.UriFragmentChangedListener; @@ -62,12 +60,10 @@ public class FragmentHandlingAndAsynchUIUpdate extends AbstractTestUIWithLog { return; } - Iterator it = getLayout().iterator(); final String frag = event.getUriFragment().substring(4); Component fragComp = null; - while (it.hasNext()) { - Component comp = it.next(); + for (Component comp : getLayout()) { if (comp.getId() != null && comp instanceof Label && comp.getId().equals(frag)) { fragComp = comp; -- cgit v1.2.3