|
Java Units API Build 2004-02-06 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Object Format UnitFormat
This is the abstract base class for all unit formats.
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:
Unit.valueOf("m°C") == SI.MILLI(SI.CELSIUS) Unit.valueOf("kW") == SI.KILO(SI.WATT) Unit.valueOf("ft") == SI.METER.multiply(0.3048)
Nested Class Summary |
Nested classes inherited from class Format |
Format.Field |
Constructor Summary | |
UnitFormat()
|
Method Summary | |
static Unit |
alias(Unit unit,
String alias)
Attaches a system-wide alias to the specified unit. |
abstract StringBuffer |
format(Object obj,
StringBuffer toAppendTo,
FieldPosition pos)
Formats a unit and appends the resulting text to a given string buffer. |
static UnitFormat |
getAsciiInstance()
Returns the ASCII unit format. |
static UnitFormat |
getHtmlInstance()
Returns the HTML unit format. |
static UnitFormat |
getInstance()
Returns the default unit format for the current default locale. |
static UnitFormat |
getStandardInstance()
Returns the standard unit format. |
static boolean |
isUnitIdentifierPart(char ch)
Determines if the specified character may be part of a unit identifier. |
static Unit |
label(Unit unit,
String label)
Attaches a system-wide label to the specified unit. |
String |
labelFor(Unit unit)
Returns the label for the specified unit. |
Object |
parseObject(String source,
ParsePosition pos)
Parses text from a string to produce an object. |
Unit |
parseUnit(CharSequence source)
Parses text from a character sequence to produce a unit. |
Unit |
unitFor(CharSequence label)
Returns the unit identified by the specified label. |
Methods inherited from class Format |
clone, format, formatToCharacterIterator, parseObject |
Methods inherited from class Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public UnitFormat()
Method Detail |
public static Unit label(Unit unit, String label)
UnitFormat.label(DAY.multiply(365), "year");
Unit FOOT = UnitFormat.label(METER.multiply(0.3048), "ft");
unit
- the unit being associated to the specified label.label
- the new label for the specified unit or null
to detache the previous label (if any).
IllegalArgumentException
- if the specified label is a known symbol
or if the specified label is already attached to a different
unit (must be detached first).labelFor(javax.units.Unit)
,
alias(javax.units.Unit, java.lang.String)
public static Unit alias(Unit unit, String alias)
UnitFormat.alias(METER.multiply(0.3048), "foot");
UnitFormat.alias(METER.multiply(0.3048), "feet");
UnitFormat.alias(METER, "meter");
UnitFormat.alias(METER, "metre");
unit
- the unit being aliased.alias
- the alias being attached to the specified unit.
unitFor(java.lang.CharSequence)
public static final UnitFormat getInstance()
centimétre cube par kilogramme fois Ampére carré
(French locale).
public static final UnitFormat getStandardInstance()
0080-00FF
) supported by the majority of fonts.
For example: cm³·A²/kg
Unit.toString()
).public static final UnitFormat getAsciiInstance()
0000-007F
exclusively.
For example: cm^3 kg^-1 A^2
public static final UnitFormat getHtmlInstance()
cm<sup>3</sup>·kg<sup>-1
</sup>·A<sup>2</sup>
(cm3·kg-1·A2
)
public static boolean isUnitIdentifierPart(char ch)
ch
- the character to be tested.
true
if the character may be part of a unit
identifier; false
otherwise.public abstract StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
obj
- the unit to format.toAppendTo
- where the text is to be appendedpos
- a FieldPosition
identifying a field
in the formatted text (not used).
toAppendTo
,
with formatted text appended.
NullPointerException
- if toAppendTo
is
null
IllegalArgumentException
- if this format cannot format the given
object (e.g. not a Unit
instance).public final Object parseObject(String source, ParsePosition pos)
source
- a String
, part of which should be parsed.pos
- a ParsePosition
object with index and error
index information.
Object
parsed from the string. In case of
error, returns null.parseUnit(java.lang.CharSequence)
public Unit parseUnit(CharSequence source) throws ParseException
The expected form of the character sequence is:
{<name>{<power>{<root>}}}
For examples:
HTML tags are ignored (e.g. <sup>...</sup>).
Escape sequences are considered as separators (e.g. ·).
"/" (if not placed between two numbers) indicates ALL the following
unit exponents will be multiplied by -1
; multiple
instances of "/"
in a line will result in successive
implicit multiplications by -1
of all the exponents that follow (e.g. "s/s/s"
is equivalent to "s"
).
source
- the characters sequence to be parsed.
Unit
parsed from the string.
ParseException
- if a parsing error occurs.public String labelFor(Unit unit)
unit
- the unit to format.
[K+273.15], [m*0.01]
) or
null
for units with custom converters or
ProductUnit
with no label.unitFor(java.lang.CharSequence)
public Unit unitFor(CharSequence label)
label
- the label, alias, or symbol identifying the unit.
null
if the identification fails.labelFor(javax.units.Unit)
|
Java Units API Build 2004-02-06 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Symbols, terms and definitions | JSR-108 project |