class RadixTree {

  public String getLongestPrefix(String path) {
    RadixNode<T> n = root;
    Path p = Paths.get(path);
    int level = 0;
    while (level < p.getNameCount()) {
      HashMap<String, RadixNode> children = n.getChildren();
      if (children.isEmpty()) {
        break;
      }
      String component = p.getName(level).toString();
      if (children.containsKey(component)) {
        n = children.get(component);
        level++;
      } else {
        break;
      }
    }

    if (level >= 1) {
      Path longestMatch =
          Paths.get(root.getName()).resolve(p.subpath(0, level));
      String ret = longestMatch.toString();
      return path.endsWith("/") ?  ret + "/" : ret;
    } else {
      return root.getName();
    }
  }

  public  RadixTree();

}