ptolemy.data.unit
Class Unit

java.lang.Object
  extended byptolemy.data.unit.Unit
All Implemented Interfaces:
UnitPresentation

public class Unit
extends java.lang.Object
implements UnitPresentation

Class that contains the internal representation of a Unit. A Unit has the mathematical notation S<E1, E2, ..., En> where S is the scale and <E1, E2, ..., En> is the type of the Unit.

This class also contains methods for operating on Units, such as multiply, divide, etc.

Since:
Ptolemy II 4.0
Version:
$Id: Unit.java,v 1.17 2004/04/22 16:25:37 rowland Exp $
Author:
Rowland R Johnson
Accepted Rating:
Red (rowland)
Proposed Rating:
Red (rowland)

Constructor Summary
Unit()
          Create a Unit with no name and the unitless type.
Unit(BaseUnit bu)
          Create a Unit from a BaseUnit.
Unit(java.lang.String name)
          Create a Unit with a specified name, and the unitless type.
 
Method Summary
protected  void _setLabels(java.util.Vector labels)
          Set the labels of the Unit.
 Unit copy()
          Make a copy of this Unit.
 java.lang.String descriptiveForm()
          The expression of the Unit that is commonly used by humans.
 Unit divideBy(Unit divisor)
          Divide this Unit by another Unit.
 boolean equals(Unit otherUnit)
          Return True if this Unit equals another Unit.
 UnitExpr factor()
          Factor a Unit into a UnitExpr that has UnitTerms that are in the Library.
 java.util.Vector getLabels()
          Get the labels for a Unit.
 java.lang.String getLabelsString()
          Create a String that is the concatenation of all the labels.
 java.lang.String getPrimaryLabel()
          Get the primary label of a Unit.
 double getScale()
          Get the scale.
 int[] getType()
          Get the type (represented as a int array) of this Unit.
 boolean hasSameType(Unit otherUnit)
          Return true if the Unit has the same type as another Unit.
 Unit invert()
          Invert this Unit.
 Unit multiplyBy(Unit multiplicand)
          Multiply this Unit by another Unit.
 Unit pow(double power)
          Returns of value of this Unit raised to the power of the argument.
 void setPrimaryLabel(java.lang.String label)
          Set the primary label.
 void setScale(double d)
          Set the scale.
 void setType(int[] type)
          Set the type.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Unit

public Unit()
Create a Unit with no name and the unitless type.


Unit

public Unit(BaseUnit bu)
Create a Unit from a BaseUnit.

Parameters:
bu - BaseUnit that provides the basis for this Unit.

Unit

public Unit(java.lang.String name)
Create a Unit with a specified name, and the unitless type.

Parameters:
name - Name of the Unit.
Method Detail

copy

public Unit copy()
Make a copy of this Unit.

Returns:
A new Unit.

descriptiveForm

public java.lang.String descriptiveForm()
The expression of the Unit that is commonly used by humans. For example, the unit 4.1868E7<2, 1, -3, 0, 0> will produce the common expression "calorie second^-1".

Specified by:
descriptiveForm in interface UnitPresentation
Returns:
The descriptive form.
See Also:
UnitPresentation.descriptiveForm()

divideBy

public Unit divideBy(Unit divisor)
Divide this Unit by another Unit.

Parameters:
divisor - The divisor unit.
Returns:
This Unit divided by the divisor.

equals

public boolean equals(Unit otherUnit)
Return True if this Unit equals another Unit.

Parameters:
otherUnit - The Unit to be compared against.
Returns:
True if this Unit equals the other Unit.

factor

public UnitExpr factor()
Factor a Unit into a UnitExpr that has UnitTerms that are in the Library. In general, factorization is a lengthy process, and this method is not a complete factorization algorithm. It only tries some of the more likely combinations.

Returns:
UnitExpr that is equivalent to to the Unit.

getLabels

public java.util.Vector getLabels()
Get the labels for a Unit.

Returns:
The labels.
See Also:
getPrimaryLabel()

getLabelsString

public java.lang.String getLabelsString()
Create a String that is the concatenation of all the labels.

Returns:
The concatenation of the labels.

getPrimaryLabel

public java.lang.String getPrimaryLabel()
Get the primary label of a Unit. A Unit can have more than one label. For example, cm, and centimeter are labels for the same Unit. There always exists a label that is primary.

Returns:
The primary label.

getScale

public double getScale()
Get the scale.

Returns:
Scale.

getType

public int[] getType()
Get the type (represented as a int array) of this Unit.

Returns:
The type (represented as a int array) of this Unit.

hasSameType

public boolean hasSameType(Unit otherUnit)
Return true if the Unit has the same type as another Unit.

Parameters:
otherUnit -
Returns:
True if the Unit has the same type as the argument.

invert

public Unit invert()
Invert this Unit.

Returns:
The inverse of this Unit.

multiplyBy

public Unit multiplyBy(Unit multiplicand)
Multiply this Unit by another Unit.

Parameters:
multiplicand -
Returns:
The product of this Unit multiplied by the argument.

pow

public Unit pow(double power)
Returns of value of this Unit raised to the power of the argument.

Parameters:
power - The exponent.
Returns:
This Unit raised to the power of the argument.

setPrimaryLabel

public void setPrimaryLabel(java.lang.String label)
Set the primary label.

Parameters:
label - The primary label.

setScale

public void setScale(double d)
Set the scale.

Parameters:
d - The scale.

setType

public void setType(int[] type)
Set the type.

Parameters:
type -

toString

public java.lang.String toString()
Specified by:
toString in interface UnitPresentation

_setLabels

protected void _setLabels(java.util.Vector labels)
Set the labels of the Unit.

Parameters:
labels - The labels.