package emergencylanding.k.library.debug;

import k.core.util.Helper;

public class Memory {
    private static long lastF = Memory.getFree();
    private static long lastM = Memory.getMax();
    private static long lastT = Memory.getTotal();

    private Memory() {
        System.out.println("AHEM! Don't create this class!");
        byte[] chrs = "POTATO".getBytes();
        int res = 0;
        for (byte b : chrs) {
            res += b;
        }
        System.exit(res);
    }

    public static void printFree() {
        long free = Memory.getFree();
        System.out.println("FREE_MEM: " + free);
        Memory.lastF = free;
    }

    public static void printMax() {
        long max = Memory.getMax();
        System.out.println("MAX_MEM: " + max);
        Memory.lastM = max;
    }

    public static void printTotal() {
        long total = Memory.getTotal();
        System.out.println("TOTAL_MEM: " + total);
        Memory.lastT = total;
    }

    public static long getFree() {
        return Runtime.getRuntime().freeMemory();
    }

    public static long getMax() {
        return Runtime.getRuntime().maxMemory();
    }

    public static long getTotal() {
        return Runtime.getRuntime().totalMemory();
    }

    public static void printAll() {
        Memory.printFree();
        Memory.printMax();
        Memory.printTotal();
    }

    public static void comparePrint() {
        String[] lines = new String[3];
        if (Memory.getFree() < Memory.lastF) {
            lines[0] = "Free memory is less.";
        } else {
            lines[0] = "Free memory is more!";
        }

        if (Memory.getMax() < Memory.lastM) {
            lines[1] = "Max memory is less.";
        } else {
            lines[1] = "Max memory is more!";
        }

        if (Memory.getTotal() < Memory.lastT) {
            lines[2] = "Total memory is less.";
        } else {
            lines[2] = "Total memory is more!";
        }
        Helper.BetterArrays.dump(lines);
    }

    public static void gc() {
        System.gc();
    }

}

@@ -272,211 +272,33 @@
     
-System.out.println(%22AHEM! Don't create this class!%22);%0A        byte%5B%5D chrs = %22POTATO%22.getBytes();%0A        int res = 0;%0A        for (byte b : chrs) %7B%0A            res += b;%0A        %7D%0A        System.exit(res
+throw new AssertionError(
 );%0A 

Throw error instead of exiting