Package ptolemy.moml.unit
Class UnitTerm
- java.lang.Object
-
- ptolemy.moml.unit.UnitTerm
-
- All Implemented Interfaces:
UnitPresentation
public class UnitTerm extends java.lang.Object implements UnitPresentation
UnitTerm represents a term in a Unit Expression. A UnitTerm has 1) an exponent and 2) an element. The element can be either 1) a Unit, 2) a variable, or 3) a Unit Expression. These choices for element are mutually exclusive. UnitTerms are usually constructed as a result of parsing a Unit Expression.- 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
_setType(int type)
UnitTerm
copy()
Make a shallow copy of this UnitTerm.java.lang.String
descriptiveForm()
Create a String that is understandable by a human.int
getExponent()
Unit
getUnit()
Get the element if it is a Unit.UnitExpr
getUnitExpr()
Get the element if it is a UnitExpr.java.lang.String
getVariable()
Get the element if it is a variable.UnitTerm
invert()
Invert this UnitTerm.boolean
isUnit()
True if this is a Unit.boolean
isUnitExpr()
True is this is a UnitExpr.boolean
isVariable()
True if this a variable.void
setExponent(int exponent)
Set the exponent.void
setUnit(Unit unit)
Set the element to be a Unit.void
setUnitExpr(UnitExpr expr)
Set the element to be a UnitExpr.void
setVariable(java.lang.String v)
Set the element to be a variablejava.lang.String
toString()
java.lang.Object
visit(EquationVisitor visitor)
Visit an instance of UnitTerm.
-
-
-
Constructor Detail
-
UnitTerm
public UnitTerm()
Construct a UnitTerm with no element.
-
UnitTerm
public UnitTerm(Unit unit)
Construct an instance where the contained element is a Unit.- Parameters:
unit
- The Unit that will be the element of this instance.
-
-
Method Detail
-
copy
public UnitTerm copy()
Make a shallow copy of this UnitTerm. That is, the underlying Unit or UnitExpr is not copied.- Returns:
- The copy of this UnitTerm
-
descriptiveForm
public java.lang.String descriptiveForm()
Create a String that is understandable by a human.- Specified by:
descriptiveForm
in interfaceUnitPresentation
- Returns:
- The descriptive form.
- See Also:
UnitPresentation.descriptiveForm()
-
getExponent
public int getExponent()
- Returns:
- The exponent.
-
getUnit
public Unit getUnit()
Get the element if it is a Unit.- Returns:
- The Unit if the element is a Unit, otherwise null.
-
getUnitExpr
public UnitExpr getUnitExpr()
Get the element if it is a UnitExpr.- Returns:
- The UnitExpr if the element is a UnitExpr, otherwise null.
-
getVariable
public java.lang.String getVariable()
Get the element if it is a variable.- Returns:
- The variable if the element is a variable, null otherwise.
-
invert
public UnitTerm invert()
Invert this UnitTerm.- Returns:
- The inverse of this UnitTerm.
-
isUnit
public boolean isUnit()
True if this is a Unit.- Returns:
- True if this is a Unit.
-
isUnitExpr
public boolean isUnitExpr()
True is this is a UnitExpr.- Returns:
- True is this is a UnitExpr.
-
isVariable
public boolean isVariable()
True if this a variable.- Returns:
- True if this a variable.
-
setExponent
public void setExponent(int exponent)
Set the exponent.- Parameters:
exponent
- The exponent.
-
setUnit
public void setUnit(Unit unit)
Set the element to be a Unit.- Parameters:
unit
- The Unit.
-
setUnitExpr
public void setUnitExpr(UnitExpr expr)
Set the element to be a UnitExpr.- Parameters:
expr
- The Unit Expression.
-
setVariable
public void setVariable(java.lang.String v)
Set the element to be a variable- Parameters:
v
- The variable.
-
toString
public java.lang.String toString()
- Specified by:
toString
in interfaceUnitPresentation
- Overrides:
toString
in classjava.lang.Object
-
visit
public java.lang.Object visit(EquationVisitor visitor) throws IllegalActionException
Visit an instance of UnitTerm.- Parameters:
visitor
- The visitor.- Returns:
- The result of visiting the UnitTerm.
- Throws:
IllegalActionException
-
_setType
protected void _setType(int type)
- Parameters:
type
- The Unit type.
-
-