Enum Class SizeUnit
- All Implemented Interfaces:
Serializable
,Comparable<SizeUnit>
,Constable
Represents units of size for things such as memory or files.
- Author:
- James R. Perkins
-
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 TypeMethodDescriptionReturns the abbreviation for the unit.double
Converts the given size to the given unit to this unit.parent()
Returns the parent, previous, unit for this unit.long
toBytes
(long size) Converts the given size to bytes from this unit.static String
toHumanReadable
(long size) Converts the size, in bytes, to a human-readable form.toString
(long size) Converts the size to a human-readable string format.static SizeUnit
Returns the enum constant of this class with the specified name.static SizeUnit[]
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
-
-
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
-
abbreviation
Returns the abbreviation for the unit.- Returns:
- the abbreviation for the unit
-
toBytes
public long toBytes(long size) Converts the given size to bytes from this unit. For exampleSizeUnit.KILOBYTES.toBytes(1L)
would return 1024.- Parameters:
size
- the size to convert- Returns:
- the size in bytes
-
convert
Converts the given size to the given unit to this unit.- Parameters:
size
- the size to convertunit
- the unit to convert the size to- Returns:
- the converted units
-
toString
Converts the size to a human-readable string format.For example
SizeUnit.KILOBYTE.toString(1024L)
would return "1 KB".- Parameters:
size
- the size, in bytes- Returns:
- a human-readable size
-
parent
-
toHumanReadable
Converts the size, in bytes, to a human-readable form. For example1024
bytes return "1 KB".- Parameters:
size
- the size, in bytes, to convert- Returns:
- a human-readable size
-