Hyperic HQ Plugin API v. 4.4.0.2

org.hyperic.util.units
Class DurationFormatter

java.lang.Object
  extended by org.hyperic.util.units.DurationFormatter
All Implemented Interfaces:
Formatter
Direct Known Subclasses:
ApproxDurationFormatter

public class DurationFormatter
extends java.lang.Object
implements Formatter

Format a value into a duration.


Field Summary
protected static int GRANULAR_DAYS
           
protected static int GRANULAR_HOURS
           
protected static int GRANULAR_MILLIS
           
protected static int GRANULAR_MINS
           
protected static int GRANULAR_SECS
           
protected static int GRANULAR_YEARS
           
protected static int MILLISEC_DIGITS
           
 
Constructor Summary
DurationFormatter()
           
 
Method Summary
protected  org.hyperic.util.units.DurationFormatter.TimeBreakDown breakDownTime(java.math.BigDecimal val)
           
protected  FormattedNumber format(java.math.BigDecimal baseTime, int granularity, int milliDigits, java.util.Locale locale)
           
 FormattedNumber format(UnitNumber val, java.util.Locale locale, FormatSpecifics specifics)
          Format a number with the given locale.
 FormattedNumber[] formatSame(double[] val, int unitType, int scale, java.util.Locale locale, FormatSpecifics specifics)
          Format a several values at once into the same format.
 java.math.BigDecimal getBaseValue(double value, int scale)
          Get the base value of a value, given its scale.
 java.math.BigDecimal getScaledValue(java.math.BigDecimal value, int targScale)
          Get a scaled version of a value.
 UnitNumber parse(java.lang.String val, java.util.Locale locale, ParseSpecifics specifics)
          Parse a string into a UnitNumber.
protected  double parseTimeStr(java.lang.String duration)
          Returns the # of seconds in a string in the form of "xx.xs" or "xx:yy:zz.a"
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GRANULAR_YEARS

protected static final int GRANULAR_YEARS
See Also:
Constant Field Values

GRANULAR_DAYS

protected static final int GRANULAR_DAYS
See Also:
Constant Field Values

GRANULAR_HOURS

protected static final int GRANULAR_HOURS
See Also:
Constant Field Values

GRANULAR_MINS

protected static final int GRANULAR_MINS
See Also:
Constant Field Values

GRANULAR_SECS

protected static final int GRANULAR_SECS
See Also:
Constant Field Values

GRANULAR_MILLIS

protected static final int GRANULAR_MILLIS
See Also:
Constant Field Values

MILLISEC_DIGITS

protected static final int MILLISEC_DIGITS
See Also:
Constant Field Values
Constructor Detail

DurationFormatter

public DurationFormatter()
Method Detail

format

public FormattedNumber format(UnitNumber val,
                              java.util.Locale locale,
                              FormatSpecifics specifics)
Description copied from interface: Formatter
Format a number with the given locale.

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

formatSame

public FormattedNumber[] formatSame(double[] val,
                                    int unitType,
                                    int scale,
                                    java.util.Locale locale,
                                    FormatSpecifics specifics)
Description copied from interface: Formatter
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.)

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

format

protected FormattedNumber format(java.math.BigDecimal baseTime,
                                 int granularity,
                                 int milliDigits,
                                 java.util.Locale locale)

breakDownTime

protected org.hyperic.util.units.DurationFormatter.TimeBreakDown breakDownTime(java.math.BigDecimal val)

getBaseValue

public java.math.BigDecimal getBaseValue(double value,
                                         int scale)
Description copied from interface: Formatter
Get the base value of a value, given its scale. E.x.: getBaseValue(1, SCALE_KILO) -> 1024 (bytes being the base unit)

Specified by:
getBaseValue in interface Formatter
Parameters:
value - Value to get the base of
scale - Scale of the value -- must be valid for the formatter unit type

getScaledValue

public java.math.BigDecimal getScaledValue(java.math.BigDecimal value,
                                           int targScale)
Description copied from interface: Formatter
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)

Specified by:
getScaledValue in interface Formatter
Parameters:
value - Value to scale
targScale - Target scale -- must be valid for the formatter unit type

parseTimeStr

protected double parseTimeStr(java.lang.String duration)
                       throws java.text.ParseException
Returns the # of seconds in a string in the form of "xx.xs" or "xx:yy:zz.a"

Throws:
java.text.ParseException

parse

public UnitNumber parse(java.lang.String val,
                        java.util.Locale locale,
                        ParseSpecifics specifics)
                 throws java.text.ParseException
Description copied from interface: Formatter
Parse a string into a UnitNumber. E.x. parse("34 MB") -> UnitNumber(34, UNIT_BYTES, SCALE_MEGA)

Specified by:
parse in interface Formatter
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:
java.text.ParseException

Hyperic HQ Plugin API v. 4.4.0.2

Copyright © 2004-2006 Hyperic, Inc. support@hyperic.net, All Rights Reserved.