JADE v6.1

com.dautelle.physics
Class QuantityFormat

java.lang.Object
  extended byjava.text.Format
      extended bycom.dautelle.physics.QuantityFormat
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public abstract class QuantityFormat
extends java.text.Format

This class provides the interface for formatting and parsing quantities.

Version:
6.1, June 30, 2004
Author:
Jean-Marie Dautelle
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.text.Format
java.text.Format.Field
 
Constructor Summary
protected QuantityFormat()
          Base constructor.
 
Method Summary
 java.lang.StringBuffer format(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
          Formats a quantity and appends the resulting text to a given string buffer.
abstract  java.lang.StringBuffer format(Quantity quantity, java.lang.StringBuffer toAppendTo, Unit outputUnit)
          Formats a quantity and appends the resulting text to a given string buffer.
static QuantityFormat getDefaultInstance()
          Returns the default quantity format instance.
static QuantityFormat getInstance()
          Returns the context local quantity format (default getDefaultInstance()).
abstract  Quantity parse(java.lang.CharSequence source)
          Parses text from a character sequence to produce a quantity.
 java.lang.Object parseObject(java.lang.String source, java.text.ParsePosition pos)
          Parses text from a string to produce an object.
static void setInstance(QuantityFormat format)
          Sets the context local quantity format.
 
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QuantityFormat

protected QuantityFormat()
Base constructor.

Method Detail

getInstance

public static QuantityFormat getInstance()
Returns the context local quantity format (default getDefaultInstance()).

Returns:
the quantity format for the current thread.

setInstance

public static void setInstance(QuantityFormat format)
Sets the context local quantity format.

Parameters:
format - the new local/global format.

getDefaultInstance

public static final QuantityFormat getDefaultInstance()
Returns the default quantity format instance. Only the digits guaranteed to be exact are written out. In other words, the error is always on the last digit and less than the last digit weight. For example, if "1.33" is appended then the quantity is guaranteed to be in the range ]1.32, 1.34[.

Returns:
the default quantity format.

format

public final java.lang.StringBuffer format(java.lang.Object obj,
                                           java.lang.StringBuffer toAppendTo,
                                           java.text.FieldPosition pos)
Formats a quantity and appends the resulting text to a given string buffer.

Parameters:
obj - the quantity to format.
toAppendTo - where the text is to be appended
pos - a FieldPosition identifying a field in the formatted text (not used).
Returns:
the string buffer passed in as toAppendTo, with formatted text appended.
Throws:
java.lang.NullPointerException - if toAppendTo is null
java.lang.IllegalArgumentException - if this format cannot format the given object (e.g. not a Quantity instance).

parseObject

public final java.lang.Object parseObject(java.lang.String source,
                                          java.text.ParsePosition pos)
Parses text from a string to produce an object.

Parameters:
source - a String, part of which should be parsed.
pos - a ParsePosition object with index and error index information.
Returns:
an Object parsed from the string. In case of error, returns null.

parse

public abstract Quantity parse(java.lang.CharSequence source)
                        throws java.text.ParseException
Parses text from a character sequence to produce a quantity.

Parameters:
source - the characters sequence to be parsed.
Returns:
a Quantity parsed from the string.
Throws:
java.text.ParseException - if a parsing error occurs.

format

public abstract java.lang.StringBuffer format(Quantity quantity,
                                              java.lang.StringBuffer toAppendTo,
                                              Unit outputUnit)
Formats a quantity and appends the resulting text to a given string buffer.

Parameters:
quantity - the quantity to format.
toAppendTo - where the text is to be appended.
outputUnit - the output unit for the quantity.
Returns:
the string buffer passed in as toAppendTo, with formatted text appended.
Throws:
java.lang.NullPointerException - if toAppendTo is null
java.lang.IllegalArgumentException - if this format cannot format the given object (e.g. not a Quantity instance).

JADE v6.1

Copyright © 2004 Jean-Marie Dautelle.