--- /dev/null
+package compbio.ws.client;\r
+import static compbio.ws.client.Constraints.hostkey;\r
+import static compbio.ws.client.Constraints.limitList;\r
+import static compbio.ws.client.Constraints.paramList;\r
+import static compbio.ws.client.Constraints.presetList;\r
+import static compbio.ws.client.Constraints.presetkey;\r
+import static compbio.ws.client.Constraints.pseparator;\r
+import static compbio.ws.client.Constraints.servicekey;\r
+\r
+class CmdHelper {\r
+\r
+ /**\r
+ * Check whether presetList is set in the command line\r
+ * \r
+ * @param cmd\r
+ * command line options\r
+ * @return true if presetList is found, false otherwise\r
+ */\r
+ static boolean listPresets(String[] cmd) {\r
+ return keyFound(cmd, presetList);\r
+ }\r
+\r
+ /**\r
+ * Checks whether limitList parameter is in the command line\r
+ * \r
+ * @param cmd\r
+ * - command line options\r
+ * @return true if it is, false otherwise\r
+ */\r
+ static boolean listLimits(String[] cmd) {\r
+ return keyFound(cmd, limitList);\r
+ }\r
+\r
+ /**\r
+ * Checks whether the key is in the command line\r
+ * \r
+ * @param cmd\r
+ * @param key\r
+ * @return true if it is, false otherwise\r
+ */\r
+ static boolean keyFound(String[] cmd, String key) {\r
+ assert cmd != null && cmd.length > 0;\r
+ assert key != null;\r
+ for (int i = 0; i < cmd.length; i++) {\r
+ String listPresets = cmd[i];\r
+ if (listPresets.trim().equalsIgnoreCase(key)) {\r
+ return true;\r
+ }\r
+ }\r
+ return false;\r
+ }\r
+\r
+ /**\r
+ * Extracts preset name from the command line is any\r
+ * \r
+ * @param cmd\r
+ * command line options\r
+ * @return presetName or null if no presets is defined\r
+ */\r
+ static String getPresetName(String[] cmd) {\r
+ String preset = null;\r
+ for (int i = 0; i < cmd.length; i++) {\r
+ String presetPrm = cmd[i];\r
+ if (presetPrm.trim().toLowerCase()\r
+ .startsWith(presetkey + pseparator)) {\r
+ preset = presetPrm.substring(presetPrm.indexOf(pseparator) + 1);\r
+ break;\r
+ }\r
+ }\r
+ return preset;\r
+ }\r
+\r
+ /**\r
+ * Extracts service name from the command line\r
+ * \r
+ * @param cmd\r
+ * command line options\r
+ * @return service name or null if it is not defined\r
+ */\r
+ public static String getServiceName(String[] cmd) {\r
+ for (int i = 0; i < cmd.length; i++) {\r
+ String serv = cmd[i];\r
+ if (serv.trim().toLowerCase().startsWith(servicekey + pseparator)) {\r
+ return serv.substring(serv.indexOf(pseparator) + 1);\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+\r
+ /**\r
+ * Extracts host name from the command line\r
+ * \r
+ * @param cmd\r
+ * command line options\r
+ * @return host name or null if it is not defined\r
+ */\r
+ public static String getHost(String[] cmd) {\r
+ for (int i = 0; i < cmd.length; i++) {\r
+ String host = cmd[i];\r
+ if (host.trim().toLowerCase().startsWith(hostkey + pseparator)) {\r
+ return host.substring(host.indexOf(pseparator) + 1);\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+\r
+ /**\r
+ * Searches the command line keys in the array of parameters\r
+ * \r
+ * @param cmd\r
+ * command line options\r
+ * @return true is the list of Parameters is requested, false otherwise\r
+ */\r
+ static boolean listParameters(String[] cmd) {\r
+ return keyFound(cmd, paramList);\r
+ }\r
+\r
+}\r