From 910e4be3bda009d0f5b2fac8eb7fd8c13d6fdea0 Mon Sep 17 00:00:00 2001 From: Sasha Date: Fri, 19 Apr 2013 16:11:55 +0100 Subject: [PATCH] simplify loops --- webservices/compbio/ws/client/CmdHelper.java | 30 +++++++++++--------------- webservices/compbio/ws/client/IOHelper.java | 4 ++-- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/webservices/compbio/ws/client/CmdHelper.java b/webservices/compbio/ws/client/CmdHelper.java index 509abcc..1175230 100644 --- a/webservices/compbio/ws/client/CmdHelper.java +++ b/webservices/compbio/ws/client/CmdHelper.java @@ -27,7 +27,6 @@ import static compbio.ws.client.Constraints.servicekey; import static compbio.ws.client.Constraints.testKey; class CmdHelper { - /** * Check whether presetList is set in the command line * @@ -80,9 +79,9 @@ class CmdHelper { static boolean keyFound(String[] cmd, String key) { assert cmd != null && cmd.length > 0; assert key != null; - for (int i = 0; i < cmd.length; i++) { - String listPresets = cmd[i]; - if (listPresets.trim().equalsIgnoreCase(key)) { + + for (String c : cmd) { + if (c.trim().equalsIgnoreCase(key)) { return true; } } @@ -98,11 +97,9 @@ class CmdHelper { */ static String getPresetName(String[] cmd) { String preset = null; - for (int i = 0; i < cmd.length; i++) { - String presetPrm = cmd[i]; - if (presetPrm.trim().toLowerCase() - .startsWith(presetkey + pseparator)) { - preset = presetPrm.substring(presetPrm.indexOf(pseparator) + 1); + for (String c : cmd) { + if (c.trim().toLowerCase().startsWith(presetkey + pseparator)) { + preset = c.substring(c.indexOf(pseparator) + 1); break; } } @@ -117,10 +114,9 @@ class CmdHelper { * @return service name or null if it is not defined */ public static String getServiceName(String[] cmd) { - for (int i = 0; i < cmd.length; i++) { - String serv = cmd[i]; - if (serv.trim().toLowerCase().startsWith(servicekey + pseparator)) { - return serv.substring(serv.indexOf(pseparator) + 1); + for (String c : cmd) { + if (c.trim().toLowerCase().startsWith(servicekey + pseparator)) { + return c.substring(c.indexOf(pseparator) + 1); } } return null; @@ -134,10 +130,9 @@ class CmdHelper { * @return host name or null if it is not defined */ public static String getHost(String[] cmd) { - for (int i = 0; i < cmd.length; i++) { - String host = cmd[i]; - if (host.trim().toLowerCase().startsWith(hostkey + pseparator)) { - return host.substring(host.indexOf(pseparator) + 1); + for (String c : cmd) { + if (c.trim().toLowerCase().startsWith(hostkey + pseparator)) { + return c.substring(c.indexOf(pseparator) + 1); } } return null; @@ -153,5 +148,4 @@ class CmdHelper { static boolean listParameters(String[] cmd) { return keyFound(cmd, paramList); } - } diff --git a/webservices/compbio/ws/client/IOHelper.java b/webservices/compbio/ws/client/IOHelper.java index 290e0e1..3e4b726 100644 --- a/webservices/compbio/ws/client/IOHelper.java +++ b/webservices/compbio/ws/client/IOHelper.java @@ -46,8 +46,8 @@ public class IOHelper { static File getFile(String[] cmd, String key, boolean mustExist) throws IOException { assert key != null && key.trim().length() != 0; - for (int i = 0; i < cmd.length; i++) { - String filename = cmd[i]; + for (String c : cmd) { + String filename = c; filename = filename.trim(); if (filename.toLowerCase().startsWith(key + pseparator)) { filename = filename.substring((key + pseparator).length()); -- 1.7.10.2