public static String parentOf(String path) throws PathNotFoundException {
    List<String> elements = split(path);

    int size = elements.size();
    if (size == 0) {
      throw new PathNotFoundException("No parent of " + path);
    }
    if (size == 1) {
      return "/";
    }
    elements.remove(size - 1);
    StringBuilder parent = new StringBuilder(path.length());
    for (String element : elements) {
      parent.append("/");
      parent.append(element);
    }
    return parent.toString();
  }
@Test
  public void testParentOf() throws Throwable {
    assertEquals("/", parentOf("/a"));
    assertEquals("/", parentOf("/a/"));
    assertEquals("/a", parentOf("/a/b"));
    assertEquals("/a/b", parentOf("/a/b/c"));
  }