| java.lang.Object java.text.Format javax.measure.unit.UnitFormat
UnitFormat | abstract public class UnitFormat extends Format (Code) | | This class provides the interface for formatting and parsing
Unit 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]
author: Jean-Marie Dautelle author: Eric Russell version: 1.3, August 29, 2006 |
Inner Class :protected static class DefaultFormat extends UnitFormat | |
Inner Class :protected static class ASCIIFormat extends DefaultFormat | |
Constructor Summary | |
protected | UnitFormat() Base constructor. |
UnitFormat | protected UnitFormat()(Code) | | Base constructor.
|
alias | abstract public void alias(Unit> unit, String alias)(Code) | | Attaches a system-wide alias to this unit. Multiple aliases may
be attached to the same unit. Aliases are used during parsing to
recognize different variants of the same unit. For example:
[code]
UnitFormat.getLocaleInstance().alias(METER.multiply(0.3048), "foot");
UnitFormat.getLocaleInstance().alias(METER.multiply(0.3048), "feet");
UnitFormat.getLocaleInstance().alias(METER, "meter");
UnitFormat.getLocaleInstance().alias(METER, "metre");
[/code]
If the specified label is already associated to an unit the previous
association is discarded or ignored.
Parameters: unit - the unit being aliased. Parameters: alias - the alias attached to this unit. throws: IllegalArgumentException - if the label is not a UnitFormat.isValidIdentifier(String) valid identifier. |
format | final public StringBuffer format(Object unit, StringBuffer toAppendTo, FieldPosition pos)(Code) | | Formats an unit and appends the resulting text to a given string
buffer (implements java.text.Format ).
Parameters: unit - the unit to format. Parameters: toAppendTo - where the text is to be appended Parameters: pos - the field position (not used). toAppendTo |
getInstance | public static UnitFormat getInstance(Locale inLocale)(Code) | | Returns the unit format for the specified locale.
the unit format for the specified locale. |
getUCUMInstance | public static UnitFormat getUCUMInstance()(Code) | | Returns the UCUM
international unit format; this format uses characters range
0000-007F exclusively and is not locale-sensitive.
For example: kg.m/s2
the UCUM international format. |
isValidIdentifier | abstract public boolean isValidIdentifier(String name)(Code) | | Indicates if the specified name can be used as unit identifier.
Parameters: name - the identifier to be tested. true if the name specified can be used as label or alias for this format;false otherwise. |
label | abstract public void label(Unit> unit, String label)(Code) | | Attaches a system-wide label to the specified unit. For example:
[code]
UnitFormat.getInstance().label(DAY.multiply(365), "year");
UnitFormat.getInstance().label(METER.multiply(0.3048), "ft");
[/code]
If the specified label is already associated to an unit the previous
association is discarded or ignored.
Parameters: unit - the unit being labelled. Parameters: label - the new label for this unit. throws: IllegalArgumentException - if the label is not a UnitFormat.isValidIdentifier(String) valid identifier. |
parseObject | final public Unit> parseObject(String source, ParsePosition pos)(Code) | | Parses the text from a string to produce an object
(implements java.text.Format ).
Parameters: source - the string source, part of which should be parsed. Parameters: pos - the cursor position. the corresponding unit or null if the string cannot be parsed. |
parseProductUnit | abstract public Unit<? extends Quantity> parseProductUnit(CharSequence csq, ParsePosition pos) throws ParseException(Code) | | Parses a sequence of character to produce a unit or a rational product
of unit.
Parameters: csq - the CharSequence to parse. Parameters: pos - an object holding the parsing index and error position. an Unit parsed from the character sequence. throws: IllegalArgumentException - if the character sequence containsan illegal syntax. |
parseSingleUnit | abstract public Unit<? extends Quantity> parseSingleUnit(CharSequence csq, ParsePosition pos) throws ParseException(Code) | | Parses a sequence of character to produce a single unit.
Parameters: csq - the CharSequence to parse. Parameters: pos - an object holding the parsing index and error position. an Unit parsed from the character sequence. throws: IllegalArgumentException - if the character sequence does not contain a valid unit identifier. |
|
|