Iterator<VirtualFile> (@NotNull IntIterator idIterator, @NotNull IntPredicate filter) { FileBasedIndexEx fileBasedIndex = (FileBasedIndexEx)FileBasedIndex.getInstance(); return new Iterator<>() { VirtualFile next; boolean hasNext; { findNext(); } @Override public boolean hasNext() { return hasNext; } private void findNext() { hasNext = false; while (idIterator.hasNext()) { int id = idIterator.nextInt(); if (!filter.test(id)) { continue; } VirtualFile t = fileBasedIndex.findFileById(id); if (t != null) { next = t; hasNext = true; break; } } } @Override public VirtualFile next() { if (hasNext) { VirtualFile result = next; findNext(); return result; } else { throw new NoSuchElementException(); } } @Override public void remove() { idIterator.remove(); } }; }