- java.lang.Object
-
- java.lang.Enum<MemoryUnit>
-
- org.refcodes.data.MemoryUnit
-
- All Implemented Interfaces:
Serializable
,Comparable<MemoryUnit>
public enum MemoryUnit extends Enum<MemoryUnit>
TheMemoryUnit
provides enumerations for common memory units alongside conversions to and from memory size specified in bytes.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description BigDecimal
fromBytes(long aBytes)
Calculates the number of bytes for the given value provided for the accordingMemoryUnit
.BigDecimal
fromBytes(BigDecimal aBytes)
Calculates the number of bytes for the given value provided for the accordingMemoryUnit
.BigDecimal
getBytes()
Returns the number of bytes representing a unit, e.g. 1024 forKILOBYTE
.String
getUnit()
Returns the name of the memory unit, e.g.BigDecimal
toBytes(double aUnitValue)
Calculates the number of bytes for the given value provided for the accordingMemoryUnit
.BigDecimal
toBytes(long aUnitValue)
Calculates the number of bytes for the given value provided for the accordingMemoryUnit
.BigDecimal
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
valueOf(String name)
Returns the enum constant of this type with the specified name.static MemoryUnit[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
BYTE
public static final MemoryUnit BYTE
-
KILOBYTE
public static final MemoryUnit KILOBYTE
-
MEGABYTE
public static final MemoryUnit MEGABYTE
-
GIGABYTE
public static final MemoryUnit GIGABYTE
-
TERABYTE
public static final MemoryUnit TERABYTE
-
PETABYTE
public static final MemoryUnit PETABYTE
-
EXABYTE
public static final MemoryUnit EXABYTE
-
ZETTABYTE
public static final MemoryUnit ZETTABYTE
-
YOTTABYTE
public static final MemoryUnit YOTTABYTE
-
-
Method Detail
-
values
public static MemoryUnit[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (MemoryUnit c : MemoryUnit.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static MemoryUnit valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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 type has no constant with the specified nameNullPointerException
- if the argument is null
-
getUnit
public String 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
public BigDecimal getBytes()
Returns the number of bytes representing a unit, e.g. 1024 forKILOBYTE
.- Returns:
- The number of bytes per unit.
-
toBytes
public BigDecimal toBytes(double aUnitValue)
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
public BigDecimal toBytes(BigDecimal aUnitValue)
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
public BigDecimal toBytes(long aUnitValue)
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
public BigDecimal fromBytes(long aBytes)
Calculates the number of bytes for the given value provided for the accordingMemoryUnit
.- Parameters:
aBytes
- the bytes- Returns:
- The converted value in bytes.
-
fromBytes
public BigDecimal fromBytes(BigDecimal aBytes)
Calculates the number of bytes for the given value provided for the accordingMemoryUnit
.- Parameters:
aBytes
- the bytes- Returns:
- The converted value in bytes.
-
toSuitableUnit
public 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".- Parameters:
aBytes
- The number of bytes for which to determine the most suitableMemoryUnit
- Returns:
- The according
MemoryUnit
;
-
toSuitableUnit
public 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".- Parameters:
aBytes
- The number of bytes for which to determine the most suitableMemoryUnit
- Returns:
- The according
MemoryUnit
;
-
-