eu.ciechanowiec.sling.rocket.unit.DataUnit Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sling.rocket.commons Show documentation
Show all versions of sling.rocket.commons Show documentation
Common utilities used by Sling Rocket
package eu.ciechanowiec.sling.rocket.unit;
import java.util.function.UnaryOperator;
/**
* Units of digital information.
*
*
* Data Unit Sizes
*
* Constant
* Data size
* Power of 2
* Size in Bytes
*
*
* {@link DataUnit#BYTES}
* 1B
* 2^0
* 1
*
*
* {@link DataUnit#KILOBYTES}
* 1KB
* 2^10
* 1,024
*
*
* {@link DataUnit#MEGABYTES}
* 1MB
* 2^20
* 1,048,576
*
*
* {@link DataUnit#GIGABYTES}
* 1GB
* 2^30
* 1,073,741,824
*
*
* {@link DataUnit#TERABYTES}
* 1TB
* 2^40
* 1,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