private void verifyCommitOrder(List<? extends IndexCommit> commits) {
   if (commits.isEmpty()) {
     return;
   }
   final IndexCommit firstCommit = commits.get(0);
   long last = SegmentInfos.generationFromSegmentsFileName(firstCommit.getSegmentsFileName());
   assertEquals(last, firstCommit.getGeneration());
   for (int i = 1; i < commits.size(); i++) {
     final IndexCommit commit = commits.get(i);
     long now = SegmentInfos.generationFromSegmentsFileName(commit.getSegmentsFileName());
     assertTrue("SegmentInfos commits are out-of-order", now > last);
     assertEquals(now, commit.getGeneration());
     last = now;
   }
 }
  /** @see org.apache.lucene.index.IndexReader#listCommits */
  public static Collection<IndexCommit> listCommits(Directory dir) throws IOException {
    final String[] files = dir.listAll();

    List<IndexCommit> commits = new ArrayList<IndexCommit>();

    SegmentInfos latest = new SegmentInfos();
    latest.read(dir);
    final long currentGen = latest.getGeneration();

    commits.add(new ReaderCommit(latest, dir));

    for (int i = 0; i < files.length; i++) {

      final String fileName = files[i];

      if (fileName.startsWith(IndexFileNames.SEGMENTS)
          && !fileName.equals(IndexFileNames.SEGMENTS_GEN)
          && SegmentInfos.generationFromSegmentsFileName(fileName) < currentGen) {

        SegmentInfos sis = new SegmentInfos();
        try {
          // IOException allowed to throw there, in case
          // segments_N is corrupt
          sis.read(dir, fileName);
        } catch (FileNotFoundException fnfe) {
          // LUCENE-948: on NFS (and maybe others), if
          // you have writers switching back and forth
          // between machines, it's very likely that the
          // dir listing will be stale and will claim a
          // file segments_X exists when in fact it
          // doesn't.  So, we catch this and handle it
          // as if the file does not exist
          sis = null;
        }

        if (sis != null) commits.add(new ReaderCommit(sis, dir));
      }
    }

    // Ensure that the commit points are sorted in ascending order.
    Collections.sort(commits);

    return commits;
  }