public Path cd(String newPath) { PathInfo newPathInfo = new PathInfo(newPath); if (newPathInfo.absolute) { this.path = newPathInfo.toString(); return this; } String p = this.path + (this.path.isEmpty() ? "" : "/") + newPath; newPathInfo = new PathInfo(p); if (newPathInfo.absolute && !newPathInfo.components.isEmpty() && newPathInfo.components.get(0).equals("..")) { throw new IllegalArgumentException("Cannot cd higher than the root directory"); } this.path = newPathInfo.toString(); return this; }