net.sourceforge.unit
Class Quantity

java.lang.Object
  extended by net.sourceforge.unit.Quantity

public class Quantity
extends java.lang.Object

A Quantity is a number together with a unit.

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

Field Summary
static net.sourceforge.jmisc.Format defaultFormat
           
 net.sourceforge.jmisc.Format format
           
static int NO_CHANGE
          Returned by set() if there is no unit change.
static int UNIT_CHANGE
          Returned by set() if there was a unit changed.
static int UNITS_INCOMPATIBLE
          Returned by set() if there the unit changed, and it is not of the same type.
 
Constructor Summary
Quantity()
           
Quantity(java.lang.String s)
          Create a quantity based on the given string.
Quantity(java.lang.String s, Unit def)
          Create a quantity with the default units specified.
 
Method Summary
 void convert(Unit u)
          Change units, but not the value.
 void convert(UnitSystem s)
          Change units, but not the value.
 double get()
          Return this value in the current units.
 double in(Unit u)
          Return this value in the specified units.
 void set(double x)
          Set this value based on the current unit.
 void set(double x, Unit u)
          Set this value based on the supplied unit.
 int set(java.lang.String s)
          Set this value and possibly change units.
 int set(java.lang.String s, boolean sloppy)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

defaultFormat

public static net.sourceforge.jmisc.Format defaultFormat

format

public net.sourceforge.jmisc.Format format

NO_CHANGE

public static int NO_CHANGE
Returned by set() if there is no unit change.


UNIT_CHANGE

public static int UNIT_CHANGE
Returned by set() if there was a unit changed.


UNITS_INCOMPATIBLE

public static int UNITS_INCOMPATIBLE
Returned by set() if there the unit changed, and it is not of the same type.

Constructor Detail

Quantity

public Quantity()

Quantity

public Quantity(java.lang.String s)
         throws ParseException
Create a quantity based on the given string.

Throws:
ParseException

Quantity

public Quantity(java.lang.String s,
                Unit def)
         throws ParseException,
                UnitMismatchException
Create a quantity with the default units specified.

Throws:
ParseException
UnitMismatchException
Method Detail

get

public double get()
Return this value in the current units.


in

public double in(Unit u)
Return this value in the specified units.


convert

public void convert(Unit u)
Change units, but not the value.


convert

public void convert(UnitSystem s)
Change units, but not the value.


set

public void set(double x)
Set this value based on the current unit.


set

public void set(double x,
                Unit u)
Set this value based on the supplied unit.


set

public int set(java.lang.String s)
        throws ParseException,
               UnitMismatchException,
               java.lang.NumberFormatException
Set this value and possibly change units.

Throws:
ParseException
UnitMismatchException
java.lang.NumberFormatException

set

public int set(java.lang.String s,
               boolean sloppy)
        throws ParseException,
               UnitMismatchException,
               java.lang.NumberFormatException
Throws:
ParseException
UnitMismatchException
java.lang.NumberFormatException

toString

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