|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.text.Format
javax.measure.unit.UnitFormat
public abstract class UnitFormat
This class provides the interface for formatting and parsing units
.
For all SI
units, the 20 SI prefixes used to form decimal
multiples and sub-multiples of SI units are recognized.
NonSI
units are directly recognized. For example:[code]
Unit.valueOf("m°C").equals(SI.MILLI(SI.CELSIUS))
Unit.valueOf("kW").equals(SI.KILO(SI.WATT))
Unit.valueOf("ft").equals(SI.METER.multiply(0.3048))[/code]
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.text.Format |
---|
Format.Field |
Constructor Summary | |
---|---|
protected |
UnitFormat()
Base constructor. |
Method Summary | |
---|---|
abstract void |
alias(Unit unit,
String alias)
Attaches a system-wide alias to this unit. |
StringBuffer |
format(Object unit,
StringBuffer toAppendTo,
FieldPosition pos)
Formats an unit and appends the resulting text to a given string buffer (implements java.text.Format ). |
abstract Appendable |
format(Unit unit,
Appendable appendable)
Formats the specified unit. |
static UnitFormat |
getAsciiInstance()
Returns the ASCII unit format; this format uses characters range 0000-007F exclusively. |
static UnitFormat |
getHtmlInstance()
Returns the HTML unit format. |
static UnitFormat |
getLocaleInstance()
Returns the locale instance; this format interprets units differently based upon the current runtime locale (e.g. "gal" (gallon) has not the same value in US and UK) |
static UnitFormat |
getStandardInstance()
Returns the standard unit format (format used by Unit.valueOf(CharSequence) and
Unit.toString() ). |
abstract boolean |
isValidIdentifier(String name)
Indicates if the specified name can be used as unit identifier. |
abstract void |
label(Unit unit,
String label)
Attaches a system-wide label to the specified unit. |
abstract Unit<? extends Quantity> |
parse(CharSequence csq,
ParsePosition pos)
Parses a sequence of character to produce an unit. |
Object |
parseObject(String source,
ParsePosition pos)
Parses the text from a string to produce an object (implements java.text.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 |
---|
protected UnitFormat()
Method Detail |
---|
public static UnitFormat getStandardInstance()
Unit.valueOf(CharSequence)
and
Unit.toString()
). This format is independant of
any locale and uses UTF Latin-1 Supplement (range 0080-00FF
)
supported by the majority of fonts. For example: cm³·A²/kg
public static UnitFormat getLocaleInstance()
public static UnitFormat getAsciiInstance()
0000-007F
exclusively.
For example: cm^3*kg^-1*A^2
public static UnitFormat getHtmlInstance()
cm<sup>3</sup>·kg<sup>-1
</sup>·A<sup>2</sup>
(cm3·kg-1·A2
)
public abstract Appendable format(Unit unit, Appendable appendable) throws IOException
unit
- the unit to format.appendable
- the appendable destination.
IOException
- if an error occurs.public abstract Unit<? extends Quantity> parse(CharSequence csq, ParsePosition pos)
csq
- the CharSequence
to parse.pos
- an object holding the parsing index and error position.
Unit
parsed from the character sequence.
IllegalArgumentException
- if the character sequence contains
an illegal syntax.public abstract void label(Unit unit, String label)
unit
- the unit being labelled.label
- the new label for this unit.
IllegalArgumentException
- if the label is not a
isValidIdentifier(String)
valid identifier.public abstract void alias(Unit unit, String alias)
unit
- the unit being aliased.alias
- the alias attached to this unit.
IllegalArgumentException
- if the label is not a
isValidIdentifier(String)
valid identifier.public abstract boolean isValidIdentifier(String name)
getStandardInstance()
) identifiers with
separators (e.g. blank spaces) are not valid.
name
- the identifier to be tested.
true
if the name specified can be used as
label or alias for this format;false
otherwise.public final StringBuffer format(Object unit, StringBuffer toAppendTo, FieldPosition pos)
java.text.Format
).
format
in class Format
unit
- the unit to format.toAppendTo
- where the text is to be appendedpos
- the field position (not used).
toAppendTo
public final Object parseObject(String source, ParsePosition pos)
java.text.Format
).
parseObject
in class Format
source
- the string source, part of which should be parsed.pos
- the cursor position.
null
if the string
cannot be parsed.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |