Package org.jboss.resteasy.spi.config
Enum SizeUnit
- java.lang.Object
-
- java.lang.Enum<SizeUnit>
-
- org.jboss.resteasy.spi.config.SizeUnit
-
- All Implemented Interfaces:
Serializable
,Comparable<SizeUnit>
public enum SizeUnit extends Enum<SizeUnit>
Represents units of size for things such as memory or files.- Author:
- James R. Perkins
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
abbreviation()
Returns the abbreviation for the unit.double
convert(long size, SizeUnit unit)
Converts the given size to the given unit to this unit.SizeUnit
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.String
toString(long size)
Converts the size to a human-readable string format.static SizeUnit
valueOf(String name)
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 Detail
-
BYTE
public static final SizeUnit BYTE
-
KILOBYTE
public static final SizeUnit KILOBYTE
-
MEGABYTE
public static final SizeUnit MEGABYTE
-
GIGABYTE
public static final SizeUnit GIGABYTE
-
TERABYTE
public static final SizeUnit TERABYTE
-
PETABYTE
public static final SizeUnit PETABYTE
-
EXABYTE
public static final SizeUnit EXABYTE
-
-
Method Detail
-
values
public static SizeUnit[] 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 (SizeUnit c : SizeUnit.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static SizeUnit 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
-
abbreviation
public String 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
public double convert(long size, SizeUnit unit)
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
public String toString(long size)
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
public SizeUnit parent()
Returns the parent, previous, unit for this unit.- Returns:
- the parent unit or
null
in the case ofBYTE
-
toHumanReadable
public static String toHumanReadable(long size)
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
-
-