net.sourceforge.unit
Class UnitSystem

java.lang.Object
  extended by net.sourceforge.unit.UnitSystem
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
Chemistry, English, EnglishR, Metric, MetricK

public class UnitSystem
extends java.lang.Object
implements java.lang.Cloneable

A UnitSystem is a collection of prefered units, such as metric or English. For example, if want to convert from Metric units to inches, you can use the following code:

   English e = new English();
   e.add("in");
   System.out.println("length: "+ e.pick( Unit.makeUnit("m"))); // prints "in"
   System.out.println("area: "+e.pick( Unit.makeUnit("m^2")));// prints "in^2"
   System.out.println("area: "+e.pick( Unit.makeUnit("acre")));// prints "in^2"
   System.out.println("force: "+ e.pick( Unit.makeUnit("N"))); // prints "lb"
   System.out.println("mass: "+ e.pick( Unit.makeUnit("kg"))); // prints "lbm"
   

Version:
$Name: $, $Revision: 1.3 $
Author:
Fred Gylys-Colwell

Constructor Summary
UnitSystem()
          Create a default system of units -- Metric, without special units like W, N or J.
UnitSystem(java.lang.String[] a)
          Create a default system of units -- and add all the units in a to it.
 
Method Summary
 void add(java.lang.String u)
          Add the unit u to this system.
 void add(java.lang.String[] u)
          Add the unit u to this system.
 void add(Unit u)
          Add the unit u to this system.
 void add(Unit[] u)
          Add the unit u to this system.
 boolean addPrimitive(Unit u)
          This attempts to add a unit as a measurement of one of the seven primitives.
 java.lang.Object clone()
           
 Unit pick(Unit u)
          Return the unit in this system that is the same type as u.
 void remove(java.lang.String u)
          Remove this unit from the list of prefered units.
 void remove(Unit u)
          Remove this unit from the list of prefered units.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UnitSystem

public UnitSystem()
Create a default system of units -- Metric, without special units like W, N or J.


UnitSystem

public UnitSystem(java.lang.String[] a)
           throws ParseException
Create a default system of units -- and add all the units in a to it.

Throws:
ParseException
Method Detail

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

add

public void add(java.lang.String u)
         throws ParseException
Add the unit u to this system. See add for more information.

Throws:
ParseException

add

public void add(java.lang.String[] u)
         throws ParseException
Add the unit u to this system. See add for more information.

Throws:
ParseException

add

public void add(Unit[] u)
Add the unit u to this system. See add for more information.


add

public void add(Unit u)
Add the unit u to this system. If the unit is a primitive type, such as length, it will be used for all mixed units, such as area. It replaces any unit in this system with the same type.


remove

public void remove(Unit u)
Remove this unit from the list of prefered units. It only works if on non-primitive units.


remove

public void remove(java.lang.String u)
Remove this unit from the list of prefered units. It only works if on non-primitive units.


addPrimitive

public boolean addPrimitive(Unit u)
This attempts to add a unit as a measurement of one of the seven primitives. The defaults are m, sec, kg, K, mol, A, and cd. Note: non-absolute temperature scales will not be made primitive.


pick

public Unit pick(Unit u)
Return the unit in this system that is the same type as u.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object