ucar.units
Class StandardUnitFormat

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

public final class StandardUnitFormat
extends UnitFormatImpl
implements StandardUnitFormatConstants

Standard formatter/parser for unit specifications. Instances of this class are thread-compatible but not thread-safe.

Author:
Steven R. Emmerson

Field Summary
 Token jj_nt
          Next token.
 Token token
          Current token.
 StandardUnitFormatTokenManager token_source
          Generated Token Manager.
 
Fields inherited from interface ucar.units.StandardUnitFormatConstants
COLON, DEFAULT, DIVIDE, EOF, LB, LETTER, LG, LN, LPAREN, MINUS, NAME, PERIOD, PLUS, RAISE, REAL_EXP, RPAREN, SHIFT, SIGN, SP, STAR, SYMBOL, T, tokenImage, UINT
 
Constructor Summary
StandardUnitFormat(InputStream stream)
          Constructor with InputStream.
StandardUnitFormat(InputStream stream, String encoding)
          Constructor with InputStream and supplied encoding
StandardUnitFormat(Reader stream)
          Constructor.
StandardUnitFormat(StandardUnitFormatTokenManager tm)
          Constructor with generated Token Manager.
 
Method Summary
 Unit basicExpr(UnitDB unitDB)
           
 Calendar clockExpr(Calendar calendar)
           
 Calendar dateExpr()
           
 void disable_tracing()
          Disable tracing.
 void enable_tracing()
          Enable tracing.
 StringBuffer format(Factor factor, StringBuffer buf)
          Formats a Factor.
 StringBuffer format(Unit unit, StringBuffer buf)
          Formats a unit.
 ParseException generateParseException()
          Generate ParseException.
 Token getNextToken()
          Get the next Token.
 Token getToken(int index)
          Get the specific Token.
static StandardUnitFormat instance()
          Returns an instance of this class.
 int integer()
           
 Unit logExpr(UnitDB unitDB)
           
 StringBuffer longFormat(Unit unit, StringBuffer buf)
          Formats a unit in the underlying system of units.
static void main(String[] args)
          Test this class.
 double number()
           
 Unit parse(String spec, UnitDB unitDB)
          Decodes a unit specification.
 Unit powerExpr(UnitDB unitDB)
           
 Unit productExpr(UnitDB unitDB)
           
 double real()
           
 void ReInit(InputStream stream)
          Reinitialise.
 void ReInit(InputStream stream, String encoding)
          Reinitialise.
 void ReInit(Reader stream)
          Reinitialise.
 void ReInit(StandardUnitFormatTokenManager tm)
          Reinitialise.
 Unit shiftExpr(UnitDB unitDB)
           
 int sign()
           
 double tenFactor()
           
 Date timeOriginExpr()
           
 Unit unitIdentifier(UnitDB unitDB)
           
 Unit unitSpec(UnitDB unitDB)
           
 double unsignedDecimal()
           
 int unsignedInteger()
           
 Calendar zoneExpr(Calendar calendar)
           
 
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
Generated Token Manager.


token

public Token token
Current token.


jj_nt

public Token jj_nt
Next token.

Constructor Detail

StandardUnitFormat

public StandardUnitFormat(InputStream stream)
Constructor with InputStream.


StandardUnitFormat

public StandardUnitFormat(InputStream stream,
                          String encoding)
Constructor with InputStream and supplied encoding


StandardUnitFormat

public StandardUnitFormat(Reader stream)
Constructor.


StandardUnitFormat

public StandardUnitFormat(StandardUnitFormatTokenManager tm)
Constructor with generated Token Manager.

Method Detail

instance

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

Returns:
An instance of this class.

parse

public Unit parse(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 StringBuffer format(Factor factor,
                           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 StringBuffer format(Unit unit,
                           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 StringBuffer longFormat(Unit unit,
                               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(String[] args)
                 throws Exception
Test this class.

Throws:
Exception

unitSpec

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

shiftExpr

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

productExpr

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

powerExpr

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

basicExpr

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

logExpr

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

number

public final double number()
                    throws ParseException
Throws:
ParseException

real

public final double real()
                  throws ParseException
Throws:
ParseException

sign

public final int sign()
               throws ParseException
Throws:
ParseException

unsignedDecimal

public final double unsignedDecimal()
                             throws ParseException
Throws:
ParseException

tenFactor

public final double tenFactor()
                       throws ParseException
Throws:
ParseException

integer

public final int integer()
                  throws ParseException
Throws:
ParseException

unsignedInteger

public final int unsignedInteger()
                          throws ParseException
Throws:
ParseException

unitIdentifier

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

timeOriginExpr

public final Date timeOriginExpr()
                          throws ParseException
Throws:
ParseException

dateExpr

public final Calendar dateExpr()
                        throws ParseException
Throws:
ParseException

clockExpr

public final Calendar clockExpr(Calendar calendar)
                         throws ParseException
Throws:
ParseException

zoneExpr

public final Calendar zoneExpr(Calendar calendar)
                        throws ParseException
Throws:
ParseException

ReInit

public void ReInit(InputStream stream)
Reinitialise.


ReInit

public void ReInit(InputStream stream,
                   String encoding)
Reinitialise.


ReInit

public void ReInit(Reader stream)
Reinitialise.


ReInit

public void ReInit(StandardUnitFormatTokenManager tm)
Reinitialise.


getNextToken

public final Token getNextToken()
Get the next Token.


getToken

public final Token getToken(int index)
Get the specific Token.


generateParseException

public ParseException generateParseException()
Generate ParseException.


enable_tracing

public final void enable_tracing()
Enable tracing.


disable_tracing

public final void disable_tracing()
Disable tracing.



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