diff options
author | Ahmed Ashour <asashour@yahoo.com> | 2017-09-29 14:14:05 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-09-29 15:14:05 +0300 |
commit | adcf2e2e80c6a05ea5e43be15dc7a2576fd2bbb4 (patch) | |
tree | 0a58b0b09cb371f757d74f83ad872f2113f96272 /client | |
parent | 46950473fdb3cfb9d44660b3a642a9229cecded2 (diff) | |
download | vaadin-framework-adcf2e2e80c6a05ea5e43be15dc7a2576fd2bbb4.tar.gz vaadin-framework-adcf2e2e80c6a05ea5e43be15dc7a2576fd2bbb4.zip |
Use enhanced for loop instead of Iterator. (#10100)
Diffstat (limited to 'client')
6 files changed, 26 insertions, 40 deletions
diff --git a/client/src/main/java/com/vaadin/client/componentlocator/LegacyLocatorStrategy.java b/client/src/main/java/com/vaadin/client/componentlocator/LegacyLocatorStrategy.java index 76360eb40d..d2c818f2f5 100644 --- a/client/src/main/java/com/vaadin/client/componentlocator/LegacyLocatorStrategy.java +++ b/client/src/main/java/com/vaadin/client/componentlocator/LegacyLocatorStrategy.java @@ -16,7 +16,6 @@ package com.vaadin.client.componentlocator; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import com.google.gwt.core.client.JavaScriptObject; @@ -470,10 +469,8 @@ public class LegacyLocatorStrategy implements LocatorStrategy { return null; } - Iterator<?> i = ((Iterable<?>) parent).iterator(); int pos = 0; - while (i.hasNext()) { - Object child = i.next(); + for (Object child : (Iterable<?>) parent) { if (child == w) { return basePath + PARENTCHILD_SEPARATOR + simpleName + "[" + pos + "]"; @@ -638,7 +635,7 @@ public class LegacyLocatorStrategy implements LocatorStrategy { } // Locate the child - Iterator<? extends Widget> iterator; + Iterable<? extends Widget> iterable; /* * VWindow and VContextMenu workarounds for backwards @@ -652,19 +649,18 @@ public class LegacyLocatorStrategy implements LocatorStrategy { for (WindowConnector wc : windows) { windowWidgets.add(wc.getWidget()); } - iterator = windowWidgets.iterator(); + iterable = windowWidgets; } else if (widgetClassName.equals("VContextMenu")) { return client.getContextMenu(); } else { - iterator = (Iterator<? extends Widget>) parent.iterator(); + iterable = (Iterable<? extends Widget>) parent; } boolean ok = false; // Find the widgetPosition:th child of type "widgetClassName" - while (iterator.hasNext()) { + for (Widget child : iterable) { - Widget child = iterator.next(); String simpleName2 = Util.getSimpleName(child); if (!widgetClassName.equals(simpleName2) diff --git a/client/src/main/java/com/vaadin/client/debug/internal/HierarchyPanel.java b/client/src/main/java/com/vaadin/client/debug/internal/HierarchyPanel.java index e70da1188c..1172704ba0 100644 --- a/client/src/main/java/com/vaadin/client/debug/internal/HierarchyPanel.java +++ b/client/src/main/java/com/vaadin/client/debug/internal/HierarchyPanel.java @@ -16,7 +16,6 @@ package com.vaadin.client.debug.internal; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import com.google.gwt.event.dom.client.ClickEvent; @@ -50,9 +49,8 @@ public class HierarchyPanel extends FlowPanel { public void update() { // Try to keep track of currently open nodes and reopen them FastStringSet openNodes = FastStringSet.create(); - Iterator<Widget> it = iterator(); - while (it.hasNext()) { - collectOpenNodes(it.next(), openNodes); + for (Widget widget : this) { + collectOpenNodes(widget, openNodes); } clear(); @@ -90,9 +88,8 @@ public class HierarchyPanel extends FlowPanel { } } if (widget instanceof HasWidgets) { - Iterator<Widget> it = ((HasWidgets) widget).iterator(); - while (it.hasNext()) { - collectOpenNodes(it.next(), openNodes); + for (Widget child : (HasWidgets) widget) { + collectOpenNodes(child, openNodes); } } } diff --git a/client/src/main/java/com/vaadin/client/ui/ShortcutActionHandler.java b/client/src/main/java/com/vaadin/client/ui/ShortcutActionHandler.java index d85643099c..26d3fd7be0 100644 --- a/client/src/main/java/com/vaadin/client/ui/ShortcutActionHandler.java +++ b/client/src/main/java/com/vaadin/client/ui/ShortcutActionHandler.java @@ -18,7 +18,6 @@ package com.vaadin.client.ui; import java.util.ArrayList; import java.util.Iterator; -import java.util.List; import com.google.gwt.core.client.Scheduler; import com.google.gwt.dom.client.Element; @@ -59,7 +58,7 @@ public class ShortcutActionHandler { ShortcutActionHandler getShortcutActionHandler(); } - private final List<ShortcutAction> actions = new ArrayList<>(); + private final ArrayList<ShortcutAction> actions = new ArrayList<>(); private ApplicationConnection client; private String paintableId; @@ -101,17 +100,15 @@ public class ShortcutActionHandler { public void handleKeyboardEvent(final Event event, ComponentConnector target) { - final int modifiers = KeyboardListenerCollection - .getKeyboardModifiers(event); final char keyCode = (char) DOM.eventGetKeyCode(event); if (keyCode == 0) { return; } + final int modifiers = KeyboardListenerCollection + .getKeyboardModifiers(event); final ShortcutKeyCombination kc = new ShortcutKeyCombination(keyCode, modifiers); - final Iterator<ShortcutAction> it = actions.iterator(); - while (it.hasNext()) { - final ShortcutAction a = it.next(); + for (final ShortcutAction a : actions) { if (a.getShortcutCombination().equals(kc)) { fireAction(event, a, target); break; diff --git a/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java b/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java index b1e5843125..da5d320c8d 100644 --- a/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java +++ b/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java @@ -17,7 +17,6 @@ package com.vaadin.client.ui; import java.util.Date; -import java.util.Iterator; import java.util.List; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -530,7 +529,8 @@ public abstract class VAbstractCalendarPanel<R extends Enum<R>> updateControlButtonRangeStyles(needsMonth); final String monthName = needsMonth - ? getDateTimeService().getMonth(displayedMonth.getMonth()) : ""; + ? getDateTimeService().getMonth(displayedMonth.getMonth()) + : ""; final int year = displayedMonth.getYear() + 1900; getFlexCellFormatter().setStyleName(0, 2, @@ -1485,8 +1485,8 @@ public abstract class VAbstractCalendarPanel<R extends Enum<R>> /** * Returns the reset key which will reset the calendar to the previous - * selection. By default this is backspace but it can be overridden to change - * the key to whatever you want. + * selection. By default this is backspace but it can be overridden to + * change the key to whatever you want. * * @return */ @@ -1926,9 +1926,7 @@ public abstract class VAbstractCalendarPanel<R extends Enum<R>> .parseInt(subPart.substring(SUBPART_DAY.length())); Date date = new Date(displayedMonth.getYear(), displayedMonth.getMonth(), dayOfMonth); - Iterator<Widget> iter = days.iterator(); - while (iter.hasNext()) { - Widget w = iter.next(); + for (Widget w : days) { if (w instanceof VAbstractCalendarPanel.Day) { Day day = (Day) w; if (day.getDate().equals(date)) { @@ -1994,7 +1992,8 @@ public abstract class VAbstractCalendarPanel<R extends Enum<R>> private void setLabel() { if (getDateField() instanceof VAbstractPopupCalendar) { - ((VAbstractPopupCalendar<?, ?>) getDateField()).setFocusedDate(this); + ((VAbstractPopupCalendar<?, ?>) getDateField()) + .setFocusedDate(this); } } } diff --git a/client/src/main/java/com/vaadin/client/ui/VComboBox.java b/client/src/main/java/com/vaadin/client/ui/VComboBox.java index 9ae8115d8b..69d9e39529 100644 --- a/client/src/main/java/com/vaadin/client/ui/VComboBox.java +++ b/client/src/main/java/com/vaadin/client/ui/VComboBox.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Set; @@ -1089,10 +1088,8 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, } clearItems(); - final Iterator<ComboBoxSuggestion> it = suggestions.iterator(); boolean isFirstIteration = true; - while (it.hasNext()) { - final ComboBoxSuggestion suggestion = it.next(); + for (final ComboBoxSuggestion suggestion : suggestions) { final MenuItem mi = new MenuItem(suggestion.getDisplayString(), true, suggestion); String style = suggestion.getStyle(); diff --git a/client/src/main/java/com/vaadin/client/widgets/ChildFocusAwareFlowPanel.java b/client/src/main/java/com/vaadin/client/widgets/ChildFocusAwareFlowPanel.java index 19ee7b8a21..0d430f8c7f 100644 --- a/client/src/main/java/com/vaadin/client/widgets/ChildFocusAwareFlowPanel.java +++ b/client/src/main/java/com/vaadin/client/widgets/ChildFocusAwareFlowPanel.java @@ -144,11 +144,11 @@ public class ChildFocusAwareFlowPanel extends FocusableFlowPanel @Override public void focus() { - Iterator<Widget> iterator = iterator(); - if (iterator.hasNext()) { - Widget widget = iterator.next(); - if (widget instanceof Focusable) { - ((Focusable) widget).setFocus(true); + Iterator<Widget> it = iterator(); + if (it.hasNext()) { + Widget child = it.next(); + if (child instanceof Focusable) { + ((Focusable) child).setFocus(true); } } } |