public enum SizeUnit extends Enum<SizeUnit>
Enum Constant and Description |
---|
BYTES
A byte unit.
|
GIBI_BYTES
A gibi-byte unit.
|
GIGA_BYTES
A giga-byte unit.
|
KIBI_BYTES
A kibi-byte unit.
|
KILO_BYTES
A kilo-byte unit.
|
MEBI_BYTES
A mebi-byte unit.
|
MEGA_BYTES
A mega-byte unit.
|
TEBI_BYTES
A tebi-byte unit.
|
TERA_BYTES
A tera-byte unit.
|
Modifier and Type | Method and Description |
---|---|
double |
fromBytes(long amount)
Converts the specified size in bytes to this unit.
|
static SizeUnit |
getBestFitUnit(long bytes)
Gets the best-fit unit for the specified number of bytes.
|
static SizeUnit |
getBestFitUnitExact(long bytes)
Gets the best-fit unit for the specified number of bytes which can
represent the provided value using an integral value.
|
String |
getLongName()
Get the long name of this unit.
|
String |
getShortName()
Get the abbreviated name of this unit.
|
long |
getSize()
Get the number of bytes that this unit represents.
|
static SizeUnit |
getUnit(String s)
Get the unit corresponding to the provided unit name.
|
static long |
parseValue(String s)
Parse the provided size string and return its equivalent size in bytes.
|
static long |
parseValue(String s,
SizeUnit defaultUnit)
Parse the provided size string and return its equivalent size in bytes.
|
long |
toBytes(double amount)
Converts the specified size in this unit to bytes.
|
String |
toString() |
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.
|
public static final SizeUnit BYTES
public static final SizeUnit GIBI_BYTES
public static final SizeUnit GIGA_BYTES
public static final SizeUnit KIBI_BYTES
public static final SizeUnit KILO_BYTES
public static final SizeUnit MEBI_BYTES
public static final SizeUnit MEGA_BYTES
public static final SizeUnit TEBI_BYTES
public static final SizeUnit TERA_BYTES
public static SizeUnit[] values()
for (SizeUnit c : SizeUnit.values()) System.out.println(c);
public static SizeUnit valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic static SizeUnit getBestFitUnit(long bytes)
BYTES
unit is always returned. For example:
getBestFitUnit(0) // BYTES getBestFitUnit(999) // BYTES getBestFitUnit(1000) // KILO_BYTES getBestFitUnit(1024) // KIBI_BYTES getBestFitUnit(1025) // KILO_BYTES getBestFitUnit(999999) // KILO_BYTES getBestFitUnit(1000000) // MEGA_BYTES
bytes
- The number of bytes.IllegalArgumentException
- If bytes
is negative.getBestFitUnitExact(long)
public static SizeUnit getBestFitUnitExact(long bytes)
BYTES
unit is always returned. For example:
getBestFitUnitExact(0) // BYTES getBestFitUnitExact(999) // BYTES getBestFitUnitExact(1000) // KILO_BYTES getBestFitUnitExact(1024) // KIBI_BYTES getBestFitUnitExact(1025) // BYTES getBestFitUnitExact(999999) // BYTES getBestFitUnitExact(1000000) // MEGA_BYTES
bytes
- The number of bytes.IllegalArgumentException
- If bytes
is negative.getBestFitUnit(long)
public static SizeUnit getUnit(String s)
s
- The name of the unit. Can be the abbreviated or long name and
can contain white space and mixed case characters.IllegalArgumentException
- If the provided name did not correspond to a known memory
size unit.public static long parseValue(String s)
s
- The size string to be parsed.NumberFormatException
- If the provided size string could not be parsed.public static long parseValue(String s, SizeUnit defaultUnit)
s
- The size string to be parsed.defaultUnit
- The default unit to use if there is no unit specified in the
size string, or null
if the string must always
contain a unit.NumberFormatException
- If the provided size string could not be parsed.public double fromBytes(long amount)
amount
- The size in bytes.public String getLongName()
public String getShortName()
public long getSize()
public long toBytes(double amount)
amount
- The size as a quantity of this unit.NumberFormatException
- If the provided size exceeded long.MAX_VALUE.Copyright 2010-2018 ForgeRock AS.