PathUtils { public static int getDepth(String path, String separator) { if(path.equals("") || path.equals(separator)) return 0; int depth = 1; int pos = path.startsWith(separator)?1:0; while ((pos=path.indexOf(separator, pos+1))!=-1) depth++; if(path.endsWith(separator)) depth--; return depth; }  static ResolvedDestination resolveDestination(String destPath, AbstractFile baseFolder); static String removeLeadingSeparator(String path); static String removeLeadingSeparator(String path, String separator); static String removeTrailingSeparator(String path); static String removeTrailingSeparator(String path, String separator); static boolean pathEquals(String path1, String path2, String separator); static int getPathHashCode(String path, String separator); static String removeLeadingFragments(String path, String separator, int nbFragments); static int getDepth(String path, String separator);  }
@Test public void testGetDepth() { assert 0 == PathUtils.getDepth("/", "/"); assert 0 == PathUtils.getDepth("", "/"); assert 1 == PathUtils.getDepth("/home", "/"); assert 1 == PathUtils.getDepth("/home/", "/"); assert 2 == PathUtils.getDepth("/home/maxence", "/"); assert 2 == PathUtils.getDepth("/home/maxence/", "/"); assert 1 == PathUtils.getDepth("/home/maxence", "\\"); assert 1 == PathUtils.getDepth("C:", "\\"); assert 1 == PathUtils.getDepth("C:\\", "\\"); assert 2 == PathUtils.getDepth("C:\\home", "\\"); assert 2 == PathUtils.getDepth("C:\\home\\", "\\"); assert 3 == PathUtils.getDepth("C:\\home\\maxence", "\\"); assert 3 == PathUtils.getDepth("C:\\home\\maxence\\", "\\"); }