nl.lxtreme.ols.api.util
Enum SizeUnit

java.lang.Object
  extended by java.lang.Enum<SizeUnit>
      extended by nl.lxtreme.ols.api.util.SizeUnit
All Implemented Interfaces:
Serializable, Comparable<SizeUnit>

public enum SizeUnit
extends Enum<SizeUnit>

Represents a size unit (SI-standard) that has a displayable representation and has a scale factor.


Enum Constant Summary
B
          bytes.
GB
          gigabytes.
KB
          kilobytes.
MB
          megabytes.
TB
          terabytes.
 
Field Summary
static double ZERO_THRESHOLD
          Constant used to determine whether we should show "0B".
 
Method Summary
static String format(double aSize)
          Convenience method to directly get a displayable represention of a given size.
 String format(double aSize, int aScale)
          Returns the given size as string representation using this size unit's display name.
 String getDisplayName()
          Returns the current value of displayName.
 double getFactor()
          Returns the current value of factor.
static SizeUnit toUnit(double aSize)
          Returns a SizeUnit instance usable for representing the given size.
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.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

B

public static final SizeUnit B
bytes.


KB

public static final SizeUnit KB
kilobytes.


MB

public static final SizeUnit MB
megabytes.


GB

public static final SizeUnit GB
gigabytes.


TB

public static final SizeUnit TB
terabytes.

Field Detail

ZERO_THRESHOLD

public static final double ZERO_THRESHOLD
Constant used to determine whether we should show "0B".

See Also:
Constant Field Values
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 name
NullPointerException - if the argument is null

format

public static String format(double aSize)
Convenience method to directly get a displayable represention of a given size.

This method does the same as calling: toUnit( aSize ).format( aSize, 2 );.

Parameters:
aSize - the size to get a displayable representation for.
Returns:
a string representation of the given size, never null.

toUnit

public static SizeUnit toUnit(double aSize)
Returns a SizeUnit instance usable for representing the given size.

Parameters:
aSize - the size to convert to a SizeUnit instance.
Returns:
a SizeUnit instance, never null.

format

public String format(double aSize,
                     int aScale)
Returns the given size as string representation using this size unit's display name.

Parameters:
aSize - the size to convert to a string representation;
aScale - the scale (= number of digits after decimal separator) to use in the string representation.
Returns:
a string representation of the given size, like "1.44MB", never null.

getDisplayName

public String getDisplayName()
Returns the current value of displayName.

Returns:
the displayName

getFactor

public double getFactor()
Returns the current value of factor.

Returns:
the factor


Copyright © 2012 L'Xtreme IT consultancy. All Rights Reserved.