ptolemy.data.unit
Class UnitExpr

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

public class UnitExpr
extends java.lang.Object
implements UnitPresentation

A UnitExpr contains UnitTerms.

Since:
Ptolemy II 4.0
Version:
$Id: UnitExpr.java,v 1.13 2004/04/20 16:48:57 rowland Exp $
Author:
Rowland R Johnson
Accepted Rating:
Red (rowland)
Proposed Rating:
Red (rowland)

Constructor Summary
UnitExpr()
          Construct an empty (i.e. no UnitTerms) UnitExpr.
UnitExpr(IOPort ioPort)
          Construct a UnitTerm from an IOPort.
 
Method Summary
protected  void _setUTerms(java.util.Vector uTerms)
           
 void addUnitTerm(UnitTerm uTerm)
          Add a UnitTerm to the expression.
 UnitExpr copy()
          Create a copy of this UnitExpr.
 java.lang.String descriptiveForm()
          The expression of the UnitExpr that is commonly used by humans.
 Unit getSingleUnit()
          If this UnitExpr has one term and it is a Unit then return that Unit.
 java.util.Vector getUTerms()
          Get the UnitTerms in this UnitExpr.
 UnitExpr invert()
          Create a new UnitExpr that is the inverse of this UnitExpr.
 UnitExpr reduce()
          Reduce a UnitExpr to produce a UnitExpr that has at most one Unit.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UnitExpr

public UnitExpr()
Construct an empty (i.e. no UnitTerms) UnitExpr.


UnitExpr

public UnitExpr(IOPort ioPort)
Construct a UnitTerm from an IOPort. The constructed UnitExpr will have one UnitTerm and it will be a variable with the name being that of the port.

Parameters:
ioPort - The IOPort.
Method Detail

addUnitTerm

public void addUnitTerm(UnitTerm uTerm)
Add a UnitTerm to the expression.

Parameters:
uTerm - The UnitTerm.

copy

public UnitExpr copy()
Create a copy of this UnitExpr.

Returns:
The new UnitExpr.

descriptiveForm

public java.lang.String descriptiveForm()
The expression of the UnitExpr that is commonly used by humans.

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

getSingleUnit

public Unit getSingleUnit()
If this UnitExpr has one term and it is a Unit then return that Unit.

Returns:
The Unit if there is a single UnitTerm, and it is a Unit, null otherwise.

getUTerms

public java.util.Vector getUTerms()
Get the UnitTerms in this UnitExpr.

Returns:
The UnitTerms.

invert

public UnitExpr invert()
Create a new UnitExpr that is the inverse of this UnitExpr.

Returns:
The invers of this UnitExpr.

reduce

public UnitExpr reduce()
Reduce a UnitExpr to produce a UnitExpr that has at most one Unit. Any embedded UnitExpr is first transformed so that all embedded UnitExprs are replaced with Units. This intermediate result is a mixture of Units and variables. The Units are then replaced with their product. The result is a single Unit and all of the original variables.

Returns:
The reduced UnitExpr.

toString

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

_setUTerms

protected void _setUTerms(java.util.Vector uTerms)