ptolemy.moml.unit
Class UnitExpr

java.lang.Object
  extended by ptolemy.moml.unit.UnitExpr
All Implemented Interfaces:
UnitPresentation

public class UnitExpr
extends java.lang.Object
implements UnitPresentation

A UnitExpr contains UnitTerms.

Since:
Ptolemy II 8.0
Version:
$Id: UnitExpr.java 57044 2010-01-27 22:41:05Z cxh $
Author:
Rowland R Johnson
Accepted Rating:
Red (rowland)
Proposed Rating:
Red (rowland)

Field Summary
(package private)  boolean _isFlat
           
(package private)  java.util.Vector _uTerms
           
 
Constructor Summary
UnitExpr()
          Construct an empty (i.e. no UnitTerms) UnitExpr.
UnitExpr(IOPort ioPort)
          Construct a UnitTerm from an IOPort.
 
Method Summary
private  void _flatten()
           
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
 

Field Detail

_isFlat

boolean _isFlat

_uTerms

java.util.Vector _uTerms
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 inverse 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
Overrides:
toString in class java.lang.Object

_setUTerms

protected void _setUTerms(java.util.Vector uTerms)

_flatten

private void _flatten()