private long decrementRemainingAllocationUnits(long units) {
    Preconditions.checkState(!closed);

    if (remainingAllocationUnits >= units) {
      remainingAllocationUnits -= units;
      return units;
    }

    long actualDecrement = remainingAllocationUnits;
    remainingAllocationUnits = 0;
    return actualDecrement;
  }
Decrements remaining allocation units by {@code units} but no more than the remaining
allocation units (which may be 0). Returns the actual units decremented, which never exceeds
{@code units}.

@param units units to decrement
@return units actually decremented
jib-core/src/main/java/com/google/cloud/tools/jib/builder/ProgressEventDispatcher.java