bt.torrent.messaging.IncompletePiecesValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bt-core Show documentation
Show all versions of bt-core Show documentation
BitTorrent Client Library (Core)
package bt.torrent.messaging;
import bt.data.Bitfield;
import java.util.function.Predicate;
public class IncompletePiecesValidator implements Predicate {
private Bitfield bitfield;
public IncompletePiecesValidator(Bitfield bitfield) {
this.bitfield = bitfield;
}
@Override
public boolean test(Integer pieceIndex) {
return !isComplete(pieceIndex);
}
private boolean isComplete(Integer pieceIndex) {
Bitfield.PieceStatus pieceStatus = bitfield.getPieceStatus(pieceIndex);
return pieceStatus == Bitfield.PieceStatus.COMPLETE || pieceStatus == Bitfield.PieceStatus.COMPLETE_VERIFIED;
}
}