|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.text.Format
javax.measure.MeasureFormat
public abstract class MeasureFormat
This class provides the interface for formatting and parsing measurements.
Instances of this class should be able to format measurements stated in
CompoundUnit. See formatCompound(...).
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.text.Format |
|---|
java.text.Format.Field |
| Constructor Summary | |
|---|---|
MeasureFormat()
|
|
| Method Summary | |
|---|---|
abstract java.lang.Appendable |
format(Measure<?> measure,
java.lang.Appendable dest)
Formats the specified measure into an Appendable. |
java.lang.StringBuilder |
format(Measure<?> measure,
java.lang.StringBuilder dest)
Convenience method equivalent to format(Measure, Appendable)
except it does not raise an IOException. |
java.lang.StringBuffer |
format(java.lang.Object obj,
java.lang.StringBuffer toAppendTo,
java.text.FieldPosition pos)
|
protected java.lang.Appendable |
formatCompound(double value,
CompoundUnit<?> unit,
java.lang.Appendable dest)
Formats the specified value using CompoundUnit compound units}. |
static MeasureFormat |
getInstance()
Returns the measure format for the default locale. |
static MeasureFormat |
getInstance(java.text.NumberFormat numberFormat,
UnitFormat unitFormat)
Returns the measure format using the specified number format and unit format (the number and unit are separated by one space). |
static MeasureFormat |
getStandard()
Returns the culture invariant format based upon BigDecimal
canonical format and the standard unit
format. |
abstract Measure<?> |
parse(java.lang.CharSequence csq,
java.text.ParsePosition cursor)
Parses a portion of the specified CharSequence from the
specified position to produce an object. |
Measure<?> |
parseObject(java.lang.String source,
java.text.ParsePosition pos)
|
| 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 |
|---|
public MeasureFormat()
| Method Detail |
|---|
public static MeasureFormat getInstance()
Unit
separated by whitespace(s).
MeasureFormat.getInstance(NumberFormat.getInstance(), UnitFormat.getInstance())
public static MeasureFormat getInstance(java.text.NumberFormat numberFormat,
UnitFormat unitFormat)
numberFormat - the number format.unitFormat - the unit format.
public static MeasureFormat getStandard()
BigDecimal
canonical format and the standard unit
format. This format is not locale-sensitive and can be used for
unambiguous electronic communication of quantities together with their
units without loss of information. For example:
"1.23456789 kg.m/s2" returns
Measure.valueOf(new BigDecimal("1.23456789"), Unit.valueOf("kg.m/s2")));
public abstract java.lang.Appendable format(Measure<?> measure,
java.lang.Appendable dest)
throws java.io.IOException
Appendable.
measure - the measure to format.dest - the appendable destination.
Appendable.
java.io.IOException - if an I/O exception occurs.
public abstract Measure<?> parse(java.lang.CharSequence csq,
java.text.ParsePosition cursor)
throws java.lang.IllegalArgumentException
CharSequence from the
specified position to produce an object. If parsing succeeds, then the
index of the cursor argument is updated to the index after
the last character used.
csq - the CharSequence to parse.cursor - the cursor holding the current parsing index.
java.lang.IllegalArgumentException - if any problem occurs while parsing the specified character
sequence (e.g. illegal syntax).
protected java.lang.Appendable formatCompound(double value,
CompoundUnit<?> unit,
java.lang.Appendable dest)
throws java.io.IOException
CompoundUnit compound units}.
The default implementation is locale sensitive and does not use space to
separate units. For example:
Unit<Length> FOOT_INCH = FOOT.compound(INCH);
Measure<Length> height = Measure.valueOf(1.81, METER);
System.out.println(height.to(FOOT_INCH));
> 5ft11,26in // French Local
Unit<Angle> DMS = DEGREE_ANGLE.compound(MINUTE_ANGLE).compound(SECOND_ANGLE);
Measure<Angle> rotation = Measure.valueOf(35.857497, DEGREE_ANGLE);
System.out.println(rotation.to(DMS));
> 35°51'26,989" // French Local
value - the value to format using compound units.unit - the compound unit.dest - the appendable destination.
Appendable.
java.io.IOException - if an I/O exception occurs.
public final java.lang.StringBuffer format(java.lang.Object obj,
java.lang.StringBuffer toAppendTo,
java.text.FieldPosition pos)
format in class java.text.Format
public final Measure<?> parseObject(java.lang.String source,
java.text.ParsePosition pos)
parseObject in class java.text.Format
public final java.lang.StringBuilder format(Measure<?> measure,
java.lang.StringBuilder dest)
format(Measure, Appendable)
except it does not raise an IOException.
measure - the measure to format.dest - the appendable destination.
StringBuilder.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||