diff options
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/JNLPFile.java | 4 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/PluginBridge.java | 4 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/ResourcesDesc.java | 17 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/cache/CacheUtil.java | 31 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java | 8 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/cache/Resource.java | 3 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/cache/ResourceTracker.java | 37 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/runtime/AppletEnvironment.java | 4 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java | 7 | ||||
-rw-r--r-- | plugin/icedteanp/java/netscape/javascript/JSObject.java | 11 | ||||
-rw-r--r-- | plugin/icedteanp/java/sun/applet/JavaConsole.java | 4 | ||||
-rw-r--r-- | plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java | 4 | ||||
-rw-r--r-- | plugin/icedteanp/java/sun/applet/PluginAppletViewer.java | 22 |
14 files changed, 94 insertions, 80 deletions
@@ -1,3 +1,21 @@ +2012-05-25 Adam Domurad <[email protected]> + + Changed for-loops over iterators and indices to for-each loops if they + were sufficient and clearer. + * netx/net/sourceforge/jnlp/JNLPFile.java: Changed for-loops that could + be expressed more clearly as for-each loops. + * netx/net/sourceforge/jnlp/PluginBridge.java: Same + * netx/net/sourceforge/jnlp/ResourcesDesc.java: Same + * netx/net/sourceforge/jnlp/cache/CacheUtil.java: Same + * netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java: Same + * netx/net/sourceforge/jnlp/cache/Resource.java: Same + * netx/net/sourceforge/jnlp/cache/ResourceTracker.java: Same + * netx/net/sourceforge/jnlp/runtime/AppletEnvironment.java: Same + * netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java: Same + * plugin/icedteanp/java/netscape/javascript/JSObject.java: Same + * plugin/icedteanp/java/sun/applet/JavaConsole.java: Same + * plugin/icedteanp/java/sun/applet/PluginAppletViewer.java: Same + 2012-05-23 Adam Domurad <[email protected]> Removed instances of snprintf where buffer size was not known. Added buffer size constant for allocating buffers for numeric conversions. diff --git a/netx/net/sourceforge/jnlp/JNLPFile.java b/netx/net/sourceforge/jnlp/JNLPFile.java index 5ddb989..41354d3 100644 --- a/netx/net/sourceforge/jnlp/JNLPFile.java +++ b/netx/net/sourceforge/jnlp/JNLPFile.java @@ -396,9 +396,7 @@ public class JNLPFile { public <T> List<T> getResources(Class<T> launchType) { List<T> result = new ArrayList<T>(); - for (int i = 0; i < resources.size(); i++) { - ResourcesDesc rescDesc = resources.get(i); - + for (ResourcesDesc rescDesc : resources) { if (localMatches(locale, rescDesc.getLocales()) && stringMatches(os, rescDesc.getOS()) && stringMatches(arch, rescDesc.getArch())) diff --git a/netx/net/sourceforge/jnlp/PluginBridge.java b/netx/net/sourceforge/jnlp/PluginBridge.java index 2146e64..273b213 100644 --- a/netx/net/sourceforge/jnlp/PluginBridge.java +++ b/netx/net/sourceforge/jnlp/PluginBridge.java @@ -204,9 +204,7 @@ public class PluginBridge extends JNLPFile { List<JARDesc> jarDescs = new ArrayList<JARDesc>(); jarDescs.addAll(sharedResources.getResources(JARDesc.class)); - Iterator<String> it = jars.iterator(); - while(it.hasNext()) { - String name = it.next(); + for (String name : jars) { if (name.length() > 0) jarDescs.add(new JARDesc(new URL(codeBase, name), null, null, false, true, false, true)); diff --git a/netx/net/sourceforge/jnlp/ResourcesDesc.java b/netx/net/sourceforge/jnlp/ResourcesDesc.java index 4c861b5..42eec01 100644 --- a/netx/net/sourceforge/jnlp/ResourcesDesc.java +++ b/netx/net/sourceforge/jnlp/ResourcesDesc.java @@ -75,9 +75,10 @@ public class ResourcesDesc { public JARDesc getMainJAR() { JARDesc jars[] = getJARs(); - for (int i = 0; i < jars.length; i++) - if (jars[i].isMain()) - return jars[i]; + for (JARDesc jar : jars) { + if (jar.isMain()) + return jar; + } if (jars.length > 0) return jars[0]; @@ -160,8 +161,7 @@ public class ResourcesDesc { public Map<String, String> getPropertiesMap() { Map<String, String> properties = new HashMap<String, String>(); List<PropertyDesc> resources = getResources(PropertyDesc.class); - for (int i = 0; i < resources.size(); i++) { - PropertyDesc prop = resources.get(i); + for (PropertyDesc prop : resources) { properties.put(prop.getKey(), prop.getValue()); } @@ -205,9 +205,10 @@ public class ResourcesDesc { public <T> List<T> getResources(Class<T> type) { List<T> result = new ArrayList<T>(); - for (int i = 0; i < resources.size(); i++) - if (type.isAssignableFrom(resources.get(i).getClass())) - result.add(type.cast(resources.get(i))); + for (Object resource : resources) { + if (type.isAssignableFrom(resource.getClass())) + result.add(type.cast(resource)); + } return result; } diff --git a/netx/net/sourceforge/jnlp/cache/CacheUtil.java b/netx/net/sourceforge/jnlp/cache/CacheUtil.java index ec65094..b918625 100644 --- a/netx/net/sourceforge/jnlp/cache/CacheUtil.java +++ b/netx/net/sourceforge/jnlp/cache/CacheUtil.java @@ -500,9 +500,9 @@ public class CacheUtil { // only resources not starting out downloaded are displayed List<URL> urlList = new ArrayList<URL>(); - for (int i = 0; i < resources.length; i++) { - if (!tracker.checkResource(resources[i])) - urlList.add(resources[i]); + for (URL url : resources) { + if (!tracker.checkResource(url)) + urlList.add(url); } URL undownloaded[] = urlList.toArray(new URL[urlList.size()]); @@ -512,28 +512,29 @@ public class CacheUtil { long read = 0; long total = 0; - for (int i = 0; i < undownloaded.length; i++) { + for (URL url : undownloaded) { // add in any -1's; they're insignificant - total += tracker.getTotalSize(undownloaded[i]); - read += tracker.getAmountRead(undownloaded[i]); + total += tracker.getTotalSize(url); + read += tracker.getAmountRead(url); } int percent = (int) ((100 * read) / Math.max(1, total)); - for (int i = 0; i < undownloaded.length; i++) - listener.progress(undownloaded[i], "version", - tracker.getAmountRead(undownloaded[i]), - tracker.getTotalSize(undownloaded[i]), + for (URL url : undownloaded) { + listener.progress(url, "version", + tracker.getAmountRead(url), + tracker.getTotalSize(url), percent); + } } while (!tracker.waitForResources(resources, indicator.getUpdateRate())); // make sure they read 100% until indicator closes - for (int i = 0; i < undownloaded.length; i++) - listener.progress(undownloaded[i], "version", - tracker.getTotalSize(undownloaded[i]), - tracker.getTotalSize(undownloaded[i]), + for (URL url : undownloaded) { + listener.progress(url, "version", + tracker.getTotalSize(url), + tracker.getTotalSize(url), 100); - + } } catch (InterruptedException ex) { if (JNLPRuntime.isDebug()) ex.printStackTrace(); diff --git a/netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java b/netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java index 8710a6a..915a9ff 100644 --- a/netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java +++ b/netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java @@ -106,9 +106,11 @@ public class DefaultDownloadIndicator implements DownloadIndicator { frame.getContentPane().setLayout(new GridBagLayout()); } - if (resources != null) - for (int i = 0; i < resources.length; i++) - result.addProgressPanel(resources[i], null); + if (resources != null) { + for (URL url : resources) { + result.addProgressPanel(url, null); + } + } frame.getContentPane().add(result, vertical); frame.pack(); diff --git a/netx/net/sourceforge/jnlp/cache/Resource.java b/netx/net/sourceforge/jnlp/cache/Resource.java index 1c4cb0f..00d411b 100644 --- a/netx/net/sourceforge/jnlp/cache/Resource.java +++ b/netx/net/sourceforge/jnlp/cache/Resource.java @@ -272,8 +272,7 @@ public class Resource { send = trackers.hardList(); } - for (int i = 0; i < send.size(); i++) { - ResourceTracker rt = send.get(i); + for (ResourceTracker rt : send) { rt.fireDownloadEvent(this); } } diff --git a/netx/net/sourceforge/jnlp/cache/ResourceTracker.java b/netx/net/sourceforge/jnlp/cache/ResourceTracker.java index bc46947..0050757 100644 --- a/netx/net/sourceforge/jnlp/cache/ResourceTracker.java +++ b/netx/net/sourceforge/jnlp/cache/ResourceTracker.java @@ -331,13 +331,13 @@ public class ResourceTracker { } DownloadEvent event = new DownloadEvent(this, resource); - for (int i = 0; i < l.length; i++) { + for (DownloadListener dl : l) { if (0 != ((ERROR | DOWNLOADED) & status)) - l[i].downloadCompleted(event); + dl.downloadCompleted(event); else if (0 != (DOWNLOADING & status)) - l[i].downloadStarted(event); + dl.downloadStarted(event); else if (0 != (CONNECTING & status)) - l[i].updateStarted(event); + dl.updateStarted(event); } } @@ -449,8 +449,9 @@ public class ResourceTracker { synchronized (resources) { // keep the lock so getResource doesn't have to aquire it each time - for (int i = 0; i < urls.length; i++) + for (int i = 0; i < urls.length; i++) { resources[i] = getResource(urls[i]); + } } if (resources.length > 0) @@ -868,8 +869,7 @@ public class ResourceTracker { resource.toString() + " : " + urls); } URL bestUrl = null; - for (int i = 0; i < urls.size(); i++) { - URL url = urls.get(i); + for (URL url : urls) { try { URLConnection connection = url.openConnection(); connection.addRequestProperty("Accept-Encoding", "pack200-gzip, gzip"); @@ -999,8 +999,7 @@ public class ResourceTracker { Resource result = null; int score = Integer.MAX_VALUE; - for (int i = 0; i < source.size(); i++) { - Resource resource = source.get(i); + for (Resource resource : source) { boolean selectable = false; synchronized (resource) { @@ -1011,9 +1010,10 @@ public class ResourceTracker { if (selectable) { int activeCount = 0; - for (int j = 0; j < active.size(); j++) - if (active.get(j) == resource.getTracker()) + for (ResourceTracker rt : active) { + if (rt == resource.getTracker()) activeCount++; + } // try to spread out the downloads so that a slow host // won't monopolize the downloads @@ -1034,9 +1034,7 @@ public class ResourceTracker { */ private Resource getResource(URL location) { synchronized (resources) { - for (int i = 0; i < resources.size(); i++) { - Resource resource = resources.get(i); - + for (Resource resource : resources) { if (CacheUtil.urlEquals(resource.location, location)) return resource; } @@ -1058,8 +1056,9 @@ public class ResourceTracker { long startTime = System.currentTimeMillis(); // start them downloading / connecting in background - for (int i = 0; i < resources.length; i++) - startResource(resources[i]); + for (Resource resource : resources) { + startResource(resource); + } // wait for completion while (true) { @@ -1067,11 +1066,11 @@ public class ResourceTracker { synchronized (lock) { // check for completion - for (int i = 0; i < resources.length; i++) { + for (Resource resource : resources) { //NetX Deadlocking may be solved by removing this //synch block. - synchronized (resources[i]) { - if (!resources[i].isSet(DOWNLOADED | ERROR)) { + synchronized (resource) { + if (!resource.isSet(DOWNLOADED | ERROR)) { finished = false; break; } diff --git a/netx/net/sourceforge/jnlp/runtime/AppletEnvironment.java b/netx/net/sourceforge/jnlp/runtime/AppletEnvironment.java index 321e18e..03ab465 100644 --- a/netx/net/sourceforge/jnlp/runtime/AppletEnvironment.java +++ b/netx/net/sourceforge/jnlp/runtime/AppletEnvironment.java @@ -116,8 +116,8 @@ public class AppletEnvironment implements AppletContext, AppletStub { destroyed = true; List<AppletAudioClip> clips = weakClips.hardList(); - for (int i = 0; i < clips.size(); i++) { - clips.get(i).dispose(); + for (AppletAudioClip clip : clips) { + clip.dispose(); } } diff --git a/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java b/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java index 320228a..fc7c1b7 100644 --- a/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java +++ b/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java @@ -231,8 +231,8 @@ public class ApplicationInstance { PrivilegedAction<Object> installProps = new PrivilegedAction<Object>() { public Object run() { - for (int i = 0; i < props.length; i++) { - System.setProperty(props[i].getKey(), props[i].getValue()); + for (PropertyDesc propDesc : props) { + System.setProperty(propDesc.getKey(), propDesc.getValue()); } return null; @@ -272,8 +272,7 @@ public class ApplicationInstance { try { // destroy resources - for (int i = 0; i < weakWindows.size(); i++) { - Window w = weakWindows.get(i); + for (Window w : weakWindows) { if (w != null) w.dispose(); } diff --git a/plugin/icedteanp/java/netscape/javascript/JSObject.java b/plugin/icedteanp/java/netscape/javascript/JSObject.java index a2f200f..0de500f 100644 --- a/plugin/icedteanp/java/netscape/javascript/JSObject.java +++ b/plugin/icedteanp/java/netscape/javascript/JSObject.java @@ -130,9 +130,9 @@ public final class JSObject { StackTraceElement[] stack = Thread.currentThread().getStackTrace(); boolean mayProceed = false; - for (int i = 0; i < stack.length; i++) { - if (stack[i].getClassName().equals("netscape.javascript.JSObject") && - stack[i].getMethodName().equals("getWindow")) { + for (StackTraceElement element : stack) { + if (element.getClassName().equals("netscape.javascript.JSObject") && + element.getMethodName().equals("getWindow")) { mayProceed = true; } } @@ -209,8 +209,9 @@ public final class JSObject { args = new Object[0]; PluginDebug.debug("JSObject.call ", methodName); - for (int i = 0; i < args.length; i++) - PluginDebug.debug(" ", args[i]); + for (Object arg : args) { + PluginDebug.debug(" ", arg); + } PluginDebug.debug(""); return PluginAppletViewer.call(internal, methodName, args); } diff --git a/plugin/icedteanp/java/sun/applet/JavaConsole.java b/plugin/icedteanp/java/sun/applet/JavaConsole.java index e3af966..9074e1b 100644 --- a/plugin/icedteanp/java/sun/applet/JavaConsole.java +++ b/plugin/icedteanp/java/sun/applet/JavaConsole.java @@ -308,8 +308,8 @@ public class JavaConsole { boolean toShowConsole = false; - for (int i = 0; i < args.length; i++) { - if (args[i] == "--show-console") { + for (String arg : args) { + if ("--show-console".equals(arg)) { toShowConsole = true; } } diff --git a/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java b/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java index 402fa99..733c644 100644 --- a/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java +++ b/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java @@ -1295,9 +1295,7 @@ public class PluginAppletSecurityContext { Permissions grantedPermissions = new Permissions(); - for (int i = 0; i < nsPrivilegeList.length; i++) { - String privilege = nsPrivilegeList[i]; - + for (String privilege : nsPrivilegeList) { if (privilege.equals("UniversalBrowserRead")) { BrowserReadPermission bp = new BrowserReadPermission(); grantedPermissions.add(bp); diff --git a/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java b/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java index 6f4f2eb..35997bb 100644 --- a/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java +++ b/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java @@ -237,27 +237,27 @@ class PluginAppletPanelFactory { // ","-separated list. No error-checking will be done on the list. String[] events = eventList.split(","); - for (int i = 0; i < events.length; i++) { - PluginDebug.debug("Adding event to queue: ", events[i]); - if (events[i].equals("dispose")) + for (String event : events) { + PluginDebug.debug("Adding event to queue: ", event); + if ("dispose".equals(event)) panel.sendEvent(AppletPanel.APPLET_DISPOSE); - else if (events[i].equals("load")) + else if ("load".equals(event)) panel.sendEvent(AppletPanel.APPLET_LOAD); - else if (events[i].equals("init")) + else if ("init".equals(event)) panel.sendEvent(AppletPanel.APPLET_INIT); - else if (events[i].equals("start")) + else if ("start".equals(event)) panel.sendEvent(AppletPanel.APPLET_START); - else if (events[i].equals("stop")) + else if ("stop".equals(event)) panel.sendEvent(AppletPanel.APPLET_STOP); - else if (events[i].equals("destroy")) + else if ("destroy".equals(event)) panel.sendEvent(AppletPanel.APPLET_DESTROY); - else if (events[i].equals("quit")) + else if ("quit".equals(event)) panel.sendEvent(AppletPanel.APPLET_QUIT); - else if (events[i].equals("error")) + else if ("error".equals(event)) panel.sendEvent(AppletPanel.APPLET_ERROR); else // non-fatal error if we get an unrecognized event - PluginDebug.debug("Unrecognized event name: ", events[i]); + PluginDebug.debug("Unrecognized event name: ", event); } while (!panel.emptyEventQueue()) |