Enum SizeUnit
- All Implemented Interfaces:
Serializable
,Comparable<SizeUnit>
Represents units of size for things such as memory or files.
- Author:
- James R. Perkins
-
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 type with the specified name.static SizeUnit[]
values()
Returns an array containing the constants of this enum type, 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 type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
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
-
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
-