package org.zstack.utils.data;

public enum SizeUnit {
    BYTE {
        public long toByte(long s) {
            return s;
        }

        public long toKiloByte(long s) {
            return (s / (k / b));
        }

        public long toMegaByte(long s) {
            return (s / (m / b));
        }

        public long toGigaByte(long s) {
            return (s / (g / b));
        }

        public long toTeraByte(long s) {
            return (s / (t / b));
        }
    },
    KILOBYTE {
        public long toByte(long s) {
            return (s * (k / b));
        }

        public long toKiloByte(long s) {
            return s;
        }

        public long toMegaByte(long s) {
            return (s / (m / k));
        }

        public long toGigaByte(long s) {
            return (s / (g / k));
        }

        public long toTeraByte(long s) {
            return (s / (t / k));
        }
    },
    MEGABYTE {
        public long toByte(long s) {
            return (s * (m / b));
        }

        public long toKiloByte(long s) {
            return (s * (m / k));
        }

        public long toMegaByte(long s) {
            return s;
        }

        public long toGigaByte(long s) {
            return (s / (g / m));
        }

        public long toTeraByte(long s) {
            return (s / (t / m));
        }
    },
    GIGABYTE {
        public long toByte(long s) {
            return (s * (g / b));
        }

        public long toKiloByte(long s) {
            return (s * (g / k));
        }

        public long toMegaByte(long s) {
            return (s * (g / m));
        }

        public long toGigaByte(long s) {
            return s;
        }

        public long toTeraByte(long s) {
            return (s / (t / g));
        }
    },
    TERABYTE {
        public long toByte(long s) {
            return (s * (t / b));
        }

        public long toKiloByte(long s) {
            return (s * (t / k));
        }

        public long toMegaByte(long s) {
            return (s * (t / m));
        }

        public long toGigaByte(long s) {
            return (s * (t / g));
        }

        public long toTeraByte(long s) {
            return s;
        }
    };

    private static final long b = 1;
    private static final long k = b * 1024;
    private static final long m = k * 1024;
    private static final long g = m * 1024;
    private static final long t = g * 1024;
    
    public long toByte(long s) {
        throw new AbstractMethodError();
    }
    public long toKiloByte(long s) {
        throw new AbstractMethodError();
    }
    public long toMegaByte(long s) {
        throw new AbstractMethodError();        
    }
    public long toGigaByte(long s) {
        throw new AbstractMethodError();
    }
    public long toTeraByte(long s) {
        throw new AbstractMethodError();
    }
}

@@ -486,32 +486,133 @@
 b));%0D%0A        %7D%0D
+%0A%0D%0A        public long convert(long s, SizeUnit src) %7B%0D%0A            return src.toByte(s);%0D%0A        %7D%0D
 %0A    %7D,%0D%0A    KIL
@@ -1043,32 +1043,137 @@
 k));%0D%0A        %7D%0D
+%0A%0D%0A        public long convert(long s, SizeUnit src) %7B%0D%0A            return src.toKiloByte(s);%0D%0A        %7D%0D
 %0A    %7D,%0D%0A    MEG
@@ -1604,32 +1604,137 @@
 m));%0D%0A        %7D%0D
+%0A%0D%0A        public long convert(long s, SizeUnit src) %7B%0D%0A            return src.toMegaByte(s);%0D%0A        %7D%0D
 %0A    %7D,%0D%0A    GIG
@@ -2165,32 +2165,137 @@
 g));%0D%0A        %7D%0D
+%0A%0D%0A        public long convert(long s, SizeUnit src) %7B%0D%0A            return src.toGigaByte(s);%0D%0A        %7D%0D
 %0A    %7D,%0D%0A    TER
@@ -2730,24 +2730,129 @@
 %0D%0A        %7D%0D
+%0A%0D%0A        public long convert(long s, SizeUnit src) %7B%0D%0A            return src.toTeraByte(s);%0D%0A        %7D%0D
 %0A    %7D;%0D%0A%0D%0A 
@@ -3418,32 +3418,32 @@
 rror();%0D%0A    %7D%0D%0A
-
     public long 
@@ -3513,11 +3513,109 @@
 %0A    %7D%0D%0A
+    public long convert(long s, SizeUnit src) %7B%0D%0A        throw new AbstractMethodError();%0D%0A    %7D%0D%0A
 %7D%0D%0A

add convert() to SizeUnit