org.opends.server.admin
Enum SizeUnit

java.lang.Object
  extended by java.lang.Enum<SizeUnit>
      extended by org.opends.server.admin.SizeUnit
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<SizeUnit>

public enum SizeUnit
extends java.lang.Enum<SizeUnit>

This enumeration defines various memory size units.


Enum Constant Summary
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 Summary
 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.
 java.lang.String getLongName()
          Get the long name of this unit.
 java.lang.String getShortName()
          Get the abbreviated name of this unit.
 long getSize()
          Get the number of bytes that this unit represents.
static SizeUnit getUnit(java.lang.String s)
          Get the unit corresponding to the provided unit name.
static long parseValue(java.lang.String s)
          Parse the provided size string and return its equivalent size in bytes.
static long parseValue(java.lang.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.
 java.lang.String toString()
          
static SizeUnit valueOf(java.lang.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.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

BYTES

public static final SizeUnit BYTES
A byte unit.


GIBI_BYTES

public static final SizeUnit GIBI_BYTES
A gibi-byte unit.


GIGA_BYTES

public static final SizeUnit GIGA_BYTES
A giga-byte unit.


KIBI_BYTES

public static final SizeUnit KIBI_BYTES
A kibi-byte unit.


KILO_BYTES

public static final SizeUnit KILO_BYTES
A kilo-byte unit.


MEBI_BYTES

public static final SizeUnit MEBI_BYTES
A mebi-byte unit.


MEGA_BYTES

public static final SizeUnit MEGA_BYTES
A mega-byte unit.


TEBI_BYTES

public static final SizeUnit TEBI_BYTES
A tebi-byte unit.


TERA_BYTES

public static final SizeUnit TERA_BYTES
A tera-byte unit.

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(java.lang.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:
java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
java.lang.NullPointerException - if the argument is null

getBestFitUnit

public static SizeUnit getBestFitUnit(long bytes)
                               throws java.lang.IllegalArgumentException
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 the 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
 

Parameters:
bytes - The number of bytes.
Returns:
Returns the best fit unit.
Throws:
java.lang.IllegalArgumentException - If bytes is negative.
See Also:
getBestFitUnitExact(long)

getBestFitUnitExact

public static SizeUnit getBestFitUnitExact(long bytes)
                                    throws java.lang.IllegalArgumentException
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 the 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
 

Parameters:
bytes - The number of bytes.
Returns:
Returns the best fit unit can represent the provided value using an integral value.
Throws:
java.lang.IllegalArgumentException - If bytes is negative.
See Also:
getBestFitUnit(long)

getUnit

public static SizeUnit getUnit(java.lang.String s)
                        throws java.lang.IllegalArgumentException
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:
java.lang.IllegalArgumentException - If the provided name did not correspond to a known memory size unit.

parseValue

public static long parseValue(java.lang.String s)
                       throws java.lang.NumberFormatException
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:
java.lang.NumberFormatException - If the provided size string could not be parsed.

parseValue

public static long parseValue(java.lang.String s,
                              SizeUnit defaultUnit)
                       throws java.lang.NumberFormatException
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, or null if the string must always contain a unit.
Returns:
Returns the parsed size in bytes.
Throws:
java.lang.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

public java.lang.String getLongName()
Get the long name of this unit.

Returns:
Returns the long name of this unit.

getShortName

public java.lang.String 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)
             throws java.lang.NumberFormatException
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:
java.lang.NumberFormatException - If the provided size exceeded long.MAX_VALUE.

toString

public java.lang.String toString()

This implementation returns the abbreviated name of this size unit.

Overrides:
toString in class java.lang.Enum<SizeUnit>