Package ucar.units
Class UnitFormatImpl
- java.lang.Object
-
- ucar.units.UnitFormatImpl
-
- All Implemented Interfaces:
UnitFormat
- Direct Known Subclasses:
StandardUnitFormat
public abstract class UnitFormatImpl extends Object implements UnitFormat
Provides support for classes that parse and format unit specifications. Instances are thread-safe.
-
-
Constructor Summary
Constructors Constructor Description UnitFormatImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
format(Factor factor)
Formats a Factor (a base unit/exponent pair).String
format(Unit unit)
Formats a unit.String
longFormat(Unit unit)
Formats a unit using a long form.Unit
parse(String spec)
Parses a unit specification.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ucar.units.UnitFormat
format, format, longFormat, parse
-
-
-
-
Method Detail
-
parse
public final Unit parse(String spec) throws NoSuchUnitException, UnitParseException, SpecificationException, UnitDBException, PrefixDBException, UnitSystemException
Parses a unit specification. This method is thread-safe.- Specified by:
parse
in interfaceUnitFormat
- 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.
-
format
public final String format(Factor factor)
Formats a Factor (a base unit/exponent pair).- Specified by:
format
in interfaceUnitFormat
- Parameters:
factor
- The base unit/exponent pair.- Returns:
- The formatted factor.
-
format
public final 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.- Specified by:
format
in interfaceUnitFormat
- Parameters:
unit
- The unit.- Returns:
- The formatted unit.
- Throws:
UnitClassException
-
longFormat
public final 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.- Specified by:
longFormat
in interfaceUnitFormat
- Parameters:
unit
- The unit.- Returns:
- The formatted unit.
- Throws:
UnitClassException
-
-