ucar.units
Class UnitFormatImpl

java.lang.Object
  extended by 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.

Version:
$Id: UnitFormatImpl.java 64 2006-07-12 22:30:50Z edavis $
Author:
Steven R. Emmerson

Constructor Summary
UnitFormatImpl()
           
 
Method Summary
 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
 

Constructor Detail

UnitFormatImpl

public UnitFormatImpl()
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 interface UnitFormat
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 interface UnitFormat
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 interface UnitFormat
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 interface UnitFormat
Parameters:
unit - The unit.
Returns:
The formatted unit.
Throws:
UnitClassException


Copyright © 1999-2011 UCAR/Unidata. All Rights Reserved.