Iterator<VirtualFile> () { BitSet ids = fileIds; IntSet idSet = this.idSet; VirtualFileManager virtualFileManager = VirtualFileManager.getInstance(); Iterator<VirtualFile> fromIdsIterator; if (ids == null) { fromIdsIterator = Collections.emptyIterator(); } else { BitSetIterator idIterator = new BitSetIterator(ids); fromIdsIterator = new Iterator<VirtualFile>() { @Override public boolean hasNext() { return idIterator.hasNext(); } @Override public VirtualFile next() { ProgressManager.checkCanceled(); return virtualFileManager.findFileById(idIterator.next()); } @Override public void remove() { idIterator.remove(); } }; } Iterator<? extends VirtualFile> totalIterator; if (idSet == null) { totalIterator = ContainerUtil.concatIterators(fromIdsIterator, weirdFiles.iterator()); } else { Iterator<VirtualFile> idSetIterator = new Iterator<VirtualFile>() { final IntIterator iterator = idSet.intIterator(); @Override public boolean hasNext() { return iterator.hasNext(); } @Override public VirtualFile next() { ProgressManager.checkCanceled(); return virtualFileManager.findFileById(iterator.nextInt()); } @Override public void remove() { iterator.remove(); } }; totalIterator = ContainerUtil.concatIterators(fromIdsIterator, idSetIterator, weirdFiles.iterator()); } return new Iterator<VirtualFile>() { VirtualFile next; Boolean hasNext; @Override public boolean hasNext() { findNext(); return hasNext; } private void findNext() { if (hasNext == null) { hasNext = false; while (totalIterator.hasNext()) { ProgressManager.checkCanceled(); VirtualFile t = totalIterator.next(); if (t != null) { next = t; hasNext = true; break; } } } } @Override public VirtualFile next() { findNext(); if (!hasNext) { throw new NoSuchElementException(); } VirtualFile result = next; hasNext = null; return result; } @Override public void remove() { totalIterator.remove(); } }; }