diff options
Diffstat (limited to 'spark-common/src/main/java/me/lucko/spark')
-rw-r--r-- | spark-common/src/main/java/me/lucko/spark/common/monitor/tick/TickStatistics.java | 2 | ||||
-rw-r--r-- | spark-common/src/main/java/me/lucko/spark/common/util/FormatUtil.java | 5 |
2 files changed, 4 insertions, 3 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/monitor/tick/TickStatistics.java b/spark-common/src/main/java/me/lucko/spark/common/monitor/tick/TickStatistics.java index c91ceae..a6265c8 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/monitor/tick/TickStatistics.java +++ b/spark-common/src/main/java/me/lucko/spark/common/monitor/tick/TickStatistics.java @@ -141,7 +141,7 @@ public class TickStatistics implements TickHook.Callback, TickReporter.Callback /** - * Rolling average calculator taken. + * Rolling average calculator. * * <p>This code is taken from PaperMC/Paper, licensed under MIT.</p> * diff --git a/spark-common/src/main/java/me/lucko/spark/common/util/FormatUtil.java b/spark-common/src/main/java/me/lucko/spark/common/util/FormatUtil.java index 8713678..492d4ea 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/util/FormatUtil.java +++ b/spark-common/src/main/java/me/lucko/spark/common/util/FormatUtil.java @@ -23,6 +23,8 @@ package me.lucko.spark.common.util; public enum FormatUtil { ; + private static final String[] SIZE_UNITS = {"bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}; + public static String percent(double value, double max) { double percent = (value * 100d) / max; return (int) percent + "%"; @@ -32,8 +34,7 @@ public enum FormatUtil { if (bytes == 0) { return "0 bytes"; } - String[] sizes = new String[]{"bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}; int sizeIndex = (int) (Math.log(bytes) / Math.log(1024)); - return String.format("%.1f", bytes / Math.pow(1024, sizeIndex)) + " " + sizes[sizeIndex]; + return String.format("%.1f", bytes / Math.pow(1024, sizeIndex)) + " " + SIZE_UNITS[sizeIndex]; } } |