use of htsjdk.samtools.util.AbstractIterator in project jvarkit by lindenb.
the class VcfIterator method filter.
/**
* wrap as a filtering iterator
*/
public static VcfIterator filter(final VcfIterator delegate, final Predicate<VariantContext> predicate) {
class FilteringVcfIterator extends AbstractIterator<VariantContext> implements VcfIterator {
private final VcfIterator delegate;
private final Predicate<VariantContext> predicate;
FilteringVcfIterator(final VcfIterator delegate, final Predicate<VariantContext> predicate) {
this.delegate = delegate;
this.predicate = predicate;
}
@Override
public AbstractVCFCodec getCodec() {
return this.delegate.getCodec();
}
@Override
public VCFHeader getHeader() {
return this.delegate.getHeader();
}
@Override
public void close() throws IOException {
this.delegate.close();
}
@Override
protected VariantContext advance() {
while (this.delegate.hasNext()) {
final VariantContext ctx = this.delegate.next();
if (this.predicate.test(ctx))
return ctx;
;
}
return null;
}
}
return new FilteringVcfIterator(delegate, predicate);
}
Aggregations