From b38e0c7b603fe407869910bffd270844a75fcbfd Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sun, 29 Mar 2020 21:22:31 +0200 Subject: [PATCH] improve MemoryUtil --- .../fr/pandacube/util/MinecraftWebUtil.java | 2 +- .../util/measurement/MemoryUtil.java | 74 +++++++++++++++---- 2 files changed, 59 insertions(+), 17 deletions(-) diff --git a/src/main/java/fr/pandacube/util/MinecraftWebUtil.java b/src/main/java/fr/pandacube/util/MinecraftWebUtil.java index 2724522..bf0a0f3 100644 --- a/src/main/java/fr/pandacube/util/MinecraftWebUtil.java +++ b/src/main/java/fr/pandacube/util/MinecraftWebUtil.java @@ -24,7 +24,7 @@ public class MinecraftWebUtil { if (c == code_prefix && (i= 0; ui--) { + MemoryUnit u = MemoryUnit.values()[ui]; + if (u == roundTo) + break; + if (size < u.value(si)) + continue; + unit = u; + break; + } + + String dispValue; + if (unit == roundTo) { + dispValue = ""+unit.toUnitRound(size, si); + } + else { + dispValue = format.format(unit.toUnit(size, si)); + } + + return (neg ? "-" : "") + dispValue + unit.unit(si); } public static String humanReadableSize(long octet) { - return humanReadableSize(octet, false); + return humanReadableSize(octet, MemoryUnit.B, false); } + }