public abstract class UnitFormat extends java.text.Format
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]
Modifier and Type | Method and Description |
---|---|
abstract void |
alias(Unit<?> unit,
java.lang.String alias)
Attaches a system-wide alias to this unit.
|
java.lang.StringBuffer |
format(java.lang.Object unit,
java.lang.StringBuffer toAppendTo,
java.text.FieldPosition pos)
Formats an unit and appends the resulting text to a given string
buffer (implements
java.text.Format ). |
abstract java.lang.Appendable |
format(Unit<?> unit,
java.lang.Appendable appendable)
Formats the specified unit.
|
static UnitFormat |
getInstance()
Returns the unit format for the default locale (format used by
Unit.valueOf(CharSequence) and
Unit.toString() ). |
static UnitFormat |
getInstance(java.util.Locale inLocale)
Returns the unit format for the specified locale.
|
static UnitFormat |
getUCUMInstance()
Returns the UCUM
international unit format; this format uses characters range
0000-007F exclusively and is not locale-sensitive. |
abstract boolean |
isValidIdentifier(java.lang.String name)
Indicates if the specified name can be used as unit identifier.
|
abstract void |
label(Unit<?> unit,
java.lang.String label)
Attaches a system-wide label to the specified unit.
|
Unit<?> |
parseObject(java.lang.String source,
java.text.ParsePosition pos)
Parses the text from a string to produce an object
(implements
java.text.Format ). |
abstract Unit<? extends Quantity> |
parseProductUnit(java.lang.CharSequence csq,
java.text.ParsePosition pos)
Parses a sequence of character to produce a unit or a rational product
of unit.
|
abstract Unit<? extends Quantity> |
parseSingleUnit(java.lang.CharSequence csq,
java.text.ParsePosition pos)
Parses a sequence of character to produce a single unit.
|
public static UnitFormat getInstance()
Unit.valueOf(CharSequence)
and
Unit.toString()
).public static UnitFormat getInstance(java.util.Locale inLocale)
public static UnitFormat getUCUMInstance()
0000-007F
exclusively and is not locale-sensitive.
For example: kg.m/s2
public abstract java.lang.Appendable format(Unit<?> unit, java.lang.Appendable appendable) throws java.io.IOException
unit
- the unit to format.appendable
- the appendable destination.java.io.IOException
- if an error occurs.public abstract Unit<? extends Quantity> parseProductUnit(java.lang.CharSequence csq, java.text.ParsePosition pos) throws java.text.ParseException
csq
- the CharSequence
to parse.pos
- an object holding the parsing index and error position.Unit
parsed from the character sequence.java.lang.IllegalArgumentException
- if the character sequence contains
an illegal syntax.java.text.ParseException
public abstract Unit<? extends Quantity> parseSingleUnit(java.lang.CharSequence csq, java.text.ParsePosition pos) throws java.text.ParseException
csq
- the CharSequence
to parse.pos
- an object holding the parsing index and error position.Unit
parsed from the character sequence.java.lang.IllegalArgumentException
- if the character sequence does not contain
a valid unit identifier.java.text.ParseException
public abstract void label(Unit<?> unit, java.lang.String label)
unit
- the unit being labelled.label
- the new label for this unit.java.lang.IllegalArgumentException
- if the label is not a
isValidIdentifier(String)
valid identifier.public abstract void alias(Unit<?> unit, java.lang.String alias)
unit
- the unit being aliased.alias
- the alias attached to this unit.java.lang.IllegalArgumentException
- if the label is not a
isValidIdentifier(String)
valid identifier.public abstract boolean isValidIdentifier(java.lang.String name)
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 java.lang.StringBuffer format(java.lang.Object unit, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
java.text.Format
).format
in class java.text.Format
unit
- the unit to format.toAppendTo
- where the text is to be appendedpos
- the field position (not used).toAppendTo
public final Unit<?> parseObject(java.lang.String source, java.text.ParsePosition pos)
java.text.Format
).parseObject
in class java.text.Format
source
- the string source, part of which should be parsed.pos
- the cursor position.null
if the string
cannot be parsed.