# Class SamRecordTrackingBuffer<T extends SamRecordWithOrdinal>

java.lang.Object
htsjdk.samtools.util.SamRecordTrackingBuffer<T>

public class SamRecordTrackingBuffer<T extends SamRecordWithOrdinal> extends Object
This class stores SAMRecords for return. The purpose of this class is to buffer records that need to be modified or processed in some fashion, and only return (or emit) them when they have been recorded as being fully examined. If we have too many records in RAM, we can spill over to disk. The order in which they are given (via SamRecordWithOrdinal) determines their order of being returned. It is the responsibility of the user of this class to make sure all records have unique index and are added in order. When a record is examined, we also store a result state. This is currently a boolean to reduce on memory and disk footprint. We store groups of records in blocks and the size of these blocks can be controlled. If we have too many records in RAM, we start spilling blocks to disk. Users should check isEmpty() to see if any records are still being tracked. If so, they should check canEmit() to see if the next record can be returned. If so, they can call next() to get that record. When users are done with this structure, call close().

## Constructor Summary

Constructors
Constructor
Description
`SamRecordTrackingBuffer(int maxRecordsInRam, int blockSize, List<File> tmpDirs, SAMFileHeader header, Class<T> clazz)`

## Method Summary

Modifier and Type
Method
Description
`void`
`add(SamRecordWithOrdinal samRecordWithOrdinal)`
Add the given SAMRecordIndex to the buffer.
`boolean`
`canEmit()`
Returns true if we can return the next record (it has been examined).
`void`
`close()`
Close IO resources associated with each underlying BufferBlock
`boolean`
`contains(SamRecordWithOrdinal samRecordWithOrdinal)`
Returns true if this buffer contains the record at the given index, false otherwise
`boolean`
`isEmpty()`
Returns true if we are tracking no records, false otherwise
`SamRecordWithOrdinal`
`next()`
Returns the next element in the iteration.
`void`
`remove()`
Removes the next record from this buffer
`void`
`setResultState(SamRecordWithOrdinal samRecordWithOrdinal, boolean resultState)`
Mark the current samRecordWithOrdinal as having been examined.
`long`
`size()`
Return the total number of elements in the queue, both in memory and on disk

### Methods inherited from class Object

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

## Constructor Details

### SamRecordTrackingBuffer

public SamRecordTrackingBuffer(int maxRecordsInRam, int blockSize, List<File> tmpDirs, SAMFileHeader header, Class<T> clazz)

Parameters:
  `maxRecordsInRam` - how many records to buffer before spilling to disk
  `blockSize` - the number of records in a given block
  `tmpDirs` - the temporary directories to use when spilling to disk
  `header` - the header
  `clazz` - the class that extends SamRecordWithOrdinal

## Method Details

### isEmpty

public boolean isEmpty()
Returns true if we are tracking no records, false otherwise

### canEmit

public boolean canEmit()
Returns true if we can return the next record (it has been examined).

### add

public void add(SamRecordWithOrdinal samRecordWithOrdinal)
Add the given SAMRecordIndex to the buffer. The records must be added in order.

Parameters:
  `samRecordWithOrdinal` - The samRecordWithOrdinal to be added

### next

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

Returns:
  The next element in the iteration.
Throws:
  `NoSuchElementException` - if the buffer is empty.
  `SAMException` - if the buffer is not competent to emit (canEmit returns false)

### remove

public void remove()
Removes the next record from this buffer

### size

public long size()
Return the total number of elements in the queue, both in memory and on disk

### contains

public boolean contains(SamRecordWithOrdinal samRecordWithOrdinal)
Returns true if this buffer contains the record at the given index, false otherwise

### setResultState

public void setResultState(SamRecordWithOrdinal samRecordWithOrdinal, boolean resultState)
Mark the current samRecordWithOrdinal as having been examined.

Parameters:
  `samRecordWithOrdinal` - The samRecordWithOrdinal to be marked
  `resultState` - Boolean flag indicating the result of the examination of this record.
Throws:
  `SAMException` - if the provided recordIndex is not found within the SamRecordTrackingBuffer

### close

public void close()
Close IO resources associated with each underlying BufferBlock