RegexMountPoint { public InodeTree.ResolveResult<T> resolve(final String srcPath, final boolean resolveLastComponent) { String pathStrToResolve = getPathToResolve(srcPath, resolveLastComponent); for (RegexMountPointInterceptor interceptor : interceptorList) { pathStrToResolve = interceptor.interceptSource(pathStrToResolve); } LOGGER.debug("Path to resolve:" + pathStrToResolve + ", srcPattern:" + getSrcPathRegex()); Matcher srcMatcher = getSrcPattern().matcher(pathStrToResolve); String parsedDestPath = getDstPath(); int mappedCount = 0; String resolvedPathStr = ""; while (srcMatcher.find()) { resolvedPathStr = pathStrToResolve.substring(0, srcMatcher.end()); Map<String, Set<String>> varMap = getVarInDestPathMap(); for (Map.Entry<String, Set<String>> entry : varMap.entrySet()) { String regexGroupNameOrIndexStr = entry.getKey(); Set<String> groupRepresentationStrSetInDest = entry.getValue(); parsedDestPath = replaceRegexCaptureGroupInPath( parsedDestPath, srcMatcher, regexGroupNameOrIndexStr, groupRepresentationStrSetInDest); } ++mappedCount; } if (0 == mappedCount) { return null; } Path remainingPath = getRemainingPathStr(srcPath, resolvedPathStr); for (RegexMountPointInterceptor interceptor : interceptorList) { parsedDestPath = interceptor.interceptResolvedDestPathStr(parsedDestPath); remainingPath = interceptor.interceptRemainingPath(remainingPath); } InodeTree.ResolveResult resolveResult = inodeTree .buildResolveResultForRegexMountPoint(InodeTree.ResultKind.EXTERNAL_DIR, resolvedPathStr, parsedDestPath, remainingPath); return resolveResult; } RegexMountPoint(InodeTree inodeTree, String sourcePathRegex,
      String destPath, String settingsStr); Map<String, Set<String>> getVarInDestPathMap(); void initialize(); static Map<String, Set<String>> getVarListInString(String input); String getSrcPathRegex(); Pattern getSrcPattern(); String getDstPath(); static Pattern getVarPatternInDest(); InodeTree.ResolveResult<T> resolve(final String srcPath,
      final boolean resolveLastComponent); static final String SETTING_SRCREGEX_SEP; static final char INTERCEPTOR_SEP; static final char INTERCEPTOR_INTERNAL_SEP; static final Pattern VAR_PATTERN_IN_DEST; }
@Test public void testResolve() throws IOException { String regexStr = "^/user/(?<username>\\w+)"; String dstPathStr = "/namenode1/testResolve/$username"; String settingsStr = null; RegexMountPoint regexMountPoint = new RegexMountPoint(inodeTree, regexStr, dstPathStr, settingsStr); regexMountPoint.initialize(); InodeTree.ResolveResult resolveResult = regexMountPoint.resolve("/user/hadoop/file1", true); Assert.assertEquals(resolveResult.kind, InodeTree.ResultKind.EXTERNAL_DIR); Assert.assertTrue( resolveResult.targetFileSystem instanceof TestRegexMountPointFileSystem); Assert.assertEquals("/user/hadoop", resolveResult.resolvedPath); Assert.assertTrue( resolveResult.targetFileSystem instanceof TestRegexMountPointFileSystem); Assert.assertEquals("/namenode1/testResolve/hadoop", ((TestRegexMountPointFileSystem) resolveResult.targetFileSystem) .getUri().toString()); Assert.assertEquals("/file1", resolveResult.remainingPath.toString()); }