ptolemy.moml.unit
Class UnitTerm

java.lang.Object
  extended by 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: UnitTerm.java 57044 2010-01-27 22:41:05Z cxh $
Author:
Rowland R Johnson
Accepted Rating:
Red (rowland)
Proposed Rating:
Red (rowland)

Field Summary
private  int _exponent
           
private  int _type
           
private  Unit _unit
           
private static int _UNIT
           
private  UnitExpr _unitExpr
           
private static int _UNITEXPR
           
private  java.lang.String _variable
           
private static int _VARIABLE
           
 
Constructor Summary
UnitTerm()
          Construct a UnitTerm with no element.
UnitTerm(Unit unit)
          Construct an instance where the contained element is a Unit.
 
Method Summary
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 variable
 java.lang.String toString()
           
 java.lang.Object visit(EquationVisitor visitor)
          Visit an instance of UnitTerm.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_UNIT

private static final int _UNIT
See Also:
Constant Field Values

_UNITEXPR

private static final int _UNITEXPR
See Also:
Constant Field Values

_VARIABLE

private static final int _VARIABLE
See Also:
Constant Field Values

_exponent

private int _exponent

_type

private int _type

_unit

private Unit _unit

_unitExpr

private UnitExpr _unitExpr

_variable

private java.lang.String _variable
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 interface UnitPresentation
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 interface UnitPresentation
Overrides:
toString in class java.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.