PathUtil { public static String parentPath(String path) { path = fix(path); if (!path.startsWith("/")) { path = "/" + path; } if (path.equals("/")) { return null; } if (path.matches("^/[^/]{1,}/{0,1}$")) { path = "/"; } else { List<String> parentPath = RegexUtil.groups( "((/{1}[^/]{1}.*))/{1}[^/]{1,}/{0,1}?", path); if (parentPath.size() <= 1) { throw new RuntimeException("error: " + parentPath + " " + path); } path = parentPath.get(1); } return path; }  static String parentPath(String path); static String fix(String path); static String getExtention(String path); static String concatPath(String path, String child); static String removeExtention(String path); static String getName(String path); static String toUrl(URL resource); static String toUrl(String url); static List<String> split(String path);  }
@Test public void testGetParent() { assertEquals("/", PathUtil.parentPath("xyz.txt")); assertEquals("/", PathUtil.parentPath("/xyz.txt")); assertEquals("/abc/fff", PathUtil.parentPath("/abc/fff/xyz.txt")); assertEquals("/", PathUtil.parentPath("xyz.txt/")); assertEquals("/", PathUtil.parentPath("/xyz.txt/")); assertEquals("/abc/fff", PathUtil.parentPath("/abc/fff/xyz.txt/")); assertNull(PathUtil.parentPath("/")); assertEquals("/abc/fff", PathUtil.parentPath(" }