@Test public void returnsNullForNoMatch() { final PathPattern pattern = new RegexPathPattern(Pattern.compile("\\/dogs")); assertNull(pattern.match("/cats")); assertNotNull(pattern.match("/dogs")); }
@Override public Path match(String path) { final Matcher m = pattern.matcher(path); if(m.find()){ PathParam[] params = new PathParam[(varNames.size())]; for(int x=0;x<varNames.size();x++){ params[x] = new PathParam(varNames.get(x), m.group(x+1)); } return new Path(path, params); }else{ return null; } }
RegexPathPattern implements PathPattern { @Override public Path match(String path) { final Matcher m = pattern.matcher(path); if(m.find()){ PathParam[] params = new PathParam[(varNames.size())]; for(int x=0;x<varNames.size();x++){ params[x] = new PathParam(varNames.get(x), m.group(x+1)); } return new Path(path, params); }else{ return null; } } }
RegexPathPattern implements PathPattern { @Override public Path match(String path) { final Matcher m = pattern.matcher(path); if(m.find()){ PathParam[] params = new PathParam[(varNames.size())]; for(int x=0;x<varNames.size();x++){ params[x] = new PathParam(varNames.get(x), m.group(x+1)); } return new Path(path, params); }else{ return null; } } RegexPathPattern(Pattern pattern, String ... varNames); }
RegexPathPattern implements PathPattern { @Override public Path match(String path) { final Matcher m = pattern.matcher(path); if(m.find()){ PathParam[] params = new PathParam[(varNames.size())]; for(int x=0;x<varNames.size();x++){ params[x] = new PathParam(varNames.get(x), m.group(x+1)); } return new Path(path, params); }else{ return null; } } RegexPathPattern(Pattern pattern, String ... varNames); @Override String raw(); @Override Path match(String path); @Override boolean matches(String path); @Override List<PathParamName> varNames(); }
RegexPathPattern implements PathPattern { @Override public Path match(String path) { final Matcher m = pattern.matcher(path); if(m.find()){ PathParam[] params = new PathParam[(varNames.size())]; for(int x=0;x<varNames.size();x++){ params[x] = new PathParam(varNames.get(x), m.group(x+1)); } return new Path(path, params); }else{ return null; } } RegexPathPattern(Pattern pattern, String ... varNames); @Override String raw(); @Override Path match(String path); @Override boolean matches(String path); @Override List<PathParamName> varNames();  }