HBASE-23967 Improve the accuracy of the method sizeToString (#1273)

Signed-off-by: Viraj Jasani <vjasani@apache.org>
Signed-off-by: Jan Hentschel <jan.hentschel@ultratendency.com>
This commit is contained in:
xuqinya1 2020-03-13 22:11:48 +08:00 committed by GitHub
parent 1b163d98b9
commit b9e74e0b0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 6 deletions

View File

@ -173,12 +173,22 @@ public abstract class QuotaSettings {
}
protected static String sizeToString(final long size) {
if (size >= (1L << 50)) return String.format("%dP", size / (1L << 50));
if (size >= (1L << 40)) return String.format("%dT", size / (1L << 40));
if (size >= (1L << 30)) return String.format("%dG", size / (1L << 30));
if (size >= (1L << 20)) return String.format("%dM", size / (1L << 20));
if (size >= (1L << 10)) return String.format("%dK", size / (1L << 10));
return String.format("%dB", size);
if (size >= (1L << 50)) {
return String.format("%.2fP", (double)size / (1L << 50));
}
if (size >= (1L << 40)) {
return String.format("%.2fT", (double)size / (1L << 40));
}
if (size >= (1L << 30)) {
return String.format("%.2fG", (double)size / (1L << 30));
}
if (size >= (1L << 20)) {
return String.format("%.2fM", (double)size / (1L << 20));
}
if (size >= (1L << 10)) {
return String.format("%.2fK", (double)size / (1L << 10));
}
return String.format("%.2fB", (double)size);
}
protected static String timeToString(final TimeUnit timeUnit) {