org.rhq.core.clientapi.util.units
Interface Formatter

All Known Implementing Classes:
BinaryFormatter, BitRateFormatter, BytesFormatter, DateFormatter, DurationFormatter, NoFormatter, PercentageFormatter, SimpleFormatter, TemperatureFormatter

public interface Formatter


Method Summary
 FormattedNumber format(UnitNumber val, Locale locale, FormatSpecifics format)
          Format a number with the given locale.
 FormattedNumber[] formatSame(double[] values, UnitsConstants unitType, ScaleConstants scale, Locale locale, FormatSpecifics format)
          Format a several values at once into the same format.
 BigDecimal getBaseValue(double value, ScaleConstants scale)
          Get the base value of a value, given its scale.
 BigDecimal getScaledValue(BigDecimal value, ScaleConstants targScale)
          Get a scaled version of a value.
 UnitNumber parse(String val, Locale locale, ParseSpecifics specifics)
          Parse a string into a UnitNumber.
 

Method Detail

format

FormattedNumber format(UnitNumber val,
                       Locale locale,
                       FormatSpecifics format)
Format a number with the given locale.

Parameters:
val - Value to format
locale - Locale that the resultant format should be in
format - Optional format to give specific hints to the formatter about how the result should look.

formatSame

FormattedNumber[] formatSame(double[] values,
                             UnitsConstants unitType,
                             ScaleConstants scale,
                             Locale locale,
                             FormatSpecifics format)
Format a several values at once into the same format. I.e. no matter the discrepency of range, they all contain the same units (megabytes, etc.)

Parameters:
values - Values to format
unitType - One of UnitsConstants.UNIT_*
scale - One of UnitsConstants.SCALE_*
locale - Locale that the resultant format should be in
format - Optional format to give specific hints to the formatter about how the result should look.

getBaseValue

BigDecimal getBaseValue(double value,
                        ScaleConstants scale)
Get the base value of a value, given its scale. E.x.: getBaseValue(1, SCALE_KILO) -> 1024 (bytes being the base unit)

Parameters:
value - Value to get the base of
scale - Scale of the value -- must be valid for the formatter unit type

getScaledValue

BigDecimal getScaledValue(BigDecimal value,
                          ScaleConstants targScale)
Get a scaled version of a value. The value in its base format, and the target scale are passed. The return value will be a number, scaled to the target. E.x.: getScaledValue(1024, SCALE_NONE) -> 1024 getScaledValue(1024, SCALE_KILO) -> 1 (1 kilobyte)

Parameters:
value - Value to scale
targScale - Target scale -- must be valid for the formatter unit type

parse

UnitNumber parse(String val,
                 Locale locale,
                 ParseSpecifics specifics)
                 throws ParseException
Parse a string into a UnitNumber. E.x. parse("34 MB") -> UnitNumber(34, UNIT_BYTES, SCALE_MEGA)

Parameters:
val - Value to parse
locale - Locale to parse with
specifics - An optional argument which gives the parser more information about parsing
Returns:
the number representing the parsed value
Throws:
ParseException - if the value could not be parsed


Copyright © 2008-2009 Red Hat, Inc.. All Rights Reserved.