@Test public void testCreateStreamUrlPatternWithTwoValues() throws Exception { List<String> result = RequestHandlerUtil.getGroups("/createStream/1/abc", CreateStreamRequestHandler.PATH_REGEX); assertEquals("two captures expected", 2, result.size()); assertEquals("First is '1'", "1", result.get(0)); assertEquals("Second is 'abc'", "abc", result.get(1)); }
public static List<String> getGroups(String path, String regex) { List<String> captures = new ArrayList<String>(); Matcher m = Pattern.compile(regex).matcher(path); if (m.lookingAt()) { for (int i = 1; i <= m.groupCount(); i++) { if (m.group(i) != null) captures.add(m.group(i)); } } return captures; }
RequestHandlerUtil { public static List<String> getGroups(String path, String regex) { List<String> captures = new ArrayList<String>(); Matcher m = Pattern.compile(regex).matcher(path); if (m.lookingAt()) { for (int i = 1; i <= m.groupCount(); i++) { if (m.group(i) != null) captures.add(m.group(i)); } } return captures; } }
RequestHandlerUtil { public static List<String> getGroups(String path, String regex) { List<String> captures = new ArrayList<String>(); Matcher m = Pattern.compile(regex).matcher(path); if (m.lookingAt()) { for (int i = 1; i <= m.groupCount(); i++) { if (m.group(i) != null) captures.add(m.group(i)); } } return captures; } private  RequestHandlerUtil(); }
RequestHandlerUtil { public static List<String> getGroups(String path, String regex) { List<String> captures = new ArrayList<String>(); Matcher m = Pattern.compile(regex).matcher(path); if (m.lookingAt()) { for (int i = 1; i <= m.groupCount(); i++) { if (m.group(i) != null) captures.add(m.group(i)); } } return captures; } private  RequestHandlerUtil(); static List<String> getGroups(String path, String regex); }
RequestHandlerUtil { public static List<String> getGroups(String path, String regex) { List<String> captures = new ArrayList<String>(); Matcher m = Pattern.compile(regex).matcher(path); if (m.lookingAt()) { for (int i = 1; i <= m.groupCount(); i++) { if (m.group(i) != null) captures.add(m.group(i)); } } return captures; } private  RequestHandlerUtil(); static List<String> getGroups(String path, String regex);  }