All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eu.ciechanowiec.sling.rocket.unit.DataUnit Maven / Gradle / Ivy

There is a newer version: 13.32.0
Show newest version
package eu.ciechanowiec.sling.rocket.unit;

import java.util.function.UnaryOperator;

/**
 * Units of digital information.
 *
 * 
 *   
 *   
 *     
 *     
 *     
 *     
 *   
 *   
 *     
 *     
 *     
 *     
 *   
 *   
 *     
 *     
 *     
 *     
 *   
 *   
 *     
 *     
 *     
 *     
 *   
 *   
 *     
 *     
 *     
 *     
 *   
 *   
 *     
 *     
 *     
 *     
 *   
 * 
Data Unit Sizes
ConstantData sizePower of 2Size in Bytes
{@link DataUnit#BYTES}1B2^01
{@link DataUnit#KILOBYTES}1KB2^101,024
{@link DataUnit#MEGABYTES}1MB2^201,048,576
{@link DataUnit#GIGABYTES}1GB2^301,073,741,824
{@link DataUnit#TERABYTES}1TB2^401,099,511,627,776
*/ public enum DataUnit { /** * Bytes (B). */ BYTES(UnaryOperator.identity()), /** * Kilobytes (KB). */ KILOBYTES(kilobytes -> Math.multiplyExact(kilobytes, DataUnitMultiplications.BYTES_PER_KB)), /** * Megabytes (MB). */ MEGABYTES(megabytes -> Math.multiplyExact(megabytes, DataUnitMultiplications.BYTES_PER_MB)), /** * Gigabytes (GB). */ GIGABYTES(gigabytes -> Math.multiplyExact(gigabytes, DataUnitMultiplications.BYTES_PER_GB)), /** * Terabytes (TB). */ TERABYTES(terabytes -> Math.multiplyExact(terabytes, DataUnitMultiplications.BYTES_PER_TB)); private final UnaryOperator toBytes; DataUnit(UnaryOperator toBytes) { this.toBytes = toBytes; } long toBytes(long size) { return toBytes.apply(size); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy