@Override public boolean contains(Path.Entry<?> e) throws IOException { updateContents(); Path.ID eid = e.id(); boolean contained; if (id == eid.parent()) { // The requested entry is contained in this folder. Therefore, we // need to search for it. contained = true; } else if (id == eid.subpath(0, id.size())) { // This folder is a parent of the requested entry. Therefore, we // need to looking for a matching folder entry. If we find one, then // we ask it for the requested entry. eid = eid.subpath(0, id.size() + 1); contained = false; } else { return false; } int idx = binarySearch(contents, nentries, eid); if (idx >= 0) { // At this point, we've found a matching index for the given ID. // However, there maybe multiple matching IDs (e.g. with different // content types). Therefore, we need to check them all to see if // they match the requested entry. Path.Item item = contents[idx]; do { if (item == e) { return true; } else if (!contained && item instanceof Path.Folder) { Path.Folder folder = (Path.Folder) item; return folder.contains(e); } } while (++idx < nentries && (item = contents[idx]).id().equals(eid)); } // no dice return false; }