Project Wonder 2.0

er.extensions
Class ERXUnitAwareDecimalFormat

java.lang.Object
  extended byjava.text.Format
      extended byjava.text.NumberFormat
          extended byjava.text.DecimalFormat
              extended byer.extensions.ERXUnitAwareDecimalFormat
All Implemented Interfaces:
Cloneable, Serializable

public class ERXUnitAwareDecimalFormat
extends DecimalFormat
implements Cloneable, 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 inherited from class java.text.NumberFormat
NumberFormat.Field
 
Field Summary
static String BYTE
          Predefined computer mass unit; supports: bytes, KB, MB, GB, TB
static String GRAM
          Predefined metric weight unit; supports: mg, g, kg, ton, kiloton
static String METER
          Predefined metric length unit; supports: nm, micrometer, mm, cm, m, km
static String SECOND
          Predefined time unit; supports: ps, ns, microsecond, ms, sec, min, hour, day
protected  NSArray unitPrefixArray
           
 
Fields inherited from class java.text.NumberFormat
FRACTION_FIELD, INTEGER_FIELD
 
Constructor Summary
ERXUnitAwareDecimalFormat()
           
ERXUnitAwareDecimalFormat(NSArray unitPrefixArray)
           
ERXUnitAwareDecimalFormat(String unitName)
           
ERXUnitAwareDecimalFormat(String pattern, DecimalFormatSymbols symbols)
           
ERXUnitAwareDecimalFormat(String pattern, DecimalFormatSymbols symbols, NSArray unitPrefixArray)
           
ERXUnitAwareDecimalFormat(String pattern, DecimalFormatSymbols symbols, String unitName)
           
 
Method Summary
 StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition fieldPosition)
           
 StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition fieldPosition)
           
 
Methods inherited from class java.text.DecimalFormat
applyLocalizedPattern, applyPattern, clone, equals, formatToCharacterIterator, getCurrency, getDecimalFormatSymbols, getGroupingSize, getMultiplier, getNegativePrefix, getNegativeSuffix, getPositivePrefix, getPositiveSuffix, hashCode, isDecimalSeparatorAlwaysShown, parse, setCurrency, setDecimalFormatSymbols, setDecimalSeparatorAlwaysShown, setGroupingSize, setMaximumFractionDigits, setMaximumIntegerDigits, setMinimumFractionDigits, setMinimumIntegerDigits, setMultiplier, setNegativePrefix, setNegativeSuffix, setPositivePrefix, setPositiveSuffix, toLocalizedPattern, toPattern
 
Methods inherited from class java.text.NumberFormat
format, format, format, getAvailableLocales, getCurrencyInstance, getCurrencyInstance, getInstance, getInstance, getIntegerInstance, getIntegerInstance, getMaximumFractionDigits, getMaximumIntegerDigits, getMinimumFractionDigits, getMinimumIntegerDigits, 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 String BYTE
Predefined computer mass unit; supports: bytes, KB, MB, GB, TB

See Also:
Constant Field Values

METER

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

See Also:
Constant Field Values

GRAM

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

See Also:
Constant Field Values

SECOND

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

See Also:
Constant Field Values

unitPrefixArray

protected final NSArray unitPrefixArray
Constructor Detail

ERXUnitAwareDecimalFormat

public ERXUnitAwareDecimalFormat()

ERXUnitAwareDecimalFormat

public ERXUnitAwareDecimalFormat(String unitName)

ERXUnitAwareDecimalFormat

public ERXUnitAwareDecimalFormat(NSArray unitPrefixArray)

ERXUnitAwareDecimalFormat

public ERXUnitAwareDecimalFormat(String pattern,
                                 DecimalFormatSymbols symbols)

ERXUnitAwareDecimalFormat

public ERXUnitAwareDecimalFormat(String pattern,
                                 DecimalFormatSymbols symbols,
                                 String unitName)

ERXUnitAwareDecimalFormat

public ERXUnitAwareDecimalFormat(String pattern,
                                 DecimalFormatSymbols symbols,
                                 NSArray unitPrefixArray)
Method Detail

format

public StringBuffer format(double number,
                           StringBuffer toAppendTo,
                           FieldPosition fieldPosition)

format

public StringBuffer format(long number,
                           StringBuffer toAppendTo,
                           FieldPosition fieldPosition)

Last updated: Do, Dez 9, 2004 • 12:46 PM CET

Copyright © 2002 – 2004 Project Wonder.