# Class FilteringVariantContextIterator

java.lang.Object
htsjdk.variant.variantcontext.filter.FilteringVariantContextIterator

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

Direct Known Subclasses:
  `FilteringIterator`

public class FilteringVariantContextIterator extends Object implements CloseableIterator<VariantContext>, Iterable<VariantContext>
A filtering iterator for VariantContexts that takes a base iterator and a VariantContextFilter. The iterator returns all the variantcontexts for which the filter's function "test" returns true (and only those)

## Constructor Summary

Constructors
Constructor
Description
`FilteringVariantContextIterator(Iterator<VariantContext> iterator, VariantContextFilter filter)`
Constructor of an iterator based on the provided iterator and predicate.

## 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.
`Iterator<VariantContext>`
`iterator()`
function to satisfy the Iterable interface
`VariantContext`
`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 Iterable

`forEach, spliterator`

### Methods inherited from interface Iterator

`forEachRemaining`

## Constructor Details

### FilteringVariantContextIterator

public FilteringVariantContextIterator(Iterator<VariantContext> iterator, VariantContextFilter filter)
Constructor of an iterator based on the provided iterator and predicate. The resulting records will be all those VariantContexts from iterator for which filter.test( . ) is true

Parameters:
  `iterator` - the backing iterator
  `filter` - the filter

## Method Details

### 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<VariantContext>`

### hasNext

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

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

### next

public VariantContext next() throws NoSuchElementException
Returns the next element in the iteration.

Specified by:
  `next` in interface `Iterator<VariantContext>`
Returns:
  the next element in the iteration
Throws:
  `NoSuchElementException` - if there are no more elements to return

### remove

public void remove()
Required method for Iterator API.

Specified by:
  `remove` in interface `Iterator<VariantContext>`
Throws:
  `UnsupportedOperationException` - since it is unsupported here.

### iterator

public Iterator<VariantContext> iterator()
function to satisfy the Iterable interface

Specified by:
  `iterator` in interface `Iterable<VariantContext>`
Returns:
  itself since the class inherits from Iterator