## visad.data.units
Class UnitTable

    java.lang.Object
      visad.data.units.UnitTable

All Implemented Interfaces:
  Serializable, UnitsDB

Direct Known Subclasses:
  DefaultUnitsDB

public class UnitTable
extends Object
implements UnitsDB, Serializable

Provides support for a table of units.

See Also:
  Serialized Form

Constructor Summary
`UnitTable(int numNames)` Construct.
`UnitTable(int numNames, int numSymbols)` Construct.

Method Summary
`Unit` `get(String name)` Get a unit.
`protected Unit` `getByName(String name)` Get a unit by name.
`protected Unit` `getBySymbol(String symbol)` Get a unit by symbol.
`Enumeration` `getNameEnumeration()` Get an enumeration of the unit names in the table.
`Enumeration` `getSymbolEnumeration()` Get an enumeration of the unit symbols in the table.
`Enumeration` `getUnitEnumeration()` Get an enumeration of the units in the table.
`void` `list()` List the units in the database.
`static void` `main(String[] args)` Test this class.
`protected String` `makePlural(String name)` Returns the plural form of a name.
`void` `put(BaseUnit unit)` Adds a base unit.
`void` `putName(String name, Unit unit)` Adds a name and a unit to the name table.
`void` `putSymbol(String symbol, Unit unit)` Adds a symbol and a unit to the symbol table.
`String` `toString()` Return a string representation of this instance.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### UnitTable

    public UnitTable(int numNames)
              throws IllegalArgumentException

  Construct.

Parameters:
  `numNames` - Anticipated minimum number of names in the database.
Throws:
  `IllegalArgumentException` - `numNames < 0`.

### UnitTable

    public UnitTable(int numNames,
                     int numSymbols)
              throws IllegalArgumentException

  Construct.

Parameters:
  `numNames` - Anticipated minimum number of names in the database.
  `numSymbols` - Anticipated minimum number of symbols in the database.
Throws:
  `IllegalArgumentException` - `numNames < 0 || numSymbols < 0` .

Method Detail

### get

    public Unit get(String name)

  Get a unit.

  Specified by:
    `get` in interface `UnitsDB`
  Parameters:
    `name` - The exact name of the unit to be retrieved. If it is the empty string, then the dimensionless, unity unit will be returned.
  Returns:
    The unit of the matching entry or null if not found.

### getByName

    protected Unit getByName(String name)

  Get a unit by name.

  Parameters:
    `name` - The name of the unit to be retrieved. If it is the empty string, then the dimensionless, unity unit will be returned.
  Returns:
    The unit of the matching entry or null if not found.

### getBySymbol

    protected Unit getBySymbol(String symbol)

  Get a unit by symbol.

  Parameters:
    `symbol` - The exact symbol of the unit to be retrieved. If it is the empty string, then the dimensionless, unity unit will be returned.
  Returns:
    The unit of the matching entry or null if not found.

### put

    public void put(BaseUnit unit)
             throws IllegalArgumentException

  Adds a base unit.

  Specified by:
    `put` in interface `UnitsDB`
  Throws:
    `IllegalArgumentException` - The base unit argument is invalid.

### makePlural

    protected String makePlural(String name)

  Returns the plural form of a name. Regular rules are used to generate the plural form.

  Parameters:
    `name` - The name.
  Returns:
    The plural form of the name.

### putName

    public void putName(String name,
                        Unit unit)

  Adds a name and a unit to the name table.

  Specified by:
    `putName` in interface `UnitsDB`
  Parameters:
    `name` - The name to be added.
    `unit` - The unit to be added.
  Throws:
    `IllegalArgumentException` - Invalid argument.

### putSymbol

    public void putSymbol(String symbol,
                          Unit unit)

  Adds a symbol and a unit to the symbol table.

  Specified by:
    `putSymbol` in interface `UnitsDB`
  Parameters:
    `symbol` - The symbol to be added.
    `unit` - The unit to be added.
  Throws:
    `IllegalArgumentException` - Invalid argument.

### getNameEnumeration

    public Enumeration getNameEnumeration()

  Get an enumeration of the unit names in the table. The Object returned by nextElement() is a String.

  Specified by:
    `getNameEnumeration` in interface `UnitsDB`

### getSymbolEnumeration

    public Enumeration getSymbolEnumeration()

  Get an enumeration of the unit symbols in the table. The Object returned by nextElement() is a String.

  Specified by:
    `getSymbolEnumeration` in interface `UnitsDB`

### getUnitEnumeration

    public Enumeration getUnitEnumeration()

  Get an enumeration of the units in the table. The Object returned by nextElement() is a Unit.

  Specified by:
    `getUnitEnumeration` in interface `UnitsDB`

### toString

    public String toString()

  Return a string representation of this instance.

### main

    public static void main(String[] args)
                     throws Exception

  Test this class.

  Throws:
    `Exception` - A problem occurred.

### list

    public void list()

  List the units in the database.

  Specified by:
    `list` in interface `UnitsDB`