package com.mojang.realmsclient;

import java.util.Locale;

public enum Unit {
    B, 
    KB, 
    MB, 
    GB;
    
    public static Unit getLargest(final long long1) {
        if (long1 < 1024L) {
            return Unit.B;
        }
        try {
            final int integer3 = (int)(Math.log((double)long1) / Math.log(1024.0));
            final String string4 = String.valueOf("KMGTPE".charAt(integer3 - 1));
            return valueOf(string4 + "B");
        }
        catch (Exception exception3) {
            return Unit.GB;
        }
    }
    
    public static double convertTo(final long long1, final Unit dhw) {
        if (dhw == Unit.B) {
            return (double)long1;
        }
        return long1 / Math.pow(1024.0, dhw.ordinal());
    }
    
    public static String humanReadable(final long long1) {
        final int integer3 = 1024;
        if (long1 < 1024L) {
            return long1 + " B";
        }
        final int integer4 = (int)(Math.log((double)long1) / Math.log(1024.0));
        final String string5 = "KMGTPE".charAt(integer4 - 1) + "";
        return String.format(Locale.ROOT, "%.1f %sB", long1 / Math.pow(1024.0, integer4), string5);
    }
    
    public static String humanReadable(final long long1, final Unit dhw) {
        return String.format("%." + ((dhw == Unit.GB) ? "1" : "0") + "f %s", convertTo(long1, dhw), dhw.name());
    }
}
