class PathContainerService {

    public Path getContainer(final Path file) {
        if(file.isRoot()) {
            return file;
        }
        Path container = file;
        while(!this.isContainer(container)) {
            container = container.getParent();
        }
        return container;
    }

}