### Question:
SelectiveRecordReaderEventIterator implements EventIterator { protected static List<File> filterUnneededFiles(final List<File> filesToRead, final List<Long> eventIds) { final List<File> files = new ArrayList<>(); final Long firstEventId = eventIds.get(0); final Long lastEventId = eventIds.get(eventIds.size() - 1); final List<File> sortedFileList = new ArrayList<>(filesToRead); Collections.sort(sortedFileList, DirectoryUtils.SMALLEST_ID_FIRST); File lastFile = null; for (final File file : filesToRead) { final long firstIdInFile = DirectoryUtils.getMinId(file); if (firstIdInFile > lastEventId) { continue; } if (firstIdInFile > firstEventId) { if (files.isEmpty() && lastFile != null) { files.add(lastFile); } files.add(file); } lastFile = file; } if (files.isEmpty() && lastFile != null) { files.add(lastFile); } return files; } SelectiveRecordReaderEventIterator(final List<File> filesToRead, final RecordReaderFactory readerFactory, final List<Long> eventIds, final int maxAttributeChars); @Override void close(); @Override Optional<ProvenanceEventRecord> nextEvent();  }### Answer:
@Test public void testFilterUnneededFiles() { final File file1 = new File("1.prov"); final File file1000 = new File("1000.prov"); final File file2000 = new File("2000.prov"); final File file3000 = new File("3000.prov"); final List<File> files = new ArrayList<>(); files.add(file1); files.add(file1000); files.add(file2000); files.add(file3000); List<Long> eventIds = new ArrayList<>(); eventIds.add(1048L); eventIds.add(2048L); eventIds.add(3048L); List<File> filteredFiles = SelectiveRecordReaderEventIterator.filterUnneededFiles(files, eventIds); assertEquals(Arrays.asList(new File[] {file1000, file2000, file3000}), filteredFiles); eventIds.clear(); eventIds.add(1L); eventIds.add(1048L); filteredFiles = SelectiveRecordReaderEventIterator.filterUnneededFiles(files, eventIds); assertEquals(Arrays.asList(new File[] {file1, file1000}), filteredFiles); }