@Test public void testGetUrls() { fields.put("title", "title"); fields.put("attachment_a", "a"); fields.put("attachment_b", "b"); fields.put("attachment_c", "c"); Map<String, Object> ret = FieldHelper.getFieldMatchingPattern(fields, "attachment_(.*)"); Assert.assertEquals(3, ret.size()); Assert.assertEquals("a", ret.get("a")); Assert.assertEquals("b", ret.get("b")); Assert.assertEquals("c", ret.get("c")); }
public static Map<String, Object> getFieldMatchingPattern(Map<String, Object> fields, String pattern) { Map<String, Object> fieldToUrl = new HashMap<String, Object>(); for (String field : fields.keySet()) { Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(field); if (m.matches()) { String toField; if (m.groupCount() >= 1) { toField = m.group(1); } else { toField = m.group(); } fieldToUrl.put(toField, fields.get(field)); } } return fieldToUrl; }
FieldHelper { public static Map<String, Object> getFieldMatchingPattern(Map<String, Object> fields, String pattern) { Map<String, Object> fieldToUrl = new HashMap<String, Object>(); for (String field : fields.keySet()) { Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(field); if (m.matches()) { String toField; if (m.groupCount() >= 1) { toField = m.group(1); } else { toField = m.group(); } fieldToUrl.put(toField, fields.get(field)); } } return fieldToUrl; } }
FieldHelper { public static Map<String, Object> getFieldMatchingPattern(Map<String, Object> fields, String pattern) { Map<String, Object> fieldToUrl = new HashMap<String, Object>(); for (String field : fields.keySet()) { Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(field); if (m.matches()) { String toField; if (m.groupCount() >= 1) { toField = m.group(1); } else { toField = m.group(); } fieldToUrl.put(toField, fields.get(field)); } } return fieldToUrl; }  }
FieldHelper { public static Map<String, Object> getFieldMatchingPattern(Map<String, Object> fields, String pattern) { Map<String, Object> fieldToUrl = new HashMap<String, Object>(); for (String field : fields.keySet()) { Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(field); if (m.matches()) { String toField; if (m.groupCount() >= 1) { toField = m.group(1); } else { toField = m.group(); } fieldToUrl.put(toField, fields.get(field)); } } return fieldToUrl; }  static Map<String, Object> getFieldMatchingPattern(Map<String, Object> fields,
                                                              String pattern); }
FieldHelper { public static Map<String, Object> getFieldMatchingPattern(Map<String, Object> fields, String pattern) { Map<String, Object> fieldToUrl = new HashMap<String, Object>(); for (String field : fields.keySet()) { Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(field); if (m.matches()) { String toField; if (m.groupCount() >= 1) { toField = m.group(1); } else { toField = m.group(); } fieldToUrl.put(toField, fields.get(field)); } } return fieldToUrl; }  static Map<String, Object> getFieldMatchingPattern(Map<String, Object> fields,
                                                              String pattern);  }