### Question:
ArgumentParser { public static String[] selectCommand(String[] args, String optionFormat, String[][] commandSets) throws ParseException { ArgumentParser ap = new ArgumentParser(optionFormat, "#command[s] +following[s] .."); Map params = ap.parse(args); String command = (String) ArgumentParser.getValue(params, "command", 0); for (String[] commandSet : commandSets) { if (commandSet[0].equals(command)) { return commandSet; } } throw new ParseException("Command '"+command+"' not found", 0); } ArgumentParser(String optionFormat, String parameterFormat); Map<String, ArgumentFormat> getOptionFormat(); Map<? extends String, ? extends ArgumentFormat> getParameterFormat(); @SuppressWarnings("unchecked") Map<String,List<?>> parse(String[] args); static Object getFirstValue(List<? extends Object> optionValues); static Object getValue(Map args, String name, int index); static void main(String[] args); static String[] selectCommand(String[] args, String optionFormat,
                                       String[][] commandSets); static final String[] TYPES; static final int TYPE_INTEGER; static final int TYPE_LONG; static final int TYPE_STRING; static final int TYPE_OCTET_STRING; }### Answer:
@Test public void selectCommand() throws Exception { String[] args = { "-l", "0x80:00:13:70:01:c0:a8:02:0e","-a","SHA", "-A", "SHADESAuthPassword", "-y", "DES", "-Y", "SHADESPrivPassword", "-u", "SHADES", "-CE", "0x80:00:13:70:02:c0:a8:02:0e", "usmUser", "create", "127.0.0.1/4700", "newuser", "SHADES", "0x80:00:13:70:01:c0:a8:02:0f" }; String[] commandSet = ArgumentParser.selectCommand(args, ALL_OPTIONS, COMMANDS); assertEquals("usmUser", commandSet[0]); ArgumentParser parser = new ArgumentParser(commandSet[1], commandSet[2]); Map<String,List<?>> commandLineParameters = parser.parse(args); assertEquals("low", commandLineParameters.get("rsl").get(0)); }