@Override
  public PieceState getPieceState(int piece) {
    long pieceStart = piece * pieceSize;
    long pieceEnd = Math.max(0, Math.min(pieceStart + pieceSize, length) - 1);
    Range range = Range.createRange(pieceStart, pieceEnd);
    PieceState state;

    if (written.contains(range)) {
      state = PieceState.DOWNLOADED;
    } else if (active.containsAny(range)) {
      state = PieceState.ACTIVE;
    } else if (available.contains(range)) {
      if (written.containsAny(range)) {
        state = PieceState.PARTIAL;
      } else {
        state = PieceState.AVAILABLE;
      }
    } else {
      state = PieceState.UNAVAILABLE;
    }

    return state;
  }
 public void blockUnpending(SwarmCoordinator swarmCoordinator, Range block) {
   System.out.println("block unpending: " + block.toString() + "/" + block.getLength());
 }
 public void blockWritten(SwarmCoordinator swarmCoordinator, Range block) {
   System.out.println("block written: " + block.toString() + "/" + block.getLength());
 }
 public void blockVerified(SwarmCoordinator swarmCoordinator, Range block) {
   System.out.println("block verified: " + block.toString() + "/" + block.getLength());
 }