Arguments { public static Parameters parse(String[] args) throws IOException { Parameters self = Parameters.create(); List<String> reasonableArgs = combineAdjacentIfReasonable(args); for (String arg : reasonableArgs) { if(arg.isEmpty()) { continue; } if (looksLikeKey(arg)) { String pattern = arg.substring(2); tokenizeComplexValue(self, pattern); } else { Parameters other = Parameters.parseFile(new File(arg)); self.copyFrom(other); } } return self; }  static Parameters parse(String[] args);  }
@Test public void testCommandLineArgs() throws Exception { String[] args = new String[]{ "--arrayKey+val1", "--arrayKey+val2", "--arrayKey+val3", "--intKey=4", "--mapKey/list+7", "--mapKey/list+8", "--mapKey/list+9", "--mapKey/innerVal=bob", "--mapKey/isTrue", "--mapKey/innerMap/wayInnerMap/buriedKey=absolutely", }; Parameters p = Arguments.parse(args); System.err.flush(); List<String> list = p.getList("arrayKey", String.class); assertEquals("val1", list.get(0)); assertEquals("val2", list.get(1)); assertEquals("val3", list.get(2)); assertEquals(4L, p.getLong("intKey")); Parameters inner = p.getMap("mapKey"); List<Long> ints = inner.getList("list", Long.class); assertEquals(7L, ints.get(0).longValue()); assertEquals(8L, ints.get(1).longValue()); assertEquals(9L, ints.get(2).longValue()); assertEquals("bob", inner.getString("innerVal")); assertTrue(inner.getBoolean("isTrue")); Parameters innerAgain = inner.getMap("innerMap"); assertNotNull(innerAgain); Parameters innerOnceMore = innerAgain.getMap("wayInnerMap"); assertNotNull(innerOnceMore); assertEquals("absolutely", innerOnceMore.getString("buriedKey")); }