@@ -0,0 +1,2622 @@
+package org.broadinstitute.sting.gatk.iterators;%0A%0Aimport net.sf.samtools.SAMRecord;%0Aimport net.sf.samtools.util.CloseableIterator;%0A%0Aimport java.util.Iterator;%0A%0A/**%0A *%0A * User: aaron%0A * Date: Apr 14, 2009%0A * Time: 5:27:31 PM%0A *%0A * The Broad Institute%0A * SOFTWARE COPYRIGHT NOTICE AGREEMENT %0A * This software and its documentation are copyright 2009 by the%0A * Broad Institute/Massachusetts Institute of Technology. All rights are reserved.%0A *%0A * This software is supplied without any warranty or guaranteed support whatsoever. Neither%0A * the Broad Institute nor MIT can be responsible for its use, misuse, or functionality.%0A *%0A */%0A%0A%0A/**%0A * @author aaron%0A * @version 1.0%0A * @date Apr 14, 2009%0A * %3Cp/%3E%0A * Class BoundedReadIterator%0A * %3Cp/%3E%0A * This class implements a read iterator that is bounded by the number of reads%0A * it will produce over the iteration.%0A */%0Apublic class BoundedReadIterator implements CloseableIterator%3CSAMRecord%3E, Iterable%3CSAMRecord%3E %7B%0A%0A    // the genome loc we're bounding%0A    final private long readCount;%0A    private long currentCount = 0;%0A    // the iterator we want to decorate%0A    private CloseableIterator%3CSAMRecord%3E iterator;%0A%0A    // are we open%0A    private boolean isOpen = false;%0A    /**%0A     * constructor%0A     * @param iter%0A     * @param readCount%0A     */%0A    public BoundedReadIterator(CloseableIterator%3CSAMRecord%3E iter, long readCount) %7B%0A        if (iter != null) %7B%0A            isOpen = true;%0A            this.iterator = iter;%0A        %7D%0A        this.readCount = readCount;%0A    %7D%0A%0A%0A    /**%0A     * Do we have a next? If the iterator has a read and we're not over the read%0A     * count, then yes%0A     * @return%0A     */%0A    public boolean hasNext() %7B%0A        if (isOpen && iterator.hasNext() && currentCount %3C readCount) %7B%0A            return true;%0A        %7D else %7B%0A            if (isOpen) %7B%0A                close();%0A            %7D%0A            return false;%0A        %7D%0A    %7D%0A%0A    /**%0A     * get the next SAMRecord%0A     * @return SAMRecord representing the next read%0A     */%0A    public SAMRecord next() %7B%0A        if (!isOpen) %7B%0A            throw new UnsupportedOperationException(%22You cannot call next on a closed iterator%22);%0A        %7D%0A        ++currentCount;%0A        return iterator.next();%0A    %7D%0A%0A    /**%0A     * this is unsupported on SAMRecord iterators%0A     */%0A    public void remove() %7B%0A        throw new UnsupportedOperationException(%22You cannot use an iterator to remove a SAMRecord%22);%0A    %7D%0A%0A    /**%0A     * close the iterator%0A     */%0A    public void close() %7B%0A        isOpen = false;%0A        iterator.close();%0A    %7D%0A%0A    public Iterator%3CSAMRecord%3E iterator() %7B%0A        return this;%0A    %7D%0A%7D%0A

Adding an iterator that bounds the number of reads