All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class units.Unit

java.lang.Object
   |
   +----units.Unit

public class Unit
extends Object
implements Cloneable, Serializable
This class embodies the pair <v, u> and is used directly by the application programmer. It has a parser that generates the internal representation from the character string expression of a unit. It also provides all the operators to calculate with units, multiplication, division and raising to a power.

Version:
$Id: Unit.java,v 1.4 1998/08/31 23:42:57 schadow Exp schadow $
Author:
Gunther Schadow

Variable Index

 o cnv
 o cnv_pfx
This provides for the SI anomality of allowing prefixes on the Degree celsius.
 o name
 o nu
 o u_vec

Constructor Index

 o Unit()
Instantiate the Unit "" = 1 (the unity)
 o Unit(String)
Parse a unit term
 o Unit(String, double, Dimension)
Instantiate a unit <nu, u_vec> with name.
 o Unit(String, double, Dimension, Function, double)
Instantiate a unit <nu, u_vec> with name and conversion functions.

Method Index

 o assign(Unit)
Sets this unit to be equal to another unit u.
 o assignUnity()
Assign the unity (= dimensionless unit 1) to this unit.
 o caseSensitive()
 o caseSensitive(boolean)
 o clone()
 o convertCoherent(double)
Converts measurement mu * this unit into a coherent unit.
 o convertFrom(double, Unit)
Converts a measurement mu * u into this unit.
 o convertTo(double, Unit)
Converts a measurement mu * this unit into other unit u.
 o dim()
Returns the dimension of this unit
 o div(Unit)
Divides this unit u1 with another unit u2.
 o dump()
 o equals(Unit)
Tests for equality of this unit u1 and another unit u2.
 o inv()
Invert this unit with respect to multiplication.
 o mul(double)
Multiplies this unit u with a scalar s.
 o mul(Unit)
Multiplies this unit u1 with another unit u2.
 o mutateCoherent(double)
Mutates this unit into a coherent unit and converts a measurement mu
 o mutateRatio(double)
Mutates this unit into a unit on a ratio scale and converts measurement mu
 o pow(int)
Raises this unit u to a power p.
 o toString()
Returns the string representation (i.e.

Variables

 o name
 protected String name
 o nu
 protected double nu
 o u_vec
 protected Dimension u_vec
 o cnv
 protected Function cnv
 o cnv_pfx
 protected double cnv_pfx
This provides for the SI anomality of allowing prefixes on the Degree celsius.

Constructors

 o Unit
 public Unit()
Instantiate the Unit "" = 1 (the unity)

 o Unit
 public Unit(String _name,
             double _nu,
             Dimension _u_vec,
             Function _cnv,
             double _cnv_pfx)
Instantiate a unit <nu, u_vec> with name and conversion functions.

 o Unit
 public Unit(String _name,
             double _nu,
             Dimension _u_vec)
Instantiate a unit <nu, u_vec> with name.

 o Unit
 public Unit(String term)
Parse a unit term

Methods

 o caseSensitive
 public static void caseSensitive(boolean cs)
 o caseSensitive
 public static boolean caseSensitive()
 o clone
 public Object clone()
Overrides:
clone in class Object
 o equals
 public boolean equals(Unit u2)
Tests for equality of this unit u1 and another unit u2.

Returns:
true if u1 and u2 are equal, false otherwise.
 o assign
 public Unit assign(Unit u)
Sets this unit to be equal to another unit u.

Returns:
this unit after assignment to u
 o assignUnity
 public Unit assignUnity()
Assign the unity (= dimensionless unit 1) to this unit.

 o dim
 public Dimension dim()
Returns the dimension of this unit

 o toString
 public String toString()
Returns the string representation (i.e. the name) of the unit

Overrides:
toString in class Object
 o dump
 public void dump()
 o convertFrom
 public double convertFrom(double mu1,
                           Unit u1)
Converts a measurement mu * u into this unit.

Returns:
the converted measurement value
Throws: IllegalArgumentException
if dimensions differ.
 o convertTo
 public double convertTo(double mu,
                         Unit u)
Converts a measurement mu * this unit into other unit u.

Returns:
the converted measurement value
Throws: IllegalArgumentException
if dimensions differ.
 o convertCoherent
 public double convertCoherent(double mu)
Converts measurement mu * this unit into a coherent unit.

Returns:
the converted measurement value
Throws: IllegalArgumentException
if dimensions differ.
 o mutateCoherent
 public double mutateCoherent(double mu)
Mutates this unit into a coherent unit and converts a measurement mu

Returns:
the converted measurement value
Throws: IllegalArgumentException
if dimensions differ.
 o mutateRatio
 public double mutateRatio(double mu)
Mutates this unit into a unit on a ratio scale and converts measurement mu

Returns:
the converted measurement value
Throws: IllegalArgumentException
if dimensions differ.
 o mul
 public Unit mul(double s)
Multiplies this unit u with a scalar s. Special meaning for special units so that (0.1*B) is 1 dB.

Returns:
the product u * s.
Throws: IllegalArgumentException
if u is on a non-ratio scale.
 o mul
 public Unit mul(Unit u2)
Multiplies this unit u1 with another unit u2. If one of the factors is a non-ratio unit the other must be dimensionless or else an exception is raised. This special case treatment allows to scale non-ratio units.

Returns:
the product u1 * u2
Throws: IllegalArgumentException
if one of the unit is not on a ratio-scale and the other is not dimensionless.
 o div
 public Unit div(Unit u2)
Divides this unit u1 with another unit u2. If u1 is not on a ratio scale an exception is raised. Mutating to a ratio scale unit is not possible for a unit, only for a measurement.

Returns:
the quotient u1 / u2
Throws: IllegalArgumentException
if a unit is not on a ratio-scale.
 o inv
 public Unit inv()
Invert this unit with respect to multiplication. If u1 is not on a ratio scale an exception is raised. Mutating to a ratio scale unit is not possible for a unit, only for a measurement.

Returns:
1/u.
Throws: IllegalArgumentException
if u is not on a ratio-scale.
 o pow
 public Unit pow(int p)
Raises this unit u to a power p. If u1 is not on a ratio scale an exception is raised. Mutating to a ratio scale unit is not possible for a unit, only for a measurement.

Returns:
the power u^p.
Throws: IllegalArgumentException
if u is not on a ratio-scale.

All Packages  Class Hierarchy  This Package  Previous  Next  Index