Package org.forgerock.opendj.config
Enum Class SizeUnit
- All Implemented Interfaces:
Serializable
,Comparable<SizeUnit>
,java.lang.constant.Constable
This enumeration defines various memory size units.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantDescriptionA byte unit.A gibi-byte unit.A giga-byte unit.A kibi-byte unit.A kilo-byte unit.A mebi-byte unit.A mega-byte unit.A tebi-byte unit.A tera-byte unit. -
Method Summary
Modifier and TypeMethodDescriptiondouble
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.Get the long name of this unit.Get the abbreviated name of this unit.long
getSize()
Get the number of bytes that this unit represents.static SizeUnit
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.toString()
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
-
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.
-
-
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
-
getBestFitUnit
Gets the best-fit unit for the specified number of bytes. The returned unit will be able to represent the number of bytes using a decimal number comprising of an integer part which is greater than zero. Bigger units are chosen in preference to smaller units and binary units are only returned if they are an exact fit. If the number of bytes is zero then theBYTES
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
- Parameters:
bytes
- The number of bytes.- Returns:
- Returns the best fit unit.
- Throws:
IllegalArgumentException
- Ifbytes
is negative.- See Also:
-
getBestFitUnitExact
Gets the best-fit unit for the specified number of bytes which can represent the provided value using an integral value. Bigger units are chosen in preference to smaller units. If the number of bytes is zero then theBYTES
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
- Parameters:
bytes
- The number of bytes.- Returns:
- Returns the best fit unit can represent the provided value using an integral value.
- Throws:
IllegalArgumentException
- Ifbytes
is negative.- See Also:
-
getUnit
Get the unit corresponding to the provided unit name.- Parameters:
s
- The name of the unit. Can be the abbreviated or long name and can contain white space and mixed case characters.- Returns:
- Returns the unit corresponding to the provided unit name.
- Throws:
IllegalArgumentException
- If the provided name did not correspond to a known memory size unit.
-
parseValue
Parse the provided size string and return its equivalent size in bytes. The size string must specify the unit e.g. "10kb".- Parameters:
s
- The size string to be parsed.- Returns:
- Returns the parsed duration in bytes.
- Throws:
NumberFormatException
- If the provided size string could not be parsed.
-
parseValue
Parse the provided size string and return its equivalent size in bytes.- Parameters:
s
- The size string to be parsed.defaultUnit
- The default unit to use if there is no unit specified in the size string, ornull
if the string must always contain a unit.- Returns:
- Returns the parsed size in bytes.
- Throws:
NumberFormatException
- If the provided size string could not be parsed.
-
fromBytes
public double fromBytes(long amount) Converts the specified size in bytes to this unit.- Parameters:
amount
- The size in bytes.- Returns:
- Returns size in this unit.
-
getLongName
Get the long name of this unit.- Returns:
- Returns the long name of this unit.
-
getShortName
Get the abbreviated name of this unit.- Returns:
- Returns the abbreviated name of this unit.
-
getSize
public long getSize()Get the number of bytes that this unit represents.- Returns:
- Returns the number of bytes that this unit represents.
-
toBytes
public long toBytes(double amount) Converts the specified size in this unit to bytes.- Parameters:
amount
- The size as a quantity of this unit.- Returns:
- Returns the number of bytes that the size represents.
- Throws:
NumberFormatException
- If the provided size exceeded long.MAX_VALUE.
-
toString
This implementation returns the abbreviated name of this size unit.
-