package ai.subut.kurjun.quota;


/**
 * Digital information unit. Can be used to express data amount in disk, data transferred per time, etc.
 *
 */
public enum DataUnit
{

    /**
     * Byte.
     */
    BYTE( 1L ),
    /**
     * Kilobyte.
     */
    KB( 1L << 10 ),
    /**
     * Megabyte.
     */
    MB( 1L << 20 ),
    /**
     * Gigabyte.
     */
    GB( 1L << 30 ),
    /**
     * Terabyte.
     */
    TB( 1L << 40 );

    private long bytes;


    private DataUnit( long bytes )
    {
        this.bytes = bytes;
    }


    public long toBytes()
    {
        return bytes;
    }


}


@@ -589,11 +589,499 @@
     %7D%0A%0A%0A
+    /**%0A     * Gets enum instance that corresponds to supplied string. String comparison is case-insensitive.%0A     *%0A     * @param s%0A     * @return enum that corresponds to supplied string, if there is one; %7B@code null%7D otherwise%0A     */%0A    public static DataUnit getByName( String s )%0A    %7B%0A        for ( DataUnit u : values() )%0A        %7B%0A            if ( u.toString().equalsIgnoreCase( s ) )%0A            %7B%0A                return u;%0A            %7D%0A        %7D%0A        return null;%0A    %7D%0A%0A%0A
 %7D%0A%0A

add method to get data unit by its name