# Class Bin

java.lang.Object
htsjdk.samtools.Bin

All Implemented Interfaces:
  `Comparable<Bin>`

Direct Known Subclasses:
  `BinWithOffset`

public class Bin extends Object implements Comparable<Bin>
An individual bin in a BAM file.

## Constructor Summary

Constructors
Constructor
Description
`Bin(int referenceSequence, int binNumber)`

## Method Summary

Modifier and Type
Method
Description
`void`
`addChunk(Chunk newChunk)`
Adds a chunk to the bin (may be the first chunk or a later one).
`void`
`addInitialChunk(Chunk newChunk)`
Adds the first chunk to the bin
`int`
`compareTo(Bin other)`
Compare two bins to see what ordering they should appear in.
`boolean`
`containsChunks()`
Returns whether the bin currently contains chunks.
`boolean`
`equals(Object other)`
See whether two bins are equal.
`int`
`getBinNumber()`
`List<Chunk>`
`getChunkList()`
Gets the list of chunks associated with this bin.
`Chunk`
`getLastChunk()`
Warning: Currently only valid during index building, not when reading existing index, (AbstractBAMFileIndex.optimizeChunkList doesn't maintain this)
`protected int`
`getReferenceSequence()`
`int`
`hashCode()`
Compute a unique hash code for the given reference sequence and bin number.
`void`
`setChunkList(List<Chunk> list)`
Sets the chunks associated with this bin
`void`
`setLastChunk(Chunk c)`
Optimization to keep lastChunk instead of iterating over all chunks repeatedly

### Methods inherited from class Object

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

## Constructor Details

### Bin

public Bin(int referenceSequence, int binNumber)

## Method Details

### getReferenceSequence

protected int getReferenceSequence()

### getBinNumber

public int getBinNumber()

### equals

public boolean equals(Object other)
See whether two bins are equal. If the ref seq and the bin number are equal, assume equality of the chunk list.

Overrides:
  `equals` in class `Object`
Parameters:
  `other` - The other Bin to which to compare this.
Returns:
  True if the two bins are equal. False otherwise.

### hashCode

public int hashCode()
Compute a unique hash code for the given reference sequence and bin number.

Overrides:
  `hashCode` in class `Object`
Returns:
  A unique hash code.

### containsChunks

public boolean containsChunks()
Returns whether the bin currently contains chunks.

Returns:
  True if the bin has chunks, false otherwise.

### compareTo

public int compareTo(Bin other)
Compare two bins to see what ordering they should appear in.

Specified by:
  `compareTo` in interface `Comparable<Bin>`
Parameters:
  `other` - Other bin to which this bin should be compared.
Returns:
  `-1 if this < other, 0 if this == other, 1 if this > other`.

### addInitialChunk

public void addInitialChunk(Chunk newChunk)
Adds the first chunk to the bin

### addChunk

public void addChunk(Chunk newChunk)
Adds a chunk to the bin (may be the first chunk or a later one).

Parameters:
  `newChunk` - the chunk to add

### setChunkList

public void setChunkList(List<Chunk> list)
Sets the chunks associated with this bin

### getChunkList

public List<Chunk> getChunkList()
Gets the list of chunks associated with this bin.

Returns:
  the chunks in this bin. If no chunks are associated, an empty list will be returned.

### setLastChunk

public void setLastChunk(Chunk c)
Optimization to keep lastChunk instead of iterating over all chunks repeatedly

### getLastChunk

public Chunk getLastChunk()
Warning: Currently only valid during index building, not when reading existing index, (AbstractBAMFileIndex.optimizeChunkList doesn't maintain this)

Returns:
  the last Chunk of the chunkList