int last_piece_number = -1;
for (int i=0;i<requests.size();i++){
PeerReadRequest request = (PeerReadRequest)requests.get(i);
int this_piece_number = request.getPieceNumber();
if ( last_piece_number != -1 && last_piece_number != this_piece_number ){
if ( !getRequestCanSpanPieces()){
return( i );
}
}
long this_start = this_piece_number * torrent.getPieceSize() + request.getOffset();
if ( next_start != -1 && this_start != next_start ){
return(i);
}
next_start = this_start + request.getLength();
last_piece_number = this_piece_number;
}
return( requests.size());