Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

er.extensions
Class ERXUnitAwareDecimalFormat  view ERXUnitAwareDecimalFormat download ERXUnitAwareDecimalFormat.java

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

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

ERXUnitAwareDecimalFormat extends java.text.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));
 
 


Nested Class Summary
static class ERXUnitAwareDecimalFormat.UnitPrefix
          UnitPrefix is an inner class
 
Nested classes 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  NSArray unitPrefixArray
           
 
Fields inherited from class java.text.DecimalFormat
 
Fields inherited from class java.text.NumberFormat
FRACTION_FIELD, INTEGER_FIELD
 
Constructor Summary
ERXUnitAwareDecimalFormat()
           
ERXUnitAwareDecimalFormat(java.lang.String unitName)
           
ERXUnitAwareDecimalFormat(java.lang.String pattern, java.text.DecimalFormatSymbols symbols)
           
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)
          This method formats the specified double and appends it to a StringBuffer.
 java.lang.StringBuffer format(long number, java.lang.StringBuffer toAppendTo, java.text.FieldPosition fieldPosition)
          This method formats the specified long and appends it to a StringBuffer.
 
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 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 NSArray unitPrefixArray
Constructor Detail

ERXUnitAwareDecimalFormat

public ERXUnitAwareDecimalFormat()

ERXUnitAwareDecimalFormat

public ERXUnitAwareDecimalFormat(java.lang.String unitName)

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)
Method Detail

format

public java.lang.StringBuffer format(double number,
                                     java.lang.StringBuffer toAppendTo,
                                     java.text.FieldPosition fieldPosition)
Description copied from class: java.text.NumberFormat
This method formats the specified double and appends it to a StringBuffer.


format

public java.lang.StringBuffer format(long number,
                                     java.lang.StringBuffer toAppendTo,
                                     java.text.FieldPosition fieldPosition)
Description copied from class: java.text.NumberFormat
This method formats the specified long and appends it to a StringBuffer.