AbstractFileSystemService implements FileSystemService { public static String getCommonPathPrefix(List<String> strings) { if (strings.size() == 0) { return ""; } char firstChar = 0; for (int pos = 0; ; pos++) { for (int i = 0; i < strings.size(); i++) { String string = strings.get(i); if (pos == string.length()) { return string; } if (string.charAt(pos) == '*') { return stripAfterLastSlash(string, pos); } if (i == 0) { firstChar = string.charAt(pos); } else if (string.charAt(pos) != firstChar) { return stripAfterLastSlash(string, pos); } } } } AbstractFileSystemService(JobClientsMap jobClientsMap); @Override String[] globPaths(String username, List<String> pathPatterns); @Override FileStatus[] globFiles(String username, List<String> pathPatterns); @Override String getQualifiedPath(String username, String path); @Override OutputStream addFile(String username, String path); @Override boolean removeFile(String username, String path); @Override boolean removeDirectory(String username, String path); @Override boolean pathExists(String path, String username); @Override InputStream openFile(String username, String path); @Deprecated FileStatus[] globFileStatuses(List<String> pathPatterns, Configuration conf); RemoteIterator<LocatedFileStatus> globFileStatusIterator(List<String> pathPatterns, Configuration conf, FileSystemPathIteratorFactory.FileStatusFilter extraFilter, boolean withDirs, boolean doLocate); Path makeQualified(FileSystem fileSystem, String child); FileSystem getFileSystem(String username); static String getCommonPathPrefix(List<String> strings); static String getUserGlob(String userName, String dirPath); static String getUserPath(String userName, String dirPath); JobClientsMap getJobClientsMap();  }
@Test public void testGetCommonPathPrefix() throws Exception { assertEquals("", AbstractFileSystemService.getCommonPathPrefix(Collections.<String>emptyList())); assertEquals("", AbstractFileSystemService.getCommonPathPrefix(Arrays.asList(""))); assertEquals("", AbstractFileSystemService.getCommonPathPrefix(Arrays.asList(".*"))); assertEquals("", AbstractFileSystemService.getCommonPathPrefix(Arrays.asList("abc.*"))); assertEquals("abc", AbstractFileSystemService.getCommonPathPrefix(Arrays.asList("abc"))); assertEquals("abc", AbstractFileSystemService.getCommonPathPrefix(Arrays.asList("abc/.*"))); assertEquals("abc", AbstractFileSystemService.getCommonPathPrefix(Arrays.asList("abc/efg.*"))); assertEquals("ab/cd", AbstractFileSystemService.getCommonPathPrefix(Arrays.asList("ab/cd/MER_.*.N1"))); assertEquals("ab/cd", AbstractFileSystemService.getCommonPathPrefix(Arrays.asList("ab/cd/ef", "ab/cd/gh"))); assertEquals("ab/cd", AbstractFileSystemService.getCommonPathPrefix( Arrays.asList("ab/cd/gh", "ab/cd/ef", "ab/cd/ef/gh"))); assertEquals("ab/cd", AbstractFileSystemService.getCommonPathPrefix(Arrays.asList("ab/cd/.*", "ab/cd/.*"))); assertEquals("", AbstractFileSystemService.getCommonPathPrefix(Arrays.asList("", "bcd"))); assertEquals("", AbstractFileSystemService.getCommonPathPrefix(Arrays.asList("a", ""))); assertEquals("ab", AbstractFileSystemService.getCommonPathPrefix(Arrays.asList("ab/cd", "ab/ce"))); assertEquals("/gpfs/DATA3/www/Sentinel3/SLSTR/2019/05", AbstractFileSystemService.getCommonPathPrefix(Arrays.asList(PATTERNS1))); }