public Path create( Path parentPath,
String subpath ) {
CheckArg.isNotNull(parentPath, "parentPath");
CheckArg.isNotNull(subpath, "subpath");
if (parentPath.isIdentifier()) {
throw new InvalidPathException(GraphI18n.unableToCreatePathBasedUponIdentifierPath.text(parentPath, subpath));
}
subpath = subpath.trim();
boolean singleChild = subpath.indexOf(Path.DELIMITER) == -1;
if (!singleChild && subpath.startsWith("./")) {
if (subpath.length() == 2) return parentPath; // self reference
// Remove the leading parent reference and try again to see if single child ...
subpath = subpath.substring(2);
singleChild = subpath.indexOf(Path.DELIMITER) == -1;
}
if (singleChild) {
try {
Path.Segment childSegment = createSegment(subpath);
if (childSegment.isIdentifier()) {
throw new InvalidPathException(GraphI18n.unableToCreatePathUsingIdentifierPathAndAnotherPath.text(parentPath,
subpath));
}
return new ChildPath(parentPath, childSegment);
} catch (IllegalArgumentException t) {
// Catch and eat, letting the slower implementation catch anything ...