File size: 1,524 Bytes
d46f4a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.mojang.realmsclient;

import java.util.Locale;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public enum Unit {
    B,
    KB,
    MB,
    GB;

    private static final int BASE_UNIT = 1024;

    public static Unit getLargest(long p_86941_) {
        if (p_86941_ < 1024L) {
            return B;
        } else {
            try {
                int i = (int)(Math.log((double)p_86941_) / Math.log(1024.0));
                String s = String.valueOf("KMGTPE".charAt(i - 1));
                return valueOf(s + "B");
            } catch (Exception exception) {
                return GB;
            }
        }
    }

    public static double convertTo(long p_86943_, Unit p_86944_) {
        return p_86944_ == B ? (double)p_86943_ : (double)p_86943_ / Math.pow(1024.0, (double)p_86944_.ordinal());
    }

    public static String humanReadable(long p_86946_) {
        int i = 1024;
        if (p_86946_ < 1024L) {
            return p_86946_ + " B";
        } else {
            int j = (int)(Math.log((double)p_86946_) / Math.log(1024.0));
            String s = "KMGTPE".charAt(j - 1) + "";
            return String.format(Locale.ROOT, "%.1f %sB", (double)p_86946_ / Math.pow(1024.0, (double)j), s);
        }
    }

    public static String humanReadable(long p_86948_, Unit p_86949_) {
        return String.format(Locale.ROOT, "%." + (p_86949_ == GB ? "1" : "0") + "f %s", convertTo(p_86948_, p_86949_), p_86949_.name());
    }
}