@Test public void testRelativize() { assertEquals("a", PathRelativizer.relativize("/", "/a")); assertEquals("/b/path", PathRelativizer.relativize("/a", "/b/path")); assertEquals("path", PathRelativizer.relativize("/a", "/a/path")); assertEquals("a/path", PathRelativizer.relativize("public_html", "/home/user/public_html/a/path")); assertEquals("/home/user/public_html/a/path", PathRelativizer.relativize(null, "/home/user/public_html/a/path")); }
public static String relativize(String root, final String path) { if(StringUtils.isBlank(root)) { return path; } if(!StringUtils.equals(root, String.valueOf(Path.DELIMITER))) { root = root + Path.DELIMITER; } if(StringUtils.contains(path, root)) { return StringUtils.substring(path, path.indexOf(root) + root.length()); } return path; }
PathRelativizer { public static String relativize(String root, final String path) { if(StringUtils.isBlank(root)) { return path; } if(!StringUtils.equals(root, String.valueOf(Path.DELIMITER))) { root = root + Path.DELIMITER; } if(StringUtils.contains(path, root)) { return StringUtils.substring(path, path.indexOf(root) + root.length()); } return path; } }
PathRelativizer { public static String relativize(String root, final String path) { if(StringUtils.isBlank(root)) { return path; } if(!StringUtils.equals(root, String.valueOf(Path.DELIMITER))) { root = root + Path.DELIMITER; } if(StringUtils.contains(path, root)) { return StringUtils.substring(path, path.indexOf(root) + root.length()); } return path; } private  PathRelativizer(); }
PathRelativizer { public static String relativize(String root, final String path) { if(StringUtils.isBlank(root)) { return path; } if(!StringUtils.equals(root, String.valueOf(Path.DELIMITER))) { root = root + Path.DELIMITER; } if(StringUtils.contains(path, root)) { return StringUtils.substring(path, path.indexOf(root) + root.length()); } return path; } private  PathRelativizer(); static String relativize(String root, final String path); }
PathRelativizer { public static String relativize(String root, final String path) { if(StringUtils.isBlank(root)) { return path; } if(!StringUtils.equals(root, String.valueOf(Path.DELIMITER))) { root = root + Path.DELIMITER; } if(StringUtils.contains(path, root)) { return StringUtils.substring(path, path.indexOf(root) + root.length()); } return path; } private  PathRelativizer(); static String relativize(String root, final String path);  }