Project Wonder 5.0

er.extensions.formatters
Class ERXUnitAwareDecimalFormat

java.lang.Object
  extended by java.text.Format
      extended by java.text.NumberFormat
          extended by java.text.DecimalFormat
              extended by er.extensions.formatters.ERXUnitAwareDecimalFormat
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class ERXUnitAwareDecimalFormat
extends java.text.DecimalFormat
implements java.lang.Cloneable, java.io.Serializable

ERXUnitAwareDecimalFormat extends DecimalFormat to add an automatic unit conversion feature for the given unit. Convenient to display friendly values for file size, elaps time, etc. Examples:

 
 import java.text.NumberFormat;
 import er.extensions.ERXUnitAwareDecimalFormat
 
 double smallValue = 123.0d;
 double largeValue = 1234567890.0d;
 NumberFormat formatter = new ERXUnitAwareDecimalFormat(ERXUnitAwareDecimalFormat.BYTE);
 formatter.setMaximumFractionDigits(2);
 
 // Will display "123 bytes"
 System.out.println(formatter.format(smallValue)); 
 
 // Will display "1.15 GB"
 System.out.println(formatter.format(largeValue));
 
 

See Also:
Serialized Form

Nested Class Summary
static class ERXUnitAwareDecimalFormat.UnitPrefix
          UnitPrefix is an inner class
 
Nested classes/interfaces inherited from class java.text.NumberFormat
java.text.NumberFormat.Field
 
Field Summary
static java.lang.String BYTE
          Predefined computer mass unit; supports: bytes, KB, MB, GB, TB
static java.lang.String GRAM
          Predefined metric weight unit; supports: mg, g, kg, ton, kiloton
static java.lang.String METER
          Predefined metric length unit; supports: nm, micrometer, mm, cm, m, km
static java.lang.String SECOND
          Predefined time unit; supports: ps, ns, microsecond, ms, sec, min, hour, day
protected  com.webobjects.foundation.NSArray unitPrefixArray
           
 
Fields inherited from class java.text.NumberFormat
FRACTION_FIELD, INTEGER_FIELD
 
Constructor Summary
ERXUnitAwareDecimalFormat()
           
ERXUnitAwareDecimalFormat(com.webobjects.foundation.NSArray unitPrefixArray)
           
ERXUnitAwareDecimalFormat(java.lang.String unitName)
           
ERXUnitAwareDecimalFormat(java.lang.String pattern, java.text.DecimalFormatSymbols symbols)
           
ERXUnitAwareDecimalFormat(java.lang.String pattern, java.text.DecimalFormatSymbols symbols, com.webobjects.foundation.NSArray unitPrefixArray)
           
ERXUnitAwareDecimalFormat(java.lang.String pattern, java.text.DecimalFormatSymbols symbols, java.lang.String unitName)
           
 
Method Summary
 java.lang.StringBuffer format(double number, java.lang.StringBuffer toAppendTo, java.text.FieldPosition fieldPosition)
           
 java.lang.StringBuffer format(long number, java.lang.StringBuffer toAppendTo, java.text.FieldPosition fieldPosition)
           
 
Methods inherited from class java.text.DecimalFormat
applyLocalizedPattern, applyPattern, clone, equals, format, formatToCharacterIterator, getCurrency, getDecimalFormatSymbols, getGroupingSize, getMaximumFractionDigits, getMaximumIntegerDigits, getMinimumFractionDigits, getMinimumIntegerDigits, getMultiplier, getNegativePrefix, getNegativeSuffix, getPositivePrefix, getPositiveSuffix, getRoundingMode, hashCode, isDecimalSeparatorAlwaysShown, isParseBigDecimal, parse, setCurrency, setDecimalFormatSymbols, setDecimalSeparatorAlwaysShown, setGroupingSize, setMaximumFractionDigits, setMaximumIntegerDigits, setMinimumFractionDigits, setMinimumIntegerDigits, setMultiplier, setNegativePrefix, setNegativeSuffix, setParseBigDecimal, setPositivePrefix, setPositiveSuffix, setRoundingMode, toLocalizedPattern, toPattern
 
Methods inherited from class java.text.NumberFormat
format, format, getAvailableLocales, getCurrencyInstance, getCurrencyInstance, getInstance, getInstance, getIntegerInstance, getIntegerInstance, getNumberInstance, getNumberInstance, getPercentInstance, getPercentInstance, isGroupingUsed, isParseIntegerOnly, parse, parseObject, setGroupingUsed, setParseIntegerOnly
 
Methods inherited from class java.text.Format
format, parseObject
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BYTE

public static final java.lang.String BYTE
Predefined computer mass unit; supports: bytes, KB, MB, GB, TB

See Also:
Constant Field Values

METER

public static final java.lang.String METER
Predefined metric length unit; supports: nm, micrometer, mm, cm, m, km

See Also:
Constant Field Values

GRAM

public static final java.lang.String GRAM
Predefined metric weight unit; supports: mg, g, kg, ton, kiloton

See Also:
Constant Field Values

SECOND

public static final java.lang.String SECOND
Predefined time unit; supports: ps, ns, microsecond, ms, sec, min, hour, day

See Also:
Constant Field Values

unitPrefixArray

protected final com.webobjects.foundation.NSArray unitPrefixArray
Constructor Detail

ERXUnitAwareDecimalFormat

public ERXUnitAwareDecimalFormat()

ERXUnitAwareDecimalFormat

public ERXUnitAwareDecimalFormat(java.lang.String unitName)

ERXUnitAwareDecimalFormat

public ERXUnitAwareDecimalFormat(com.webobjects.foundation.NSArray unitPrefixArray)

ERXUnitAwareDecimalFormat

public ERXUnitAwareDecimalFormat(java.lang.String pattern,
                                 java.text.DecimalFormatSymbols symbols)

ERXUnitAwareDecimalFormat

public ERXUnitAwareDecimalFormat(java.lang.String pattern,
                                 java.text.DecimalFormatSymbols symbols,
                                 java.lang.String unitName)

ERXUnitAwareDecimalFormat

public ERXUnitAwareDecimalFormat(java.lang.String pattern,
                                 java.text.DecimalFormatSymbols symbols,
                                 com.webobjects.foundation.NSArray unitPrefixArray)
Method Detail

format

public java.lang.StringBuffer format(double number,
                                     java.lang.StringBuffer toAppendTo,
                                     java.text.FieldPosition fieldPosition)
Overrides:
format in class java.text.DecimalFormat

format

public java.lang.StringBuffer format(long number,
                                     java.lang.StringBuffer toAppendTo,
                                     java.text.FieldPosition fieldPosition)
Overrides:
format in class java.text.DecimalFormat

Last updated: Tue, Feb 21, 2017 • 05:45 PM CET

Copyright © 2002 – 2007 Project Wonder.