@Test public void testPathJoin() throws Exception { assertThat(pathJoin("/", "aaa", "bbb"), is("aaa/bbb")); assertThat(pathJoin("/", "a", "b"), is("a/b")); assertThat(pathJoin("/", "a/", "/b"), is("a/b")); assertThat(pathJoin("/", "a/", "b/"), is("a/b/")); assertThat(pathJoin("/"), is("")); assertThat(pathJoin("/", "a"), is("a")); assertThat(pathJoin("/", "/a/"), is("/a/")); }
public static String pathJoin(String separator, String ... parts) { StringBuilder builder = new StringBuilder(); if (parts.length == 0) return ""; if (parts.length == 1) return parts[0]; for (int i = 0; i < parts.length; i++) { String part = parts[i]; if (i == 0) { builder.append(org.apache.commons.lang.StringUtils.removeEnd(part, separator)).append(separator); } else if (i == parts.length - 1) { builder.append(org.apache.commons.lang.StringUtils.removeStart(part, separator)); } else { builder.append(org.apache.commons.lang.StringUtils.removeStart(org.apache.commons.lang.StringUtils.removeEnd(part, separator), separator)).append(separator); } } return builder.toString(); }
PathUtils { public static String pathJoin(String separator, String ... parts) { StringBuilder builder = new StringBuilder(); if (parts.length == 0) return ""; if (parts.length == 1) return parts[0]; for (int i = 0; i < parts.length; i++) { String part = parts[i]; if (i == 0) { builder.append(org.apache.commons.lang.StringUtils.removeEnd(part, separator)).append(separator); } else if (i == parts.length - 1) { builder.append(org.apache.commons.lang.StringUtils.removeStart(part, separator)); } else { builder.append(org.apache.commons.lang.StringUtils.removeStart(org.apache.commons.lang.StringUtils.removeEnd(part, separator), separator)).append(separator); } } return builder.toString(); } }
PathUtils { public static String pathJoin(String separator, String ... parts) { StringBuilder builder = new StringBuilder(); if (parts.length == 0) return ""; if (parts.length == 1) return parts[0]; for (int i = 0; i < parts.length; i++) { String part = parts[i]; if (i == 0) { builder.append(org.apache.commons.lang.StringUtils.removeEnd(part, separator)).append(separator); } else if (i == parts.length - 1) { builder.append(org.apache.commons.lang.StringUtils.removeStart(part, separator)); } else { builder.append(org.apache.commons.lang.StringUtils.removeStart(org.apache.commons.lang.StringUtils.removeEnd(part, separator), separator)).append(separator); } } return builder.toString(); }  }
PathUtils { public static String pathJoin(String separator, String ... parts) { StringBuilder builder = new StringBuilder(); if (parts.length == 0) return ""; if (parts.length == 1) return parts[0]; for (int i = 0; i < parts.length; i++) { String part = parts[i]; if (i == 0) { builder.append(org.apache.commons.lang.StringUtils.removeEnd(part, separator)).append(separator); } else if (i == parts.length - 1) { builder.append(org.apache.commons.lang.StringUtils.removeStart(part, separator)); } else { builder.append(org.apache.commons.lang.StringUtils.removeStart(org.apache.commons.lang.StringUtils.removeEnd(part, separator), separator)).append(separator); } } return builder.toString(); }  static String pathJoin(String separator, String ... parts); }
PathUtils { public static String pathJoin(String separator, String ... parts) { StringBuilder builder = new StringBuilder(); if (parts.length == 0) return ""; if (parts.length == 1) return parts[0]; for (int i = 0; i < parts.length; i++) { String part = parts[i]; if (i == 0) { builder.append(org.apache.commons.lang.StringUtils.removeEnd(part, separator)).append(separator); } else if (i == parts.length - 1) { builder.append(org.apache.commons.lang.StringUtils.removeStart(part, separator)); } else { builder.append(org.apache.commons.lang.StringUtils.removeStart(org.apache.commons.lang.StringUtils.removeEnd(part, separator), separator)).append(separator); } } return builder.toString(); }  static String pathJoin(String separator, String ... parts);  }