ucar.units
Class StandardUnitFormat

java.lang.Object
  extended by ucar.units.UnitFormatImpl
      extended by ucar.units.StandardUnitFormat
All Implemented Interfaces:
java.io.Serializable, StandardUnitFormatConstants, UnitFormat

public final class StandardUnitFormat
extends UnitFormatImpl
implements StandardUnitFormatConstants

Standard formatter/parser for unit specifications.

Author:
Steven R. Emmerson
See Also:
Serialized Form

Field Summary
 Token jj_nt
           
 boolean lookingAhead
           
 Token token
           
 StandardUnitFormatTokenManager token_source
           
 
Fields inherited from interface ucar.units.StandardUnitFormatConstants
DEFAULT, DIVIDE, E, EOF, LETTER, NAME, PER, SHIFT, SINCE, SYMBOL, T, tokenImage, UINT, UTC, WHITESPACE, Z
 
Constructor Summary
StandardUnitFormat(java.io.InputStream stream)
           
StandardUnitFormat(java.io.Reader stream)
           
StandardUnitFormat(StandardUnitFormatTokenManager tm)
           
 
Method Summary
 void disable_tracing()
           
 void enable_tracing()
           
 java.lang.StringBuffer format(Factor factor, java.lang.StringBuffer buf)
          Formats a Factor.
 java.lang.StringBuffer format(Unit unit, java.lang.StringBuffer buf)
          Formats a unit.
 ParseException generateParseException()
           
 Token getNextToken()
           
 Token getToken(int index)
           
static StandardUnitFormat instance()
          Returns an instance of this class.
 int integer()
           
 java.lang.StringBuffer longFormat(Unit unit, java.lang.StringBuffer buf)
          Formats a unit in the underlying system of units.
static void main(java.lang.String[] args)
          Test this class.
 double number()
           
 double numericalOriginExpression()
           
 Unit parse(java.lang.String spec, UnitDB unitDB)
          Decodes a unit specification.
 int powerExpression()
           
 void ReInit(java.io.InputStream stream)
           
 void ReInit(java.io.Reader stream)
           
 void ReInit(StandardUnitFormatTokenManager tm)
           
 int sign()
           
 java.util.Date timeOriginExpression()
           
 Unit unitFactor(UnitDB unitDB)
           
 Unit unitIdentifier(UnitDB unitDB)
           
 Unit unitSpec(UnitDB unitDB)
           
 Unit unitTerm(UnitDB unitDB)
           
 double unsignedDecimal()
           
 int unsignedInteger()
           
 
Methods inherited from class ucar.units.UnitFormatImpl
format, format, longFormat, parse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

token_source

public StandardUnitFormatTokenManager token_source

token

public Token token

jj_nt

public Token jj_nt

lookingAhead

public boolean lookingAhead
Constructor Detail

StandardUnitFormat

public StandardUnitFormat(java.io.InputStream stream)

StandardUnitFormat

public StandardUnitFormat(java.io.Reader stream)

StandardUnitFormat

public StandardUnitFormat(StandardUnitFormatTokenManager tm)
Method Detail

instance

public static StandardUnitFormat instance()
Returns an instance of this class.

Returns:
An instance of this class.

parse

public Unit parse(java.lang.String spec,
                  UnitDB unitDB)
           throws UnitParseException,
                  SpecificationException,
                  UnitDBException,
                  PrefixDBException,
                  UnitSystemException
Decodes a unit specification. An unrecognized unit is made into an UnknownUnit.

Specified by:
parse in interface UnitFormat
Parameters:
spec - The unit specification to be decoded.
unitDB - The unit database to use.
Returns:
The unit corresponding to the specification.
Throws:
UnitParseException - The unit specification syntax is invalid.
SpecificationException - Something's wrong with the specification.
UnitDBException - Something's wrong with the unit database.
PrefixDBException - Something's wrong with the unit prefix database.
UnitSystemException - Something's wrong with the underlying system of units.

format

public java.lang.StringBuffer format(Factor factor,
                                     java.lang.StringBuffer buf)
Formats a Factor.

Specified by:
format in interface UnitFormat
Parameters:
factor - The factor to be formatted.
buf - The buffer to append to.
Returns:
The appended-to buffer.

format

public java.lang.StringBuffer format(Unit unit,
                                     java.lang.StringBuffer buf)
                              throws UnitClassException
Formats a unit. The symbol or name will be used if available; otherwise, a specification in terms of underlying units will be returned.

Specified by:
format in interface UnitFormat
Parameters:
unit - The unit to be formatted.
buf - The buffer to append to.
Returns:
The appended-to buffer.
Throws:
UnitClassException - The class of the unit is unknown.

longFormat

public java.lang.StringBuffer longFormat(Unit unit,
                                         java.lang.StringBuffer buf)
                                  throws UnitClassException
Formats a unit in the underlying system of units.

Specified by:
longFormat in interface UnitFormat
Parameters:
unit - The unit to be formatted.
buf - The buffer to append to.
Returns:
The appended-to buffer.
Throws:
UnitClassException - The class of the unit is unknown.

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Test this class.

Throws:
java.lang.Exception

unitSpec

public final Unit unitSpec(UnitDB unitDB)
                    throws ParseException,
                           OperationException,
                           UnitSystemException,
                           PrefixDBException,
                           UnitDBException
Throws:
ParseException
OperationException
UnitSystemException
PrefixDBException
UnitDBException

unitTerm

public final Unit unitTerm(UnitDB unitDB)
                    throws ParseException,
                           OperationException,
                           UnitSystemException,
                           PrefixDBException,
                           UnitDBException
Throws:
ParseException
OperationException
UnitSystemException
PrefixDBException
UnitDBException

unitFactor

public final Unit unitFactor(UnitDB unitDB)
                      throws ParseException,
                             OperationException,
                             UnitSystemException,
                             PrefixDBException,
                             UnitDBException
Throws:
ParseException
OperationException
UnitSystemException
PrefixDBException
UnitDBException

numericalOriginExpression

public final double numericalOriginExpression()
                                       throws ParseException
Throws:
ParseException

number

public final double number()
                    throws ParseException
Throws:
ParseException

integer

public final int integer()
                  throws ParseException
Throws:
ParseException

sign

public final int sign()
               throws ParseException
Throws:
ParseException

unsignedInteger

public final int unsignedInteger()
                          throws ParseException
Throws:
ParseException

unsignedDecimal

public final double unsignedDecimal()
                             throws ParseException
Throws:
ParseException

powerExpression

public final int powerExpression()
                          throws ParseException
Throws:
ParseException

unitIdentifier

public final Unit unitIdentifier(UnitDB unitDB)
                          throws ParseException,
                                 UnitDBException,
                                 UnitSystemException,
                                 PrefixDBException
Throws:
ParseException
UnitDBException
UnitSystemException
PrefixDBException

timeOriginExpression

public final java.util.Date timeOriginExpression()
                                          throws ParseException
Throws:
ParseException

ReInit

public void ReInit(java.io.InputStream stream)

ReInit

public void ReInit(java.io.Reader stream)

ReInit

public void ReInit(StandardUnitFormatTokenManager tm)

getNextToken

public final Token getNextToken()

getToken

public final Token getToken(int index)

generateParseException

public ParseException generateParseException()

enable_tracing

public final void enable_tracing()

disable_tracing

public final void disable_tracing()