@Test public void testSimplifyPath() { assertThat(util.simplifyPath("/a/b/c/d")).isEqualTo("/a/b/c/d"); assertThat(util.simplifyPath("/a/../b/")).isEqualTo("/b"); assertThat(util.simplifyPath("/a/./b/c/../d")).isEqualTo("/a/b/d"); assertThat(util.simplifyPath("./a")).isEqualTo("/a"); assertThat(util.simplifyPath(null)).isEqualTo(""); assertThat(util.simplifyPath("")).isEqualTo(""); }
@Nonnull public String simplifyPath(@Nonnull String path) { if (ifInvalidPATH(path)) { return ""; } String delim = "[/]+"; String[] arr = path.split(delim); Stack<String> stack = new Stack<>(); fillStack(arr, stack); if (emptyStack(stack)) { return "/"; } StringBuilder sb = new StringBuilder(); for (String str : stack) { sb.append("/").append(str); } return sb.toString(); }
Util { @Nonnull public String simplifyPath(@Nonnull String path) { if (ifInvalidPATH(path)) { return ""; } String delim = "[/]+"; String[] arr = path.split(delim); Stack<String> stack = new Stack<>(); fillStack(arr, stack); if (emptyStack(stack)) { return "/"; } StringBuilder sb = new StringBuilder(); for (String str : stack) { sb.append("/").append(str); } return sb.toString(); } }
Util { @Nonnull public String simplifyPath(@Nonnull String path) { if (ifInvalidPATH(path)) { return ""; } String delim = "[/]+"; String[] arr = path.split(delim); Stack<String> stack = new Stack<>(); fillStack(arr, stack); if (emptyStack(stack)) { return "/"; } StringBuilder sb = new StringBuilder(); for (String str : stack) { sb.append("/").append(str); } return sb.toString(); }  }
Util { @Nonnull public String simplifyPath(@Nonnull String path) { if (ifInvalidPATH(path)) { return ""; } String delim = "[/]+"; String[] arr = path.split(delim); Stack<String> stack = new Stack<>(); fillStack(arr, stack); if (emptyStack(stack)) { return "/"; } StringBuilder sb = new StringBuilder(); for (String str : stack) { sb.append("/").append(str); } return sb.toString(); }  @Nonnull String simplifyPath(@Nonnull String path); void createParentDirs(@Nonnull File file); }
Util { @Nonnull public String simplifyPath(@Nonnull String path) { if (ifInvalidPATH(path)) { return ""; } String delim = "[/]+"; String[] arr = path.split(delim); Stack<String> stack = new Stack<>(); fillStack(arr, stack); if (emptyStack(stack)) { return "/"; } StringBuilder sb = new StringBuilder(); for (String str : stack) { sb.append("/").append(str); } return sb.toString(); }  @Nonnull String simplifyPath(@Nonnull String path); void createParentDirs(@Nonnull File file);  }