# Class FilteringSamIterator

java.lang.Object
htsjdk.samtools.filter.FilteringSamIterator

All Implemented Interfaces:
  `CloseableIterator<SAMRecord>, Closeable, AutoCloseable, Iterator<SAMRecord>`

Direct Known Subclasses:
  `FilteringIterator`

public class FilteringSamIterator extends Object implements CloseableIterator<SAMRecord>
Filtering Iterator which takes a filter and an iterator and iterates through only those records which are not rejected by the filter.

$Id$

## Constructor Summary

Constructors
Constructor
Description
`FilteringSamIterator(Iterator<SAMRecord> iterator, SamRecordFilter filter)`
Constructor
`FilteringSamIterator(Iterator<SAMRecord> iterator, SamRecordFilter filter, boolean filterByPair)`
Constructor

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
Should be implemented to close/release any underlying resources.
`boolean`
`hasNext()`
Returns true if the iteration has more elements.
`SAMRecord`
`next()`
Returns the next element in the iteration.
`void`
`remove()`
Required method for Iterator API.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface CloseableIterator

`stream, toList`

### Methods inherited from interface Iterator

`forEachRemaining`

## Constructor Details

### FilteringSamIterator

public FilteringSamIterator(Iterator<SAMRecord> iterator, SamRecordFilter filter, boolean filterByPair)
Constructor

Parameters:
  `iterator` - the backing iterator
  `filter` - the filter (which may be a FilterAggregator)
  `filterByPair` - if true, filter reads in pairs

### FilteringSamIterator

public FilteringSamIterator(Iterator<SAMRecord> iterator, SamRecordFilter filter)
Constructor

Parameters:
  `iterator` - the backing iterator
  `filter` - the filter (which may be a FilterAggregator)

## Method Details

### hasNext

public boolean hasNext()
Returns true if the iteration has more elements.

Specified by:
  `hasNext` in interface `Iterator<SAMRecord>`
Returns:
  true if the iteration has more elements. Otherwise returns false.

### next

public SAMRecord next()
Returns the next element in the iteration.

Specified by:
  `next` in interface `Iterator<SAMRecord>`
Returns:
  the next element in the iteration
Throws:
  `NoSuchElementException`

### remove

public void remove()
Required method for Iterator API.

Specified by:
  `remove` in interface `Iterator<SAMRecord>`
Throws:
  `UnsupportedOperationException`

### close

public void close()
Description copied from interface: `CloseableIterator`
Should be implemented to close/release any underlying resources.

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `CloseableIterator<SAMRecord>`