public class Bitfield extends Object
| Constructor and Description |
|---|
Bitfield(int size) |
| Modifier and Type | Method and Description |
|---|---|
int |
countHavePieces()
Goes through the bitfieldBytes and checks how many pieces the client has
|
byte[] |
getBytes()
Returns a copy of the internal byte array
|
boolean |
hasPiece(int pieceIndex)
Checks the bitfieldBytes if we have the given piece
|
void |
havePiece(int pieceIndex)
Notify that we have the given piece
This will update the bitfieldBytes to bitwise OR the bit to 1 |
void |
havePiece(int pieceIndex,
boolean mayExpand)
Notify that we have the given piece
This will update the bitfieldBytes to bitwise OR the bit to 1 |
void |
setSize(int size)
Increases or decreased the bitfieldBytes size but it will preserve the old data
|
public void setSize(int size)
size - The new size to grow/shrink topublic boolean hasPiece(int pieceIndex)
pieceIndex - the piece to checkpublic void havePiece(int pieceIndex)
pieceIndex - The piece to addpublic void havePiece(int pieceIndex,
boolean mayExpand)
pieceIndex - The piece to addmayExpand - If the bitfieldBytes may grow to fit the new have datapublic byte[] getBytes()
public int countHavePieces()
Copyright © 2016. All rights reserved.