Merge branch 'stable-2.15'

* stable-2.15:
  ChangeData#isReviewedBy: Guard against null current patch set
  Revert "GetCapabilities#CheckOne: Return json content type"
  FormatUtil: Correctly fix the Math#round() error flagged by error-prone
  Add a change deleted event/listener
  Fix broken link in documentation of receive.requireSignedPush

Change-Id: I57f595d1081f436187df4b73a37a4366cc66196b
This commit is contained in:
Jonathan Nieder
2018-09-16 17:27:18 -07:00
16 changed files with 206 additions and 38 deletions

View File

@@ -126,25 +126,7 @@ public class FormatUtil {
if (size == 0) {
return Resources.C.notAvailable();
}
int p = Math.abs(saturatedCast(delta * 100 / size));
return p + "%";
}
/**
* Returns the {@code int} nearest in value to {@code value}.
*
* @param value any {@code long} value
* @return the same value cast to {@code int} if it is in the range of the {@code int} type,
* {@link Integer#MAX_VALUE} if it is too large, or {@link Integer#MIN_VALUE} if it is too
* small
*/
private static int saturatedCast(long value) {
if (value > Integer.MAX_VALUE) {
return Integer.MAX_VALUE;
}
if (value < Integer.MIN_VALUE) {
return Integer.MIN_VALUE;
}
return (int) value;
long percentage = Math.abs(Math.round(delta * 100.0 / size));
return percentage + "%";
}
}