package edu.mit.broad.sam; import edu.mit.broad.sam.util.CloseableIterator; import edu.mit.broad.sam.util.NonDestructiveIterator; /** * Wrapper around SAMRecord iterator that skips over non-primary elements. */ public class NotPrimarySkippingIterator { private final NonDestructiveIterator> it; public NotPrimarySkippingIterator(final CloseableIterator underlyingIt) { it = new NonDestructiveIterator>(underlyingIt); skipAnyNotprimary(); } public boolean hasCurrent() { return it.hasCurrent(); } public SAMRecord getCurrent() { assert(hasCurrent()); return it.getCurrent(); } public boolean advance() { it.advance(); skipAnyNotprimary(); return hasCurrent(); } private void skipAnyNotprimary() { while (it.hasCurrent() && it.getCurrent().getNotPrimaryAlignmentFlag()) { it.advance(); } } }