From 7e4b4ff5a9e9eca6810d473a4d7681a61c9a89ce Mon Sep 17 00:00:00 2001 From: Ahmed Ashour Date: Mon, 2 Oct 2017 11:43:19 +0200 Subject: Use enhanced for loop for arrays. (#10121) --- .../main/java/com/vaadin/event/EventRouter.java | 11 ++++--- .../main/java/com/vaadin/event/ListenerMethod.java | 34 +++++++++------------- 2 files changed, 19 insertions(+), 26 deletions(-) (limited to 'server/src/main/java/com/vaadin/event') diff --git a/server/src/main/java/com/vaadin/event/EventRouter.java b/server/src/main/java/com/vaadin/event/EventRouter.java index f5c04b2de1..59599a0aac 100644 --- a/server/src/main/java/com/vaadin/event/EventRouter.java +++ b/server/src/main/java/com/vaadin/event/EventRouter.java @@ -132,9 +132,9 @@ public class EventRouter implements MethodEventSource { // Find the correct method final Method[] methods = target.getClass().getMethods(); Method method = null; - for (int i = 0; i < methods.length; i++) { - if (methods[i].getName().equals(methodName)) { - method = methods[i]; + for (Method m : methods) { + if (m.getName().equals(methodName)) { + method = m; } } if (method == null) { @@ -197,9 +197,8 @@ public class EventRouter implements MethodEventSource { // Send the event to all listeners. The listeners themselves // will filter out unwanted events. - final Object[] listeners = listenerList.toArray(); - for (int i = 0; i < listeners.length; i++) { - ListenerMethod listenerMethod = (ListenerMethod) listeners[i]; + for (Object l : listenerList.toArray()) { + ListenerMethod listenerMethod = (ListenerMethod) l; if (null != errorHandler) { try { listenerMethod.receiveEvent(event); diff --git a/server/src/main/java/com/vaadin/event/ListenerMethod.java b/server/src/main/java/com/vaadin/event/ListenerMethod.java index c631bbec14..9159f7f781 100644 --- a/server/src/main/java/com/vaadin/event/ListenerMethod.java +++ b/server/src/main/java/com/vaadin/event/ListenerMethod.java @@ -120,9 +120,8 @@ public class ListenerMethod implements EventListener, Serializable { private static Method findHighestMethod(Class cls, String method, Class[] paramTypes) { Class[] ifaces = cls.getInterfaces(); - for (int i = 0; i < ifaces.length; i++) { - Method ifaceMethod = findHighestMethod(ifaces[i], method, - paramTypes); + for (Class c : ifaces) { + Method ifaceMethod = findHighestMethod(c, method, paramTypes); if (ifaceMethod != null) { return ifaceMethod; } @@ -134,11 +133,10 @@ public class ListenerMethod implements EventListener, Serializable { return parentMethod; } } - Method[] methods = cls.getMethods(); - for (int i = 0; i < methods.length; i++) { + for (Method m : cls.getMethods()) { // we ignore parameter types for now - you need to add this - if (methods[i].getName().equals(method)) { - return methods[i]; + if (m.getName().equals(method)) { + return m; } } return null; @@ -245,11 +243,10 @@ public class ListenerMethod implements EventListener, Serializable { throws IllegalArgumentException { // Finds the correct method - final Method[] methods = target.getClass().getMethods(); Method method = null; - for (int i = 0; i < methods.length; i++) { - if (methods[i].getName().equals(methodName)) { - method = methods[i]; + for (Method m : target.getClass().getMethods()) { + if (m.getName().equals(methodName)) { + method = m; } } if (method == null) { @@ -355,11 +352,9 @@ public class ListenerMethod implements EventListener, Serializable { Object[] arguments) throws IllegalArgumentException { // Find the correct method - final Method[] methods = target.getClass().getMethods(); - Method method = null; - for (int i = 0; i < methods.length; i++) { - if (methods[i].getName().equals(methodName)) { - method = methods[i]; + for (Method m : target.getClass().getMethods()) { + if (m.getName().equals(methodName)) { + method = m; } } if (method == null) { @@ -456,11 +451,10 @@ public class ListenerMethod implements EventListener, Serializable { throws IllegalArgumentException { // Finds the correct method - final Method[] methods = target.getClass().getMethods(); Method method = null; - for (int i = 0; i < methods.length; i++) { - if (methods[i].getName().equals(methodName)) { - method = methods[i]; + for (Method m : target.getClass().getMethods()) { + if (m.getName().equals(methodName)) { + method = m; } } if (method == null) { -- cgit v1.2.3