Package ucar.units
Class StandardUnitFormat
- java.lang.Object
-
- ucar.units.UnitFormatImpl
-
- 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.
-
-
Field Summary
Fields Modifier and Type Field Description Tokenjj_ntNext token.TokentokenCurrent token.StandardUnitFormatTokenManagertoken_sourceGenerated Token Manager.
-
Constructor Summary
Constructors Constructor Description StandardUnitFormat(InputStream stream)Constructor with InputStream.StandardUnitFormat(InputStream stream, String encoding)Constructor with InputStream and supplied encodingStandardUnitFormat(Reader stream)Constructor.StandardUnitFormat(StandardUnitFormatTokenManager tm)Constructor with generated Token Manager.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description UnitbasicExpr(UnitDB unitDB)CalendarclockExpr(Calendar calendar)CalendardateExpr()voiddisable_tracing()Disable tracing.voidenable_tracing()Enable tracing.StringBufferformat(Factor factor, StringBuffer buf)Formats a Factor.StringBufferformat(Unit unit, StringBuffer buf)Formats a unit.ParseExceptiongenerateParseException()Generate ParseException.TokengetNextToken()Get the next Token.TokengetToken(int index)Get the specific Token.static StandardUnitFormatinstance()Returns an instance of this class.intinteger()UnitlogExpr(UnitDB unitDB)StringBufferlongFormat(Unit unit, StringBuffer buf)Formats a unit in the underlying system of units.doublenumber()Unitparse(String spec, UnitDB unitDB)Decodes a unit specification.UnitpowerExpr(UnitDB unitDB)UnitproductExpr(UnitDB unitDB)doublereal()voidReInit(InputStream stream)Reinitialise.voidReInit(InputStream stream, String encoding)Reinitialise.voidReInit(Reader stream)Reinitialise.voidReInit(StandardUnitFormatTokenManager tm)Reinitialise.UnitshiftExpr(UnitDB unitDB)intsign()doubletenFactor()DatetimeOriginExpr()UnitunitIdentifier(UnitDB unitDB)UnitunitSpec(UnitDB unitDB)doubleunsignedDecimal()intunsignedInteger()CalendarzoneExpr(Calendar calendar)-
Methods inherited from class ucar.units.UnitFormatImpl
format, format, longFormat, parse
-
-
-
-
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:
parsein interfaceUnitFormat- 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:
formatin interfaceUnitFormat- 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:
formatin interfaceUnitFormat- 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:
longFormatin interfaceUnitFormat- 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.
-
unitSpec
public final Unit unitSpec(UnitDB unitDB) throws ParseException, OperationException, UnitSystemException, PrefixDBException, UnitDBException
-
shiftExpr
public final Unit shiftExpr(UnitDB unitDB) throws ParseException, OperationException, UnitSystemException, PrefixDBException, UnitDBException
-
productExpr
public final Unit productExpr(UnitDB unitDB) throws ParseException, OperationException, UnitSystemException, PrefixDBException, UnitDBException
-
powerExpr
public final Unit powerExpr(UnitDB unitDB) throws ParseException, OperationException, UnitSystemException, PrefixDBException, UnitDBException
-
basicExpr
public final Unit basicExpr(UnitDB unitDB) throws ParseException, OperationException, UnitSystemException, PrefixDBException, UnitDBException
-
logExpr
public final Unit logExpr(UnitDB unitDB) 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
-
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.
-
-