public class UnitTable extends java.lang.Object implements UnitsDB, java.io.Serializable
| Constructor and Description |
|---|
UnitTable(int numNames)
Construct.
|
UnitTable(int numNames,
int numSymbols)
Construct.
|
| Modifier and Type | Method and Description |
|---|---|
Unit |
get(java.lang.String name)
Get a unit.
|
protected Unit |
getByName(java.lang.String name)
Get a unit by name.
|
protected Unit |
getBySymbol(java.lang.String symbol)
Get a unit by symbol.
|
java.util.Enumeration |
getNameEnumeration()
Get an enumeration of the unit names in the table.
|
java.util.Enumeration |
getSymbolEnumeration()
Get an enumeration of the unit symbols in the table.
|
java.util.Enumeration |
getUnitEnumeration()
Get an enumeration of the units in the table.
|
void |
list()
List the units in the database.
|
static void |
main(java.lang.String[] args)
Test this class.
|
protected java.lang.String |
makePlural(java.lang.String name)
Returns the plural form of a name.
|
void |
put(BaseUnit unit)
Adds a base unit.
|
void |
putName(java.lang.String name,
Unit unit)
Adds a name and a unit to the name table.
|
void |
putSymbol(java.lang.String symbol,
Unit unit)
Adds a symbol and a unit to the symbol table.
|
java.lang.String |
toString()
Return a string representation of this instance.
|
public UnitTable(int numNames)
throws java.lang.IllegalArgumentException
numNames - Anticipated minimum number of names in the
database.java.lang.IllegalArgumentException - numNames < 0.public UnitTable(int numNames,
int numSymbols)
throws java.lang.IllegalArgumentException
numNames - Anticipated minimum number of names in the
database.numSymbols - Anticipated minimum number of symbols in the
database.java.lang.IllegalArgumentException - numNames < 0 || numSymbols < 0
.public Unit get(java.lang.String name)
protected Unit getByName(java.lang.String name)
name - The name of the unit to be retrieved. If it is
the empty string, then the dimensionless, unity
unit
will be returned.name is non-null.protected Unit getBySymbol(java.lang.String symbol)
symbol - The exact symbol of the unit to be retrieved. If it is
the empty string, then the dimensionless, unity
unit
will be returned.name is non-null.public void put(BaseUnit unit) throws java.lang.IllegalArgumentException
protected java.lang.String makePlural(java.lang.String name)
name - The name.public void putName(java.lang.String name,
Unit unit)
public void putSymbol(java.lang.String symbol,
Unit unit)
public java.util.Enumeration getNameEnumeration()
getNameEnumeration in interface UnitsDBpublic java.util.Enumeration getSymbolEnumeration()
getSymbolEnumeration in interface UnitsDBpublic java.util.Enumeration getUnitEnumeration()
getUnitEnumeration in interface UnitsDBpublic java.lang.String toString()
toString in class java.lang.Objectpublic static void main(java.lang.String[] args)
throws java.lang.Exception
java.lang.Exception - A problem occurred.