ArgScanner { @VisibleForTesting static List<String> joinKeysToValues(Iterable<String> args) { List<String> joinedArgs = Lists.newArrayList(); String unmappedKey = null; for (String arg : args) { if (unmappedKey == null) { if (DANGLING_ASSIGNMENT_PATTERN.matcher(arg).matches()) { unmappedKey = arg; } else { joinedArgs.add(arg); } } else { if (ASSIGNMENT_PATTERN.matcher(arg).matches()) { joinedArgs.add(unmappedKey); joinedArgs.add(arg); unmappedKey = null; } else if (DANGLING_ASSIGNMENT_PATTERN.matcher(arg).find()) { joinedArgs.add(unmappedKey); unmappedKey = arg; } else { joinedArgs.add(unmappedKey + "=" + arg); unmappedKey = null; } } } if (unmappedKey != null) { joinedArgs.add(unmappedKey); } return joinedArgs; } ArgScanner();  ArgScanner(PrintStream out); boolean parse(Iterable<String> args); boolean parse(Predicate<Field> filter, Iterable<String> args); boolean parse(ArgsInfo argsInfo, Iterable<String> args);  }
@Test public void testJoinKeysToValues() { assertThat(ArgScanner.joinKeysToValues(Arrays.asList("")), is(Arrays.asList(""))); assertThat(ArgScanner.joinKeysToValues(Arrays.asList("-a", "b", "-c", "-d")), is(Arrays.asList("-a=b", "-c", "-d"))); assertThat(ArgScanner.joinKeysToValues(Arrays.asList("-a='b'", "-c", "-d", "'e'")), is(Arrays.asList("-a='b'", "-c", "-d='e'"))); assertThat(ArgScanner.joinKeysToValues(Arrays.asList("-a=-b", "c", "-d", "\"e\"")), is(Arrays.asList("-a=-b", "c", "-d=\"e\""))); }