private PathBinders() {
}
public static PathBinder parse(String path, boolean exact) {
PathBinderBuilder pathBinderBuilder = new DefaultPathBinderBuilder();
Matcher matchResult = PLACEHOLDER.matcher(path);
int lastIndex = 0;
if (matchResult.find()) {
do {
int thisIndex = matchResult.start();
if (thisIndex != lastIndex) {
pathBinderBuilder.literal(path.substring(lastIndex, thisIndex));
}
lastIndex = matchResult.end();
String component = matchResult.group(0);
boolean found = false;
for (TokenType type : TokenType.values()) {
if (type.match(component, pathBinderBuilder)) {
found = true;
break;
}
}
if (!found) {
throw new IllegalArgumentException(String.format("Cannot match path %s (%s)", path, component));
}
} while (matchResult.find());
if (lastIndex < path.length()) {
pathBinderBuilder.literal(path.substring(lastIndex));
}
} else {
pathBinderBuilder.literal(path);
}
return pathBinderBuilder.build(exact);
}