|
JScience v3.3 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavolution.text.TextFormat<Measure>
org.jscience.physics.measures.MeasureFormat
public abstract class MeasureFormat
This class provides the interface for formatting and parsing measures instances. For example:
// Display measurements using unscaled units (e.g. base units or alternate units).
MeasureFormat.setInstance(new MeasureFormat() { // Context local.
public Appendable format(Measure m, Appendable a) throws IOException {
Unit u = m.getUnit();
if (u instanceof TransformedUnit)
u = ((TransformedUnit)u).getParentUnit();
return MeasureFormat.getPlusMinusErrorInstance(2).format(m.to(u), a);
}
public Measure parse(CharSequence csq, Cursor c) {
return MeasureFormat.getPlusMinusErrorInstance(2).parse(csq, c);
}
});
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class javolution.text.TextFormat |
|---|
TextFormat.Cursor |
| Constructor Summary | |
|---|---|
protected |
MeasureFormat()
Default constructor. |
| Method Summary | |
|---|---|
static MeasureFormat |
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 MeasureFormat |
getExactDigitsInstance()
Returns a format for which only digits guaranteed to be exact are written out. |
static MeasureFormat |
getInstance()
Returns the current local
format (default MeasureFormat.getPlusMinusErrorInstance(2)). |
static MeasureFormat |
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(MeasureFormat format)
Sets the current local format. |
| Methods inherited from class javolution.text.TextFormat |
|---|
format, format, parse, parse |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
protected MeasureFormat()
| Method Detail |
|---|
public static MeasureFormat getInstance()
local
format (default MeasureFormat.getPlusMinusErrorInstance(2)).
getPlusMinusErrorInstance(int)public static void setInstance(MeasureFormat format)
local format.
format - the new format.public static MeasureFormat getPlusMinusErrorInstance(int digitsInError)
"(1.34 ± 0.01) m".
This format can be used for formatting as well as for parsing.
digitsInError - the maximum number of digits in error.public static MeasureFormat getBracketErrorInstance(int digitsInError)
"1.3456[20] m"
is equivalent to "1.3456 ± 0.0020 m".
This format can be used for formatting as well as for parsing.
digitsInError - the maximum number of digits in error.public static MeasureFormat getExactDigitsInstance()
"1.34 m" means a length between 1.32 m and
1.35 m. This format can be used for formatting only.
|
JScience v3.3 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||