aboutsummaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorAhmed Ashour <asashour@yahoo.com>2017-09-19 09:41:48 +0200
committerHenri Sara <henri.sara@gmail.com>2017-09-19 10:41:47 +0300
commit4a8195b59ef07c62a22e2f51cf49f1f2f9657638 (patch)
tree666b0eeacc411882af466eb15a5f5f59c47fe31b /uitest
parent7425cef7bfbffc6cf7ba1f2142157c94273268a9 (diff)
downloadvaadin-framework-4a8195b59ef07c62a22e2f51cf49f1f2f9657638.tar.gz
vaadin-framework-4a8195b59ef07c62a22e2f51cf49f1f2f9657638.zip
Replace iterators with enhanced for loops (#10018)
This change also includes some other minor cleanup.
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/ListenerOrder.java6
-rw-r--r--uitest/src/main/java/com/vaadin/tests/Parameters.java7
-rw-r--r--uitest/src/main/java/com/vaadin/tests/TestBench.java26
-rw-r--r--uitest/src/main/java/com/vaadin/tests/TestForMultipleStyleNames.java11
-rw-r--r--uitest/src/main/java/com/vaadin/tests/TestSizeableIncomponents.java4
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/treetable/TreeTableTest.java3
-rw-r--r--uitest/src/main/java/com/vaadin/tests/dd/TreeDragStart.java4
-rw-r--r--uitest/src/main/java/com/vaadin/tests/integration/JSR286Portlet.java6
-rw-r--r--uitest/src/main/java/com/vaadin/tests/themes/valo/ValoThemeUI.java9
-rw-r--r--uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeHorizontalResize.java4
-rw-r--r--uitest/src/main/java/com/vaadin/v7/tests/components/tree/Trees.java3
11 files changed, 32 insertions, 51 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/ListenerOrder.java b/uitest/src/main/java/com/vaadin/tests/ListenerOrder.java
index c4fe9a2a65..6baa1b364b 100644
--- a/uitest/src/main/java/com/vaadin/tests/ListenerOrder.java
+++ b/uitest/src/main/java/com/vaadin/tests/ListenerOrder.java
@@ -89,10 +89,8 @@ public class ListenerOrder extends com.vaadin.server.LegacyApplication
s1.addListener((ValueChangeListener) this);
Item i = s1.getItem("second");
- for (Iterator<?> it = i.getItemPropertyIds().iterator(); it
- .hasNext();) {
- Object o = it.next();
- System.out.println("[" + o + "]");
+ for (Object id : i.getItemPropertyIds()) {
+ System.out.println("[" + id + "]");
}
}
diff --git a/uitest/src/main/java/com/vaadin/tests/Parameters.java b/uitest/src/main/java/com/vaadin/tests/Parameters.java
index d59c717b75..bb38110bcc 100644
--- a/uitest/src/main/java/com/vaadin/tests/Parameters.java
+++ b/uitest/src/main/java/com/vaadin/tests/Parameters.java
@@ -114,10 +114,9 @@ public class Parameters extends com.vaadin.server.LegacyApplication
params.removeAllItems();
Map<String, String[]> parameters = request.getParameterMap();
- for (final Iterator<String> i = parameters.keySet().iterator(); i
- .hasNext();) {
- final String name = i.next();
- final String[] values = parameters.get(name);
+ for (final Map.Entry<String, String[]> entry : parameters.entrySet()) {
+ final String name = entry.getKey();
+ final String[] values = entry.getValue();
String v = "";
for (int j = 0; j < values.length; j++) {
if (v.length() > 0) {
diff --git a/uitest/src/main/java/com/vaadin/tests/TestBench.java b/uitest/src/main/java/com/vaadin/tests/TestBench.java
index d66f58e539..076d02b4be 100644
--- a/uitest/src/main/java/com/vaadin/tests/TestBench.java
+++ b/uitest/src/main/java/com/vaadin/tests/TestBench.java
@@ -20,9 +20,10 @@ import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
-import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import com.vaadin.server.ExternalResource;
import com.vaadin.server.LegacyApplication;
@@ -69,8 +70,7 @@ public class TestBench extends com.vaadin.server.LegacyApplication
VerticalLayout bodyLayout = new VerticalLayout();
- // TODO this could probably be a simple Set
- HashMap<Class<?>, String> itemCaptions = new HashMap<>();
+ Set<Class<?>> itemCaptions = new HashSet<>();
@Override
public void init() {
@@ -81,23 +81,21 @@ public class TestBench extends com.vaadin.server.LegacyApplication
try {
final List<Class<?>> testableClasses = getTestableClassesForPackage(
testablePackages[p]);
- for (final Iterator<Class<?>> it = testableClasses
- .iterator(); it.hasNext();) {
- final Class<?> t = it.next();
+ for (final Class<?> t : testableClasses) {
// ignore TestBench itself
if (t.equals(TestBench.class)) {
continue;
}
try {
testables.addItem(t);
- itemCaptions.put(t, t.getName());
+ itemCaptions.add(t);
testables.setParent(t, testablePackages[p]);
testables.setChildrenAllowed(t, false);
continue;
} catch (final Exception e) {
try {
testables.addItem(t);
- itemCaptions.put(t, t.getName());
+ itemCaptions.add(t);
testables.setParent(t, testablePackages[p]);
testables.setChildrenAllowed(t, false);
continue;
@@ -113,18 +111,15 @@ public class TestBench extends com.vaadin.server.LegacyApplication
menu = new Tree("Testables", testables);
- for (final Iterator<Class<?>> i = itemCaptions.keySet().iterator(); i
- .hasNext();) {
- final Class<?> testable = i.next();
+ for (final Class<?> testable : itemCaptions) {
// simplify captions
final String name = testable.getName()
.substring(testable.getName().lastIndexOf('.') + 1);
menu.setItemCaption(testable, name);
}
// expand all root items
- for (final Iterator<?> i = menu.rootItemIds().iterator(); i
- .hasNext();) {
- menu.expandItemsRecursively(i.next());
+ for (final Object id : menu.rootItemIds()) {
+ menu.expandItemsRecursively(id);
}
menu.addListener(this);
@@ -302,8 +297,7 @@ public class TestBench extends com.vaadin.server.LegacyApplication
final ArrayList<Class<?>> classes = new ArrayList<>();
// For every directory identified capture all the .class files
- for (final Iterator<File> it = directories.iterator(); it.hasNext();) {
- final File directory = it.next();
+ for (final File directory : directories) {
if (directory.exists()) {
// Get the list of the files contained in the package
final String[] files = directory.list();
diff --git a/uitest/src/main/java/com/vaadin/tests/TestForMultipleStyleNames.java b/uitest/src/main/java/com/vaadin/tests/TestForMultipleStyleNames.java
index b7c4885c17..b4b933ecde 100644
--- a/uitest/src/main/java/com/vaadin/tests/TestForMultipleStyleNames.java
+++ b/uitest/src/main/java/com/vaadin/tests/TestForMultipleStyleNames.java
@@ -77,6 +77,7 @@ public class TestForMultipleStyleNames extends CustomComponent
}
+ @SuppressWarnings("unchecked")
@Override
public void valueChange(ValueChangeEvent event) {
@@ -89,11 +90,9 @@ public class TestForMultipleStyleNames extends CustomComponent
}
}
- final Collection<?> styles = (Collection<?>) s.getValue();
+ final Collection<String> styles = (Collection<String>) s.getValue();
- for (final Iterator<?> iterator = styles.iterator(); iterator
- .hasNext();) {
- final String styleName = (String) iterator.next();
+ for (final String styleName : styles) {
if (curStyles.contains(styleName)) {
// already added
curStyles.remove(styleName);
@@ -101,9 +100,7 @@ public class TestForMultipleStyleNames extends CustomComponent
l.addStyleName(styleName);
}
}
- for (final Iterator<String> iterator2 = curStyles.iterator(); iterator2
- .hasNext();) {
- final String object = iterator2.next();
+ for (final String object : curStyles) {
l.removeStyleName(object);
}
}
diff --git a/uitest/src/main/java/com/vaadin/tests/TestSizeableIncomponents.java b/uitest/src/main/java/com/vaadin/tests/TestSizeableIncomponents.java
index 584a952885..40e7f82014 100644
--- a/uitest/src/main/java/com/vaadin/tests/TestSizeableIncomponents.java
+++ b/uitest/src/main/java/com/vaadin/tests/TestSizeableIncomponents.java
@@ -303,9 +303,7 @@ public class TestSizeableIncomponents extends LegacyApplication {
((Label) c).setValue("Test label");
}
- for (Iterator<Configuration> i = configurations.iterator(); i
- .hasNext();) {
- Configuration conf = i.next();
+ for (Configuration conf : configurations) {
conf.configure(c);
}
return c;
diff --git a/uitest/src/main/java/com/vaadin/tests/components/treetable/TreeTableTest.java b/uitest/src/main/java/com/vaadin/tests/components/treetable/TreeTableTest.java
index e8903ed92f..c6e4749a98 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/treetable/TreeTableTest.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/treetable/TreeTableTest.java
@@ -65,8 +65,7 @@ public class TreeTableTest extends Tables<TreeTable>
Hierarchical c = getComponent().getContainerDataSource();
int idx = 0;
- for (Iterator<?> i = c.getItemIds().iterator(); i.hasNext();) {
- Object id = i.next();
+ for (Object id : c.getItemIds()) {
if (id == itemId) {
if (idx % 2 == 1) {
return "bold";
diff --git a/uitest/src/main/java/com/vaadin/tests/dd/TreeDragStart.java b/uitest/src/main/java/com/vaadin/tests/dd/TreeDragStart.java
index 3c21c90475..0709e5d888 100644
--- a/uitest/src/main/java/com/vaadin/tests/dd/TreeDragStart.java
+++ b/uitest/src/main/java/com/vaadin/tests/dd/TreeDragStart.java
@@ -57,8 +57,8 @@ public class TreeDragStart extends TestBase {
getLayout().addComponent(tree);
// Expand all items
- for (Iterator<?> it = tree.rootItemIds().iterator(); it.hasNext();) {
- tree.expandItemsRecursively(it.next());
+ for (Object id : tree.rootItemIds()) {
+ tree.expandItemsRecursively(id);
}
// Set the tree in drag source mode
diff --git a/uitest/src/main/java/com/vaadin/tests/integration/JSR286Portlet.java b/uitest/src/main/java/com/vaadin/tests/integration/JSR286Portlet.java
index 5abb63cb63..b06fb68ef8 100644
--- a/uitest/src/main/java/com/vaadin/tests/integration/JSR286Portlet.java
+++ b/uitest/src/main/java/com/vaadin/tests/integration/JSR286Portlet.java
@@ -147,9 +147,9 @@ public class JSR286Portlet extends UI {
.getAttribute(PortletRequest.USER_INFO);
if (uinfo != null) {
String s = "";
- for (Iterator<?> it = uinfo.keySet().iterator(); it.hasNext();) {
- Object key = it.next();
- Object val = uinfo.get(key);
+ for (Map.Entry<?, ?> entry : uinfo.entrySet()) {
+ Object key = entry.getKey();
+ Object val = entry.getValue();
s += key + ": " + val + "\n";
}
if (request.isUserInRole("administrator")) {
diff --git a/uitest/src/main/java/com/vaadin/tests/themes/valo/ValoThemeUI.java b/uitest/src/main/java/com/vaadin/tests/themes/valo/ValoThemeUI.java
index 1268a5cbde..4ec83dc6ec 100644
--- a/uitest/src/main/java/com/vaadin/tests/themes/valo/ValoThemeUI.java
+++ b/uitest/src/main/java/com/vaadin/tests/themes/valo/ValoThemeUI.java
@@ -146,15 +146,12 @@ public class ValoThemeUI extends UI {
@Override
public void afterViewChange(ViewChangeEvent event) {
- for (Iterator<Component> it = menuItemsLayout.iterator(); it
- .hasNext();) {
- it.next().removeStyleName("selected");
+ for (Component c : menuItemsLayout) {
+ c.removeStyleName("selected");
}
for (Entry<String, String> item : menuItems.entrySet()) {
if (event.getViewName().equals(item.getKey())) {
- for (Iterator<Component> it = menuItemsLayout
- .iterator(); it.hasNext();) {
- Component c = it.next();
+ for (Component c : menuItemsLayout) {
if (c.getCaption() != null && c.getCaption()
.startsWith(item.getValue())) {
c.addStyleName("selected");
diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeHorizontalResize.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeHorizontalResize.java
index cb948b789e..1606a40272 100644
--- a/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeHorizontalResize.java
+++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeHorizontalResize.java
@@ -35,8 +35,8 @@ public class TreeHorizontalResize extends TestBase {
Tree tree = new Tree();
tree.setContainerDataSource(getHardwareContainer());
tree.setItemCaptionPropertyId(hw_PROPERTY_NAME);
- for (Iterator<?> it = tree.rootItemIds().iterator(); it.hasNext();) {
- tree.expandItemsRecursively(it.next());
+ for (Object id : tree.rootItemIds()) {
+ tree.expandItemsRecursively(id);
}
treeLayout.addComponent(tree);
}
diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/tree/Trees.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/Trees.java
index b53c125be3..17e63bea4a 100644
--- a/uitest/src/main/java/com/vaadin/v7/tests/components/tree/Trees.java
+++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/Trees.java
@@ -57,8 +57,7 @@ public class Trees extends AbstractSelectTestCase<Tree>
.getContainerDataSource();
int idx = 0;
- for (Iterator<?> i = c.getItemIds().iterator(); i.hasNext();) {
- Object id = i.next();
+ for (Object id : c.getItemIds()) {
if (id == itemId) {
if (idx % 2 == 1) {
return "bold";