bb.science
Class Unit

java.lang.Object
  extended by bb.science.Unit

public class Unit
extends Object

Models a unit of measurement. It has name, symbol, and description properties.

This class also offers static constants which are Unit instances that model the SI base units. (Exception: we take the gram (instead of the kilogram) to be our base unit of mass, as this works much better with the Prefix class.)

This class is multithread safe: it is immutable (both its immediate state, as well as the deep state of its fields).

Author:
Brent Boyer
See Also:
SI base units

Nested Class Summary
static class Unit.UnitTest
          See the Overview page of the project's javadocs for a general description of this unit test class.
 
Field Summary
static Unit ampere
          Models the SI base unit of electric current, the ampere.
static Unit candela
          Models the SI base unit of luminous intensity, the candela.
protected  String description
          A description of the underlying quantity associated with the unit (e.g. length, mass, etc).
static Unit gram
          Models the SI unit of mass, the gram.
static Unit kelvin
          Models the SI base unit of thermodynamic temperature, the kelvin.
static Unit meter
          Models the SI base unit of length, the meter.
static Unit mole
          Models the SI base unit of amount of substance, the mole.
protected  String name
          The full name of the unit (e.g. meter, gram).
static Unit second
          Models the SI base unit of time, the second.
protected  String symbol
          The symbol for the unit (e.g. m, g, etc).
 
Constructor Summary
Unit(String name, String symbol, String description)
          Constructs a new Unit instance for the supplied name, symbol, and description.
 
Method Summary
 String getDescription()
          Returns a description of the underlying quantity associated with the unit (e.g. length, mass, etc).
 String getName()
          Returns the full name of the unit (e.g. meter, gram).
static Unit[] getSiBaseUnits()
          Returns an array of all the SI base units.
 String getSymbol()
          Returns the symbol for the unit (e.g. m, g, etc).
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

meter

public static final Unit meter
Models the SI base unit of length, the meter.


gram

public static final Unit gram
Models the SI unit of mass, the gram. (We use this as our base unit of mass, and not the kg as the SI does, in order to work with our Prefix class.)


second

public static final Unit second
Models the SI base unit of time, the second.


ampere

public static final Unit ampere
Models the SI base unit of electric current, the ampere.


kelvin

public static final Unit kelvin
Models the SI base unit of thermodynamic temperature, the kelvin.


mole

public static final Unit mole
Models the SI base unit of amount of substance, the mole.


candela

public static final Unit candela
Models the SI base unit of luminous intensity, the candela.


name

protected final String name
The full name of the unit (e.g. meter, gram).


symbol

protected final String symbol
The symbol for the unit (e.g. m, g, etc).


description

protected final String description
A description of the underlying quantity associated with the unit (e.g. length, mass, etc).

Constructor Detail

Unit

public Unit(String name,
            String symbol,
            String description)
     throws IllegalArgumentException
Constructs a new Unit instance for the supplied name, symbol, and description.

Throws:
IllegalArgumentException - if any arg is either null or all whitespace
Method Detail

getSiBaseUnits

public static final Unit[] getSiBaseUnits()
Returns an array of all the SI base units.


getName

public String getName()
Returns the full name of the unit (e.g. meter, gram).


getSymbol

public String getSymbol()
Returns the symbol for the unit (e.g. m, g, etc).


getDescription

public String getDescription()
Returns a description of the underlying quantity associated with the unit (e.g. length, mass, etc).


toString

public String toString()
Overrides:
toString in class Object