From dfb1d56b71b3e5891635d887043a415b8b0295d6 Mon Sep 17 00:00:00 2001 From: rbuj Date: Sat, 26 Jul 2014 12:16:50 +0200 Subject: [PATCH] jurt: Enhanced For-Loops Change-Id: I74a9b8afd1e4a1364c61c7b85277909f38611f6d Reviewed-on: https://gerrit.libreoffice.org/10553 Reviewed-by: David Tardon Tested-by: David Tardon --- .../comp/servicemanager/ServiceManager.java | 34 +++++++++---------- .../lib/connections/pipe/PipeConnection.java | 14 ++------ .../connections/socket/SocketConnection.java | 13 ++----- 3 files changed, 23 insertions(+), 38 deletions(-) diff --git a/jurt/com/sun/star/comp/servicemanager/ServiceManager.java b/jurt/com/sun/star/comp/servicemanager/ServiceManager.java index 8def4ac72eb3..4a4a4e6f05e6 100644 --- a/jurt/com/sun/star/comp/servicemanager/ServiceManager.java +++ b/jurt/com/sun/star/comp/servicemanager/ServiceManager.java @@ -296,10 +296,7 @@ public class ServiceManager implements XMultiServiceFactory, throws com.sun.star.uno.RuntimeException { if (eventListener != null) { - java.util.Iterator enumer = eventListener.iterator(); - - while (enumer.hasNext()) { - XEventListener listener = enumer.next(); + for (XEventListener listener : eventListener) { listener.disposing(new com.sun.star.lang.EventObject(this)); } eventListener.clear(); @@ -468,16 +465,17 @@ public class ServiceManager implements XMultiServiceFactory, String[] serviceNames = xServiceInfo.getSupportedServiceNames(); - for ( int i=0; i vec = factoriesByServiceNames.get(serviceNames[i]); - - if ( !vec.remove(object) ) + for (String serviceName : serviceNames) { + if (factoriesByServiceNames.containsKey(serviceName)) { + ArrayList vec = factoriesByServiceNames.get(serviceName); + if (!vec.remove(object)) { System.err.println("The implementation " + xServiceInfo.getImplementationName() + - " is not registered for the service " + serviceNames[i] + " - ignoring!"); - - if ( vec.isEmpty() ) // remove the vector if no implementations aviable for the service - factoriesByServiceNames.remove( serviceNames[i] ); + " is not registered for the service " + serviceName + " - ignoring!"); + } + // remove the vector if no implementations aviable for the service + if (vec.isEmpty()) { + factoriesByServiceNames.remove(serviceName); + } } } } @@ -565,12 +563,14 @@ public class ServiceManager implements XMultiServiceFactory, public boolean supportsService( String serviceName ) throws com.sun.star.uno.RuntimeException { - for (int i=0; i elements = _aListeners.iterator(); - while(elements.hasNext()) { - XStreamListener xStreamListener = elements.next(); + for (XStreamListener xStreamListener : _aListeners) { xStreamListener.started(); } } private void notifyListeners_close() { - Iterator elements = _aListeners.iterator(); - while(elements.hasNext()) { - XStreamListener xStreamListener = elements.next(); + for (XStreamListener xStreamListener : _aListeners) { xStreamListener.closed(); } } private void notifyListeners_error(com.sun.star.uno.Exception exception) { - Iterator elements = _aListeners.iterator(); - while(elements.hasNext()) { - XStreamListener xStreamListener = elements.next(); + for (XStreamListener xStreamListener : _aListeners) { xStreamListener.error(exception); } } @@ -215,4 +208,3 @@ public class PipeConnection implements XConnection, XConnectionBroadcaster { } } - diff --git a/jurt/com/sun/star/lib/connections/socket/SocketConnection.java b/jurt/com/sun/star/lib/connections/socket/SocketConnection.java index e849d8b387e9..f7ad9119a4c1 100644 --- a/jurt/com/sun/star/lib/connections/socket/SocketConnection.java +++ b/jurt/com/sun/star/lib/connections/socket/SocketConnection.java @@ -25,7 +25,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.Socket; import java.util.ArrayList; -import java.util.Iterator; import com.sun.star.connection.XConnection; import com.sun.star.connection.XConnectionBroadcaster; @@ -89,25 +88,19 @@ public class SocketConnection implements XConnection, XConnectionBroadcaster { } private void notifyListeners_open() { - Iterator elements = _listeners.iterator(); - while(elements.hasNext()) { - XStreamListener xStreamListener = elements.next(); + for (XStreamListener xStreamListener : _listeners) { xStreamListener.started(); } } private void notifyListeners_close() { - Iterator elements = _listeners.iterator(); - while(elements.hasNext()) { - XStreamListener xStreamListener = elements.next(); + for (XStreamListener xStreamListener : _listeners) { xStreamListener.closed(); } } private void notifyListeners_error(com.sun.star.uno.Exception exception) { - Iterator elements = _listeners.iterator(); - while(elements.hasNext()) { - XStreamListener xStreamListener = elements.next(); + for (XStreamListener xStreamListener : _listeners) { xStreamListener.error(exception); } }