public abstract class UCUMFormat
extends tec.uom.se.format.AbstractUnitFormat
This class provides the interface for formatting and parsing
units
according to the
Uniform Code for CommonUnits of
Measure (UCUM).
For a technical/historical overview of this format please read CommonUnits of Measure in Clinical Information Systems.
As of revision 1.16, the BNF in the UCUM standard contains an error. I've attempted to work around the problem by modifying the BNF productions for <Term>. Once the error in the standard is corrected, it may be necessary to modify the productions in the UCUMFormatParser.jj file to conform to the standard.
Modifier and Type | Class and Description |
---|---|
private static class |
UCUMFormat.Parsing
The Parsing format outputs formats and parses units according to the
"c/s" or "c/i" column in the UCUM standard, depending on which SymbolMap
is passed to its constructor.
|
private static class |
UCUMFormat.Print
The Print format is used to output units according to the "print" column
in the UCUM standard.
|
static class |
UCUMFormat.Variant
Variant of unit representation in the UCUM standard
|
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
BUNDLE_BASE |
(package private) tec.uom.se.format.SymbolMap |
symbolMap
The symbol map used by this instance to map between
Unit s and String s. |
Constructor and Description |
---|
UCUMFormat(tec.uom.se.format.SymbolMap symbolMap)
Base constructor.
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
appendAnnotation(java.lang.CharSequence symbol,
java.lang.CharSequence annotation,
java.lang.Appendable appendable) |
java.lang.Appendable |
format(javax.measure.Unit<?> unknownUnit,
java.lang.Appendable appendable) |
(package private) void |
formatConverter(javax.measure.UnitConverter converter,
boolean continued,
java.lang.StringBuilder buffer)
Formats the given converter to the given StringBuffer.
|
static UCUMFormat |
getInstance(UCUMFormat.Variant variant)
Returns the instance for formatting/parsing using the given variant
|
static UCUMFormat |
getInstance(UCUMFormat.Variant variant,
tec.uom.se.format.SymbolMap symbolMap)
Returns an instance for formatting and parsing using user defined symbols
|
protected tec.uom.se.format.SymbolMap |
getSymbols()
Get the symbol map used by this instance to map between
Unit s and String s, etc... |
boolean |
isLocaleSensitive() |
void |
label(javax.measure.Unit<?> unit,
java.lang.String label) |
abstract javax.measure.Unit<? extends javax.measure.Quantity<?>> |
parse(java.lang.CharSequence csq) |
protected javax.measure.Unit<?> |
parse(java.lang.CharSequence csq,
int index) |
abstract javax.measure.Unit<? extends javax.measure.Quantity<?>> |
parse(java.lang.CharSequence csq,
java.text.ParsePosition cursor) |
private static final java.lang.String BUNDLE_BASE
final tec.uom.se.format.SymbolMap symbolMap
Unit
s and String
s.public static UCUMFormat getInstance(UCUMFormat.Variant variant)
variant
- the UCUM variant to usepublic static UCUMFormat getInstance(UCUMFormat.Variant variant, tec.uom.se.format.SymbolMap symbolMap)
variant
- the UCUM variant to usesymbolMap
- the map of user defined symbols to useprotected tec.uom.se.format.SymbolMap getSymbols()
Unit
s and String
s, etc...getSymbols
in class tec.uom.se.format.AbstractUnitFormat
public abstract javax.measure.Unit<? extends javax.measure.Quantity<?>> parse(java.lang.CharSequence csq, java.text.ParsePosition cursor) throws javax.measure.format.ParserException
parse
in class tec.uom.se.format.AbstractUnitFormat
javax.measure.format.ParserException
protected javax.measure.Unit<?> parse(java.lang.CharSequence csq, int index) throws javax.measure.format.ParserException
parse
in class tec.uom.se.format.AbstractUnitFormat
javax.measure.format.ParserException
public abstract javax.measure.Unit<? extends javax.measure.Quantity<?>> parse(java.lang.CharSequence csq) throws javax.measure.format.ParserException
javax.measure.format.ParserException
public java.lang.Appendable format(javax.measure.Unit<?> unknownUnit, java.lang.Appendable appendable) throws java.io.IOException
format
in interface javax.measure.format.UnitFormat
format
in class tec.uom.se.format.AbstractUnitFormat
java.io.IOException
public void label(javax.measure.Unit<?> unit, java.lang.String label)
label
in interface javax.measure.format.UnitFormat
label
in class tec.uom.se.format.AbstractUnitFormat
public boolean isLocaleSensitive()
void appendAnnotation(java.lang.CharSequence symbol, java.lang.CharSequence annotation, java.lang.Appendable appendable) throws java.io.IOException
java.io.IOException
void formatConverter(javax.measure.UnitConverter converter, boolean continued, java.lang.StringBuilder buffer)
ConverterFormat
does, but there's no need to worry about
operator precedence here, since UCUM only supports multiplication,
division, and exponentiation and expressions are always evaluated left-
to-right.converter
- the converter to be formattedcontinued
- true
if the converter expression should begin
with an operator, otherwise false
. This will
always be true unless the unit being modified is equal to
Unit.ONE.buffer
- the StringBuffer
to append to. Contains the
already-formatted unit being modified by the given converter.