ptolemy.moml.unit
Class UnitLibrary

java.lang.Object
  extended by ptolemy.moml.unit.UnitLibrary

public class UnitLibrary
extends java.lang.Object

A Library containing definitions of commonly used units. Currently, the Unit library is static in the sense that it is loaded when the system starts and is hard-wired to a particular Unit System (the System International Unit System). However, it should be easy to change the architecture so that multiple Unit Systems can be accommodated, and loaded on-the-fly.

Since:
Ptolemy II 8.0
Version:
$Id: UnitLibrary.java 57044 2010-01-27 22:41:05Z cxh $
Author:
Rowland R Johnson
Accepted Rating:
Red (rowland)
Proposed Rating:
Red (rowland)

Nested Class Summary
private  class UnitLibrary.UnitNameExprPair
          UnitNameExprPair
 
Field Summary
private static boolean _debug
           
private static int _numCats
           
private static UParser _parser
           
private static java.util.Vector _unitsLibrary
           
static Unit Identity
          The Identity Unit, i.e. 1.0*<0, 0, ..., 0>
 
Constructor Summary
UnitLibrary()
           
 
Method Summary
static void addToLibrary(Unit unit)
          Add a unit to the Library.
static Unit getBaseUnit(int catNum)
          Find the Unit in the library that is basic (scale equal to 1), singular (all but one dimensions equal to 0).
static Unit getClosestUnit(Unit unit)
          Search Library to find Unit that has the same type and is the closest to a unit in terms of the scalars.
static java.util.Vector getLibrary()
          Return the Library.
static int getNumCategories()
          Return the number of categories.
static UParser getParser()
          Return the Parser.
static Unit getUnit(Unit unit)
          Search Library for Unit equal to a particular unit.
static Unit getUnitByName(java.lang.String name)
          Search the Library for a unit with a particular name.
static java.util.Vector getUnitsByType(Unit unit)
          Search Library for all Units with type equal to this one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Identity

public static final Unit Identity
The Identity Unit, i.e. 1.0*<0, 0, ..., 0>


_debug

private static boolean _debug

_numCats

private static int _numCats

_parser

private static UParser _parser

_unitsLibrary

private static java.util.Vector _unitsLibrary
Constructor Detail

UnitLibrary

public UnitLibrary()
Method Detail

addToLibrary

public static void addToLibrary(Unit unit)
Add a unit to the Library.

Parameters:
unit - Unit to add to the library.

getBaseUnit

public static Unit getBaseUnit(int catNum)
Find the Unit in the library that is basic (scale equal to 1), singular (all but one dimensions equal to 0).

Parameters:
catNum - The category number.
Returns:
The basic, singular unit.

getClosestUnit

public static Unit getClosestUnit(Unit unit)
Search Library to find Unit that has the same type and is the closest to a unit in terms of the scalars.

Parameters:
unit - The unit for which to search.
Returns:
The Unit closest to this the argument. Null, if there are no Units in the Library with the same type.

getLibrary

public static java.util.Vector getLibrary()
Return the Library.

Returns:
The Library

getNumCategories

public static int getNumCategories()
Return the number of categories.

Returns:
Number of categories.

getParser

public static UParser getParser()
Return the Parser.

Returns:
The Parser.

getUnit

public static Unit getUnit(Unit unit)
Search Library for Unit equal to a particular unit. That is, both the type and scalar must be equal to the argument.

Parameters:
unit - The unit to search for.
Returns:
Unit in Library equal to this one. Null if none found.

getUnitByName

public static Unit getUnitByName(java.lang.String name)
Search the Library for a unit with a particular name.

Parameters:
name - The name of the desired unit.
Returns:
The unit with name equal to the argument. Null, if the Library doesn't have a unit with that name.

getUnitsByType

public static java.util.Vector getUnitsByType(Unit unit)
Search Library for all Units with type equal to this one.

Parameters:
unit - The unit to search for.
Returns:
Vector of Units with type equal to the argument.