Path { String subPath() { var builder = new StringBuilder(); Path current = this; while (current != null) { if (builder.length() > 1 && !"/".equals(current.value)) builder.append('/'); builder.append(current.value); current = current.next; } return builder.toString(); } private  Path(String value); static Path parse(String path); final String value; public Path next; }
@Test void subPath() { Path path = Path.parse("/path1/path2/"); assertEquals("/path1/path2/", path.subPath()); assertEquals("path1/path2/", path.next.subPath()); assertEquals("path2/", path.next.next.subPath()); assertEquals("/", path.next.next.next.subPath()); }