- All Implemented Interfaces:
Serializable
,Comparable<MemoryUnit>
,Constable
The
MemoryUnit
provides enumerations for common memory units
alongside conversions to and from memory size specified in bytes.-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
-
Method Summary
Modifier and TypeMethodDescriptionfromBytes
(long aBytes) Calculates the number of bytes for the given value provided for the accordingMemoryUnit
.fromBytes
(BigDecimal aBytes) Calculates the number of bytes for the given value provided for the accordingMemoryUnit
.getBytes()
Returns the number of bytes representing a unit, e.g. 1024 forKILOBYTE
.getUnit()
Returns the name of the memory unit, e.g.toBytes
(double aUnitValue) Calculates the number of bytes for the given value provided for the accordingMemoryUnit
.toBytes
(long aUnitValue) Calculates the number of bytes for the given value provided for the accordingMemoryUnit
.toBytes
(BigDecimal aUnitValue) Calculates the number of bytes for the given value provided for the accordingMemoryUnit
.static MemoryUnit
toSuitableUnit
(long aBytes) Determines the best fitting unit to represent the given number of bytes in terms of "which memory unit is the biggest memory unit of which one unit is smaller than the given amount of bytes".static MemoryUnit
toSuitableUnit
(BigDecimal aBytes) Determines the best fitting unit to represent the given number of bytes in terms of "which memory unit is the biggest memory unit of which one unit is smaller than the given amount of bytes".static MemoryUnit
Returns the enum constant of this class with the specified name.static MemoryUnit[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
BYTE
-
KILOBYTE
-
MEGABYTE
-
GIGABYTE
-
TERABYTE
-
PETABYTE
-
EXABYTE
-
ZETTABYTE
-
YOTTABYTE
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
getUnit
Returns the name of the memory unit, e.g. "KB" for kilobyte or "MB" for megabyte.- Returns:
- The name (abbreviation) of the unit.
-
getBytes
Returns the number of bytes representing a unit, e.g. 1024 forKILOBYTE
.- Returns:
- The number of bytes per unit.
-
toBytes
Calculates the number of bytes for the given value provided for the accordingMemoryUnit
.- Parameters:
aUnitValue
- The value to be converted.- Returns:
- The converted value in bytes.
-
toBytes
Calculates the number of bytes for the given value provided for the accordingMemoryUnit
.- Parameters:
aUnitValue
- The value to be converted.- Returns:
- The converted value in bytes.
-
toBytes
Calculates the number of bytes for the given value provided for the accordingMemoryUnit
.- Parameters:
aUnitValue
- The value to be converted.- Returns:
- The converted value in bytes.
-
fromBytes
Calculates the number of bytes for the given value provided for the accordingMemoryUnit
.- Parameters:
aBytes
- the bytes- Returns:
- The converted value in bytes.
-
fromBytes
Calculates the number of bytes for the given value provided for the accordingMemoryUnit
.- Parameters:
aBytes
- the bytes- Returns:
- The converted value in bytes.
-
toSuitableUnit
Determines the best fitting unit to represent the given number of bytes in terms of "which memory unit is the biggest memory unit of which one unit is smaller than the given amount of bytes".- Parameters:
aBytes
- The number of bytes for which to determine the most suitableMemoryUnit
- Returns:
- The according
MemoryUnit
;
-
toSuitableUnit
Determines the best fitting unit to represent the given number of bytes in terms of "which memory unit is the biggest memory unit of which one unit is smaller than the given amount of bytes".- Parameters:
aBytes
- The number of bytes for which to determine the most suitableMemoryUnit
- Returns:
- The according
MemoryUnit
;
-