Package ptolemy.moml.unit
Class UnitExpr
- java.lang.Object
-
- 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$
- Author:
- Rowland R Johnson
- Pt.AcceptedRating:
- Red (rowland)
- Pt.ProposedRating:
- Red (rowland)
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void_setUTerms(java.util.Vector uTerms)voidaddUnitTerm(UnitTerm uTerm)Add a UnitTerm to the expression.UnitExprcopy()Create a copy of this UnitExpr.java.lang.StringdescriptiveForm()The expression of the UnitExpr that is commonly used by humans.UnitgetSingleUnit()If this UnitExpr has one term and it is a Unit then return that Unit.java.util.VectorgetUTerms()Get the UnitTerms in this UnitExpr.UnitExprinvert()Create a new UnitExpr that is the inverse of this UnitExpr.UnitExprreduce()Reduce a UnitExpr to produce a UnitExpr that has at most one Unit.java.lang.StringtoString()
-
-
-
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:
descriptiveFormin interfaceUnitPresentation- 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:
toStringin interfaceUnitPresentation- Overrides:
toStringin classjava.lang.Object
-
_setUTerms
protected void _setUTerms(java.util.Vector uTerms)
-
-