PathTools { public static String getPathStackString(List<String> pathStack) { StringBuilder result = new StringBuilder(); boolean rootFound = false; if(!pathStack.isEmpty()) { rootFound = true; String currentEntry = pathStack.remove(0); if(!"/".equals(currentEntry)) { rootFound = false; result.append(currentEntry); } while(!pathStack.isEmpty()) { result.append('/').append(pathStack.remove(0)); } } if(rootFound && result.length() == 0) { result.append('/'); } return result.toString(); } private  PathTools(); static String resolvePath(String basePath, String path); static String evaluatePath(String path); static String getAbsolutePath(String basePath, String path); static String getParentPath(String path); static String getCompatiblePath(String path); static boolean isDotPattern(String s); static List<String> getPathStack(String path, boolean evaluateDots); static String getPathStackString(List<String> pathStack);  }
@Test public void getPathStackString() throws Exception { internalGetPathStackString("", true, ""); internalGetPathStackString("/", true, "/"); internalGetPathStackString("/foo", true, "/foo"); internalGetPathStackString("foo", true, "foo"); internalGetPathStackString("/foo/bar/../foo", true, "/foo/foo"); internalGetPathStackString("/foo/bar/...", true, "/"); internalGetPathStackString("/foo/bar/....", true, ".."); internalGetPathStackString("/foo/bar/..../foo", true, "../foo"); internalGetPathStackString("/foo/bar/..../foo", false, "/foo/bar/..../foo"); }