Package ucar.units
Interface UnitFormat
-
- All Known Implementing Classes:
StandardUnitFormat
,UnitFormatImpl
public interface UnitFormat
Interface for classes that parse and format unit specifications.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description String
format(Factor factor)
Formats a Factor (a base unit/exponent pair).StringBuffer
format(Factor factor, StringBuffer buffer)
Appends a formatted factor to a string buffer.String
format(Unit unit)
Formats a unit.StringBuffer
format(Unit unit, StringBuffer buffer)
Appends a formatted unit to a string buffer.String
longFormat(Unit unit)
Formats a unit using a long form.StringBuffer
longFormat(Unit unit, StringBuffer buffer)
Appends a unit formatted according to the long form to a string buffer.Unit
parse(String spec)
Parses a unit specification.Unit
parse(String spec, UnitDB unitDB)
Parses a unit specification.
-
-
-
Method Detail
-
parse
Unit parse(String spec) throws NoSuchUnitException, UnitParseException, SpecificationException, UnitDBException, PrefixDBException, UnitSystemException
Parses a unit specification.- Parameters:
spec
- The unit specification (e.g. "m/s");- Returns:
- The unit corresponding to the specification.
- Throws:
NoSuchUnitException
- A unit in the specification couldn't be found (e.g. the "m" in the example).UnitParseException
- The specification is grammatically incorrect.SpecificationException
- The specification is incorrect somehow.UnitDBException
- Problem with the unit database.PrefixDBException
- Problem with the unit-prefix database.UnitSystemException
- Problem with the system of units.
-
parse
Unit parse(String spec, UnitDB unitDB) throws NoSuchUnitException, UnitParseException, SpecificationException, UnitDBException, PrefixDBException, UnitSystemException
Parses a unit specification.- Parameters:
spec
- The unit specification (e.g. "m/s");unitDB
- The unit database.- Returns:
- The unit corresponding to the specification.
- Throws:
NoSuchUnitException
- A unit in the specification couldn't be found (e.g. the "m" in the example).UnitParseException
- The specification is grammatically incorrect.SpecificationException
- The specification is incorrect somehow.UnitDBException
- Problem with the unit database.PrefixDBException
- Problem with the unit-prefix database.UnitSystemException
- Problem with the system of units.
-
format
String format(Factor factor)
Formats a Factor (a base unit/exponent pair).- Parameters:
factor
- The base unit/exponent pair.- Returns:
- The formatted factor.
-
format
StringBuffer format(Factor factor, StringBuffer buffer)
Appends a formatted factor to a string buffer. A factor is a base unit/exponent pair).- Parameters:
factor
- The base unit/exponent pair.buffer
- The string buffer to be appended to.- Returns:
- The string buffer.
-
format
String format(Unit unit) throws UnitClassException
Formats a unit. If the unit has a symbol or name, then one of them will be used; otherwise, a specification of the unit in terms of underlying units will be returned.- Parameters:
unit
- The unit.- Returns:
- The formatted unit.
- Throws:
UnitClassException
-
longFormat
String longFormat(Unit unit) throws UnitClassException
Formats a unit using a long form. This always returns a specification for the unit in terms of underlying units: it doesn't return the name or symbol of the unit unless the unit is a base unit.- Parameters:
unit
- The unit.- Returns:
- The formatted unit.
- Throws:
UnitClassException
-
format
StringBuffer format(Unit unit, StringBuffer buffer) throws UnitClassException
Appends a formatted unit to a string buffer. This is similar toformat(Unit)
but it appends the specification to a string buffer.- Parameters:
unit
- The unit.buffer
- The string buffer to be appended to.- Returns:
- The string buffer.
- Throws:
UnitClassException
-
longFormat
StringBuffer longFormat(Unit unit, StringBuffer buffer) throws UnitClassException
Appends a unit formatted according to the long form to a string buffer. This is similar tolongFormat(Unit)
but it appends the specification to a string buffer.- Parameters:
unit
- The unit.buffer
- The string buffer to be appended to.- Returns:
- The string buffer.
- Throws:
UnitClassException
-
-