Class 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)
    • Constructor Summary

      Constructors 
      Constructor Description
      UnitTerm()
      Construct a UnitTerm with no element.
      UnitTerm​(Unit unit)
      Construct an instance where the contained element is a Unit.
    • 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
      • 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
      • _setType

        protected void _setType​(int type)
        Parameters:
        type - The Unit type.