HandlerPatterns { public static Map<String,String> getNamesWithAliases(String nameList) { String[] names = nameList.split(","); Map<String,String> results = new LinkedHashMap<>(); for ( String p : names) { String configName = p.trim(); if ( configName.length() > 0) { Matcher matcher = nameWithAlias.matcher(configName); if (matcher.matches()) { results.put(matcher.group(2), matcher.group(1)); } else { results.put(configName, configName); } } } return results; }  static Map<String,String> getNamesWithAliases(String nameList); static List<String> getNames(String nameList); static final String namePermittedChars; static final String namePattern; static final String nameListPattern; }
@Test public void testICanMatchProcessesWithAliasesWithTabsAndExtraWhiteSpace() throws Exception { Pattern p = Pattern.compile(HandlerPatterns.nameListPattern); String listOfProcessNames = "processOne as one, processTwo as two, processThree as three"; assertTrue(p.matcher(listOfProcessNames).matches()); Map<String,String> allProcessNames = HandlerPatterns.getNamesWithAliases(listOfProcessNames); HashMap<String,String> expected = new HashMap<>(); expected.put("one", "processOne"); expected.put("two", "processTwo"); expected.put("three", "processThree"); assertEquals(expected, allProcessNames); }