Path implements CacheValue, Comparable<Path> { @NotNull public static Path fromString(@NotNull String path) throws IllegalArgumentException { checkNotNull(path); Path p = null; if (PathUtils.isAbsolute(path)) { p = ROOT; } for (String name : PathUtils.elements(path)) { name = StringCache.get(name); if (p == null) { p = new Path(name); } else { p = new Path(p, StringCache.get(name)); } } if (p == null) { throw new IllegalArgumentException("path must not be empty"); } return p; } private  Path(@Nullable Path parent,
                 @NotNull String name,
                 int hash);  Path(@NotNull Path parent, @NotNull String name);  Path(@NotNull String name); @NotNull String getName(); @NotNull Iterable<String> elements(); boolean isRoot(); @Nullable Path getParent(); int length(); int getDepth(); @NotNull Path getAncestor(int nth); boolean isAncestorOf(@NotNull Path other); boolean isAbsolute(); @NotNull static Path fromString(@NotNull String path); @NotNull StringBuilder toStringBuilder(@NotNull StringBuilder sb); @Override int getMemory(); @Override int compareTo(@NotNull Path other); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Path ROOT; }
@Test public void fromString() { assertEquals(root, Path.fromString(root.toString())); assertEquals(foo, Path.fromString(foo.toString())); assertEquals(fooBar, Path.fromString(fooBar.toString())); assertEquals(fooBarQuux, Path.fromString(fooBarQuux.toString())); assertEquals(relFoo, Path.fromString(relFoo.toString())); assertEquals(relFooBar, Path.fromString(relFooBar.toString())); assertEquals(relFooBarQuux, Path.fromString(relFooBarQuux.toString())); }
@Test(expected = IllegalArgumentException.class) public void fromStringWithEmptyString() { Path.fromString(""); }