Package org.jscience.physics.amount
Class AmountFormat
- java.lang.Object
-
- javolution.text.TextFormat<Amount<?>>
-
- org.jscience.physics.amount.AmountFormat
-
public abstract class AmountFormat extends javolution.text.TextFormat<Amount<?>>
This class provides the interface for formatting and parsing
measures
instances. For example:[code] // Display measurements using unscaled units (e.g. base units or alternate units). AmountFormat.setInstance(new AmountFormat() { // Context local. public Appendable format(Amount m, Appendable a) throws IOException { Unit u = m.getUnit(); if (u instanceof TransformedUnit) u = ((TransformedUnit)u).getParentUnit(); return AmountFormat.getPlusMinusErrorInstance(2).format(m.to(u), a); } public Amount parse(CharSequence csq, Cursor c) { return AmountFormat.getPlusMinusErrorInstance(2).parse(csq, c); } });[/code]
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AmountFormat()
Default constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static AmountFormat
getBracketErrorInstance(int digitsInError)
Returns a format for which the error is represented by an integer value in brackets; for example"1.3456[20] m"
is equivalent to"1.3456 ± 0.0020 m"
.static AmountFormat
getExactDigitsInstance()
Returns a format for which only digits guaranteed to be exact are written out.static AmountFormat
getInstance()
Returns the currentlocal
format (defaultAmountFormat.getPlusMinusErrorInstance(2)
).static AmountFormat
getPlusMinusErrorInstance(int digitsInError)
Returns a format for which the error (if present) is stated using the '±' character; for example"(1.34 ± 0.01) m"
.static void
setInstance(AmountFormat format)
Sets the currentlocal
format.
-
-
-
Method Detail
-
getInstance
public static AmountFormat getInstance()
Returns the currentlocal
format (defaultAmountFormat.getPlusMinusErrorInstance(2)
).- Returns:
- the context local format.
- See Also:
getPlusMinusErrorInstance(int)
-
setInstance
public static void setInstance(AmountFormat format)
Sets the currentlocal
format.- Parameters:
format
- the new format.
-
getPlusMinusErrorInstance
public static AmountFormat getPlusMinusErrorInstance(int digitsInError)
Returns a format for which the error (if present) is stated using the '±' character; for example"(1.34 ± 0.01) m"
. This format can be used for formatting as well as for parsing.- Parameters:
digitsInError
- the maximum number of digits in error.
-
getBracketErrorInstance
public static AmountFormat getBracketErrorInstance(int digitsInError)
Returns a format for which the error is represented by an integer value in brackets; for example"1.3456[20] m"
is equivalent to"1.3456 ± 0.0020 m"
. This format can be used for formatting as well as for parsing.- Parameters:
digitsInError
- the maximum number of digits in error.
-
getExactDigitsInstance
public static AmountFormat getExactDigitsInstance()
Returns a format for which only 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,"1.34 m"
means a length between1.32 m
and1.35 m
. This format can be used for formatting only.
-
-