code: private static double calculateFillRatio(long totalLength, int size) {
          if (size > 0) {
              return Math.min(1, (double) totalLength / size / BookKeeperConfig.MAX_APPEND_LENGTH);
          } else {
              return 0;
          }
      }
docs: Calculates the FillRatio, which is a number between [0, 1] that represents the average fill of each
  write with respect to the maximum BookKeeper write allowance.
  @param totalLength Total length of the writes.
  @param size Total number of writes.