@Override
 public void finish() {
   // Let the collectors do any summary computations etc.
   unpairedCollector.onComplete();
   firstOfPairCollector.onComplete();
   secondOfPairCollector.onComplete();
   pairCollector.onComplete();
 }
    public void acceptRecord(final SAMRecordAndReference args) {
      final SAMRecord rec = args.getSamRecord();
      final ReferenceSequence ref = args.getReferenceSequence();

      if (rec.getReadPairedFlag()) {
        if (rec.getFirstOfPairFlag()) {
          firstOfPairCollector.addRecord(rec, ref);
        } else {
          secondOfPairCollector.addRecord(rec, ref);
        }

        pairCollector.addRecord(rec, ref);
      } else {
        unpairedCollector.addRecord(rec, ref);
      }
    }
    @Override
    public void addMetricsToFile(final MetricsFile<AlignmentSummaryMetrics, Comparable<?>> file) {
      if (firstOfPairCollector.getMetrics().TOTAL_READS > 0) {
        // override how bad cycle is determined for paired reads, it should be
        // the sum of first and second reads
        pairCollector.getMetrics().BAD_CYCLES =
            firstOfPairCollector.getMetrics().BAD_CYCLES
                + secondOfPairCollector.getMetrics().BAD_CYCLES;

        file.addMetric(firstOfPairCollector.getMetrics());
        file.addMetric(secondOfPairCollector.getMetrics());
        file.addMetric(pairCollector.getMetrics());
      }

      // if there are no reads in any category then we will returned an unpaired alignment summary
      // metric with all zero values
      if (unpairedCollector.getMetrics().TOTAL_READS > 0
          || firstOfPairCollector.getMetrics().TOTAL_READS == 0) {
        file.addMetric(unpairedCollector.getMetrics());
      }
    }