com.rubecula.jquantity
Class Units

java.lang.Object
  |
  +--com.rubecula.jquantity.Item
        |
        +--com.rubecula.jquantity.BaseUnit
              |
              +--com.rubecula.jquantity.UnitsFoundation
                    |
                    +--com.rubecula.jquantity.Units
All Implemented Interfaces:
Auditable, java.lang.Cloneable, java.lang.Comparable, Identifiable, Measurable, Nameable, Presentable, java.io.Serializable

public class Units
extends UnitsFoundation
implements Measurable, java.lang.Cloneable

This class extends UnitsFoundation by adding instance fields: _A, _B, _PowerA, _PowerB, _Scale, _Offset and _System.

New version of Units introduced February 2002.
In this new version, we make use of an Interface Measurable which provides both the scale and the dimensions of a unit. There are three implementers of Measurable:

This class is not yet fully implemented.

Version:
$Revision: 1.4 $
Author:
Robin Hillyard
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class com.rubecula.jquantity.UnitsFoundation
UnitsFoundation.UnitsException
 
Field Summary
(package private) static java.lang.String AA
           
(package private) static java.lang.String AAC
           
(package private) static java.lang.String ABA
           
(package private) static java.lang.String AMP
           
(package private) static Units Ampere
           
(package private) static java.lang.String ANGAM
           
(package private) static java.lang.String ANGAS
           
(package private) static java.lang.String ANGD
           
(package private) static java.lang.String ANGG
           
(package private) static java.lang.String ANGR
           
(package private) static java.lang.String ANGX
           
(package private) static Units Candela
           
(package private) static java.lang.String CHRG
           
(package private) static Units Coulomb
           
(package private) static Units CoulombPerMole
           
(package private) static java.lang.String CUSD
           
(package private) static Units Day
           
(package private) static java.lang.String DEGC
           
(package private) static java.lang.String DEGF
           
(package private) static java.lang.String DEGK
           
(package private) static java.lang.String DEGR
           
(package private) static Units Degree
           
(package private) static Units DollarUS
           
(package private) static java.lang.String DSTA
           
(package private) static java.lang.String DSTCM
           
(package private) static java.lang.String DSTDM
           
(package private) static java.lang.String DSTF
           
(package private) static java.lang.String DSTI
           
(package private) static java.lang.String DSTLS
           
(package private) static java.lang.String DSTLY
           
(package private) static java.lang.String DSTM
           
(package private) static java.lang.String DSTMI
           
(package private) static java.lang.String DSTMM
           
(package private) static java.lang.String DSTY
           
(package private) static java.lang.String ECAP
           
(package private) static java.lang.String ERGB
           
(package private) static java.lang.String ERGC
           
(package private) static java.lang.String ERGE
           
(package private) static java.lang.String ERGF
           
(package private) static java.lang.String ERGJ
           
(package private) static java.lang.String ERGK
           
(package private) static java.lang.String ERGV
           
(package private) static java.lang.String FRCD
           
(package private) static java.lang.String FRCN
           
(package private) static java.lang.String FRCP
           
(package private) static java.lang.String FRCW
           
(package private) static java.lang.String FREQ
           
(package private) static Units G
           
(package private) static Units Grad
           
(package private) static Units GravConstUnits
           
(package private) static Units Henry
           
(package private) static Units Hertz
           
(package private) static Units Hour
           
(package private) static java.lang.String INDCT
           
(package private) static Units Joule
           
(package private) static Units JoulePerKelvin
           
(package private) static Units Kelvin
           
static Units Kilogram
           
(package private) static Units KilogramPerSecondSquared
           
(package private) static java.lang.String LIGHT
           
(package private) static java.lang.String MASG
           
(package private) static java.lang.String MASK
           
(package private) static java.lang.String MASL
           
(package private) static java.lang.String MASO
           
(package private) static java.lang.String MASP
           
(package private) static java.lang.String MASS
           
(package private) static java.lang.String MAST
           
static Units Meter
           
(package private) static Units MeterCubed
           
(package private) static Units MeterPerSecond
           
(package private) static Units MeterPerSecondAllSquared
           
(package private) static Units MetrePerSecondSquared
           
(package private) static java.lang.String MFD
           
(package private) static java.lang.String MFLX
           
(package private) static Units Minute
           
(package private) static Units Mole
           
(package private) static Units Newton
           
static Units None
           
(package private) static Units Pascal
           
(package private) static Units PerMeter
           
(package private) static java.lang.String POWH
           
(package private) static java.lang.String POWW
           
(package private) static java.lang.String PRSA
           
(package private) static java.lang.String PRSB
           
(package private) static java.lang.String PRSP
           
(package private) static java.lang.String PRSPSI
           
(package private) static java.lang.String PRST
           
(package private) static java.lang.String QTY
           
(package private) static Units Radian
           
(package private) static java.lang.String REST
           
(package private) static Units Rightangle
           
static Units Second
           
(package private) static Units SecondSquared
           
(package private) static Units Tesla
           
(package private) static java.lang.String TIMD
           
(package private) static java.lang.String TIMF
           
(package private) static java.lang.String TIMH
           
(package private) static java.lang.String TIMM
           
(package private) static java.lang.String TIMS
           
(package private) static java.lang.String TIMW
           
(package private) static java.lang.String TIMY
           
(package private) static Units Volt
           
(package private) static java.lang.String VOLT
           
(package private) static Units Watt
           
(package private) static Units Weber
           
 
Fields inherited from class com.rubecula.jquantity.UnitsFoundation
_Name
 
Constructor Summary
(package private) Units(Measurable base)
           
(package private) Units(java.lang.String name, Measurable base)
           
(package private) Units(java.lang.String name, Measurable base, SystemFlag flag)
           
(package private) Units(UnitsName name, SystemFlag system, Rational scale, Measurable A)
           
(package private) Units(UnitsName name, SystemFlag system, Rational scale, Rational powerA, Measurable A)
           
(package private) Units(UnitsName name, SystemFlag system, Rational scale, Rational powerA, Measurable A, Rational powerB, Measurable B)
           
(package private) Units(UnitsName name, SystemFlag system, Rational scale, Rational powerA, Measurable A, Rational powerB, Measurable B, Rational offset)
           
 
Method Summary
(package private)  void audit(int indent)
           
 void audit(java.io.PrintStream out)
           
 java.lang.Object clone()
          Creates and returns a copy of this Units.
(package private)  Units combine(Rational powerA, Measurable B, Rational powerB)
           
 int compareTo(BaseUnit val)
          Compares this Units with the specified Measurable.
 int compareTo(java.lang.Object val)
          Compares this Units with the specified Object.
(package private)  Units convertToSystem(int systemIndex)
           
(package private)  Units difference(Measurable addend)
           
 BaseUnit flatten()
          Method to reduce a Units tree to a single flattened version.
(package private)  int getCommonSysIndex(Units that)
           
 Dimensions getDimensions()
          Method to return the dimensions of this Measurable.
 Rational getOffset()
          Method to return the offset of this Measurable.
 Rational getScale()
          Method to return the scale of this Measurable.
(package private)  SystemFlag getSystem()
           
(package private)  Units halve()
           
 int hashCode()
           
 boolean identity()
           
 boolean isAngular()
           
(package private)  boolean isEqual(Measurable other)
          Method to determine if this BaseUnit is equivalent to that Measurable.
 boolean isInSystem(int sysIndex)
          Method to determine if this Measurable is in a certain system of units.
static void main(java.lang.String[] args)
           
 Presentable makePresentableInstance(Presentation presentation)
          Instance method to convert a Presentation into a Presentable.
(package private)  Units minus()
           
 Presentation present(AttrMap attributes)
          Convert this Presentable object into a Presentation, according to the set of attributes provided.
(package private)  Units productScalar(Rational power)
           
(package private)  Units rename(java.lang.String name)
           
(package private)  Units scale(int scale)
          Scale this unit.
(package private)  Units scale(Rational scale)
          Scale this unit.
(package private)  Units scale(UnitsName name, int scale)
          Scale this unit and assign a new name to the result.
(package private)  Units scale(UnitsName name, int scale, SystemFlag system)
          Scale this unit and assign a new name and system to the result.
(package private)  Units scale(UnitsName name, Rational scale)
          Scale this unit and assign a new name to the result.
(package private)  Units scale(UnitsName name, Rational scale, SystemFlag system)
          Scale this unit and assign a new name and system to the result.
(package private)  Rational scaleToUnits(Measurable base, Rational value)
          This method converts value which is expressed in this Units into a value expressed in base units.
(package private)  Units sum(Measurable addend)
           
(package private)  Units sum(Measurable addend, Rational power)
           
 java.lang.String toString()
          This is the default toString method for all Items.
 java.lang.String toString(int sysIndex)
           
 
Methods inherited from class com.rubecula.jquantity.UnitsFoundation
audit, audit, audit, getIdentifier, getName, isNumber, monitor, normalize, setIdentifier, setName, setName, setName, setName, setName, setName
 
Methods inherited from class com.rubecula.jquantity.BaseUnit
isParallel
 
Methods inherited from class com.rubecula.jquantity.Item
Debug, getClassNameShort, getType, IsDebug, present, SetDebug, test, test, Wrap
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ABA

static final java.lang.String ABA
See Also:
Constant Field Values

ANGD

static final java.lang.String ANGD
See Also:
Constant Field Values

ANGR

static final java.lang.String ANGR
See Also:
Constant Field Values

ANGX

static final java.lang.String ANGX
See Also:
Constant Field Values

ANGG

static final java.lang.String ANGG
See Also:
Constant Field Values

ANGAS

static final java.lang.String ANGAS
See Also:
Constant Field Values

ANGAM

static final java.lang.String ANGAM
See Also:
Constant Field Values

CUSD

static final java.lang.String CUSD
See Also:
Constant Field Values

DEGF

static final java.lang.String DEGF
See Also:
Constant Field Values

DEGC

static final java.lang.String DEGC
See Also:
Constant Field Values

DEGK

static final java.lang.String DEGK
See Also:
Constant Field Values

DEGR

static final java.lang.String DEGR
See Also:
Constant Field Values

DSTM

static final java.lang.String DSTM
See Also:
Constant Field Values

DSTDM

static final java.lang.String DSTDM
See Also:
Constant Field Values

DSTCM

static final java.lang.String DSTCM
See Also:
Constant Field Values

DSTMM

static final java.lang.String DSTMM
See Also:
Constant Field Values

DSTA

static final java.lang.String DSTA
See Also:
Constant Field Values

DSTF

static final java.lang.String DSTF
See Also:
Constant Field Values

DSTI

static final java.lang.String DSTI
See Also:
Constant Field Values

DSTY

static final java.lang.String DSTY
See Also:
Constant Field Values

DSTMI

static final java.lang.String DSTMI
See Also:
Constant Field Values

DSTLS

static final java.lang.String DSTLS
See Also:
Constant Field Values

DSTLY

static final java.lang.String DSTLY
See Also:
Constant Field Values

TIMS

static final java.lang.String TIMS
See Also:
Constant Field Values

TIMM

static final java.lang.String TIMM
See Also:
Constant Field Values

TIMH

static final java.lang.String TIMH
See Also:
Constant Field Values

TIMD

static final java.lang.String TIMD
See Also:
Constant Field Values

TIMY

static final java.lang.String TIMY
See Also:
Constant Field Values

TIMW

static final java.lang.String TIMW
See Also:
Constant Field Values

TIMF

static final java.lang.String TIMF
See Also:
Constant Field Values

MASK

static final java.lang.String MASK
See Also:
Constant Field Values

MASG

static final java.lang.String MASG
See Also:
Constant Field Values

MASP

static final java.lang.String MASP
See Also:
Constant Field Values

MASO

static final java.lang.String MASO
See Also:
Constant Field Values

MASS

static final java.lang.String MASS
See Also:
Constant Field Values

MASL

static final java.lang.String MASL
See Also:
Constant Field Values

MAST

static final java.lang.String MAST
See Also:
Constant Field Values

AMP

static final java.lang.String AMP
See Also:
Constant Field Values

CHRG

static final java.lang.String CHRG
See Also:
Constant Field Values

ERGJ

static final java.lang.String ERGJ
See Also:
Constant Field Values

ERGK

static final java.lang.String ERGK
See Also:
Constant Field Values

ERGB

static final java.lang.String ERGB
See Also:
Constant Field Values

ERGC

static final java.lang.String ERGC
See Also:
Constant Field Values

ERGV

static final java.lang.String ERGV
See Also:
Constant Field Values

ERGE

static final java.lang.String ERGE
See Also:
Constant Field Values

ERGF

static final java.lang.String ERGF
See Also:
Constant Field Values

POWW

static final java.lang.String POWW
See Also:
Constant Field Values

POWH

static final java.lang.String POWH
See Also:
Constant Field Values

LIGHT

static final java.lang.String LIGHT
See Also:
Constant Field Values

QTY

static final java.lang.String QTY
See Also:
Constant Field Values

VOLT

static final java.lang.String VOLT
See Also:
Constant Field Values

FREQ

static final java.lang.String FREQ
See Also:
Constant Field Values

FRCN

static final java.lang.String FRCN
See Also:
Constant Field Values

FRCD

static final java.lang.String FRCD
See Also:
Constant Field Values

FRCP

static final java.lang.String FRCP
See Also:
Constant Field Values

FRCW

static final java.lang.String FRCW
See Also:
Constant Field Values

PRSP

static final java.lang.String PRSP
See Also:
Constant Field Values

PRST

static final java.lang.String PRST
See Also:
Constant Field Values

PRSB

static final java.lang.String PRSB
See Also:
Constant Field Values

PRSA

static final java.lang.String PRSA
See Also:
Constant Field Values

PRSPSI

static final java.lang.String PRSPSI
See Also:
Constant Field Values

REST

static final java.lang.String REST
See Also:
Constant Field Values

ECAP

static final java.lang.String ECAP
See Also:
Constant Field Values

MFLX

static final java.lang.String MFLX
See Also:
Constant Field Values

INDCT

static final java.lang.String INDCT
See Also:
Constant Field Values

MFD

static final java.lang.String MFD
See Also:
Constant Field Values

AA

static final java.lang.String AA
See Also:
Constant Field Values

AAC

static final java.lang.String AAC
See Also:
Constant Field Values

None

public static final Units None

Meter

public static final Units Meter

Second

public static final Units Second

Kilogram

public static final Units Kilogram

Radian

static final Units Radian

Ampere

static final Units Ampere

Kelvin

static final Units Kelvin

Candela

static final Units Candela

Mole

static final Units Mole

DollarUS

static final Units DollarUS

Minute

static final Units Minute

Hour

static final Units Hour

Day

static final Units Day

Hertz

static final Units Hertz

Degree

static final Units Degree

Rightangle

static final Units Rightangle

Grad

static final Units Grad

Coulomb

static final Units Coulomb

MeterPerSecond

static final Units MeterPerSecond

PerMeter

static final Units PerMeter

CoulombPerMole

static final Units CoulombPerMole

MeterCubed

static final Units MeterCubed

SecondSquared

static final Units SecondSquared

MetrePerSecondSquared

static final Units MetrePerSecondSquared

KilogramPerSecondSquared

static final Units KilogramPerSecondSquared

Newton

static final Units Newton

Pascal

static final Units Pascal

GravConstUnits

static final Units GravConstUnits

MeterPerSecondAllSquared

static final Units MeterPerSecondAllSquared

Joule

static final Units Joule

JoulePerKelvin

static final Units JoulePerKelvin

G

static final Units G

Watt

static final Units Watt

Volt

static final Units Volt

Weber

static final Units Weber

Henry

static final Units Henry

Tesla

static final Units Tesla
Constructor Detail

Units

Units(UnitsName name,
      SystemFlag system,
      Rational scale,
      Rational powerA,
      Measurable A,
      Rational powerB,
      Measurable B,
      Rational offset)

Units

Units(UnitsName name,
      SystemFlag system,
      Rational scale,
      Rational powerA,
      Measurable A,
      Rational powerB,
      Measurable B)

Units

Units(UnitsName name,
      SystemFlag system,
      Rational scale,
      Rational powerA,
      Measurable A)

Units

Units(UnitsName name,
      SystemFlag system,
      Rational scale,
      Measurable A)

Units

Units(java.lang.String name,
      Measurable base,
      SystemFlag flag)

Units

Units(java.lang.String name,
      Measurable base)

Units

Units(Measurable base)
Method Detail

hashCode

public final int hashCode()
Overrides:
hashCode in class java.lang.Object

clone

public java.lang.Object clone()
Creates and returns a copy of this Units.

Overrides:
clone in class java.lang.Object
Returns:
a clone of this instance.
Throws:
java.lang.Exception - : not Cloneable (should be impossible)
See Also:
Cloneable

compareTo

public int compareTo(BaseUnit val)
Compares this Units with the specified Measurable.

Parameters:
val - Units to which this Measurable is to be compared.
Returns:
0 or 1 Units is equivalent/not-equivalent to val.

compareTo

public int compareTo(java.lang.Object val)
Compares this Units with the specified Object.

Specified by:
compareTo in interface java.lang.Comparable
Overrides:
compareTo in class Item
Parameters:
val - Object to which this Units is to be compared.
Returns:
0 or 1 Units is equivalent/not-equivalent to val.

getDimensions

public Dimensions getDimensions()
Description copied from interface: Measurable
Method to return the dimensions of this Measurable.

Specified by:
getDimensions in interface Measurable
Returns:
the Dimensions.

getScale

public Rational getScale()
Description copied from interface: Measurable
Method to return the scale of this Measurable.

Specified by:
getScale in interface Measurable
Returns:
the scale.

getOffset

public Rational getOffset()
Description copied from interface: Measurable
Method to return the offset of this Measurable.

Specified by:
getOffset in interface Measurable
Returns:
the offset, usually $0.

scale

final Units scale(UnitsName name,
                  Rational scale,
                  SystemFlag system)
Scale this unit and assign a new name and system to the result.

Parameters:
name - Name of scaled unit
scale - The scale. For example, when creating an inch from a millimetre the value of scale would be 254/10.
system - The system of the new unit.
Returns:
Newly formed unit

scale

final Units scale(UnitsName name,
                  Rational scale)
Scale this unit and assign a new name to the result. Used when the system of the new unit is the same, for example when deriving one millimetre from a metre.

Parameters:
name - Name of scaled unit
scale - The scale. For example, when creating an inch from a millimetre the value of scale would be 254/10.
Returns:
Newly formed unit

scale

final Units scale(Rational scale)
Scale this unit. Used when the system of the new unit is the same, for example when deriving one millimetre from a metre.

Parameters:
scale - The scale. For example, when creating an inch from a millimetre the value of scale would be 254/10.
Returns:
Newly formed unnamed unit

scale

final Units scale(UnitsName name,
                  int scale,
                  SystemFlag system)
Scale this unit and assign a new name and system to the result.

Parameters:
name - Name of scaled unit
scale - The scale. For example, when creating a minute from a second the value of scale would be 60.
system - The system of the new unit.
Returns:
Newly formed unit

scale

final Units scale(UnitsName name,
                  int scale)
Scale this unit and assign a new name to the result. Used when the system of the new unit is the same, for example when deriving one millimetre from a metre.

Parameters:
name - Name of scaled unit
scale - The scale. For example, when creating a minute from a second the value of scale would be 60.
Returns:
Newly formed unit

scale

final Units scale(int scale)
Scale this unit. Used when the system of the new unit is the same, for example when deriving one millimetre from a metre.

Parameters:
scale - The scale. For example, when creating a minute from a second the value of scale would be 60.
Returns:
Newly formed unnamed unit

combine

final Units combine(Rational powerA,
                    Measurable B,
                    Rational powerB)

sum

final Units sum(Measurable addend,
                Rational power)

sum

final Units sum(Measurable addend)

difference

final Units difference(Measurable addend)

productScalar

final Units productScalar(Rational power)

minus

final Units minus()

halve

final Units halve()
           throws JQuantityException
JQuantityException

rename

final Units rename(java.lang.String name)

getSystem

final SystemFlag getSystem()

isInSystem

public boolean isInSystem(int sysIndex)
Description copied from class: BaseUnit
Method to determine if this Measurable is in a certain system of units.

Overrides:
isInSystem in class BaseUnit
Parameters:
sysIndex - the index of the units system.
Returns:
true of this Measurable belongs to System defined by sysIndex.

flatten

public BaseUnit flatten()
                 throws JQuantityException
Description copied from class: BaseUnit
Method to reduce a Units tree to a single flattened version.

Specified by:
flatten in class BaseUnit
Returns:
the equivalent FlatUnit.
Throws:
JQuantityException

isEqual

boolean isEqual(Measurable other)
Description copied from class: BaseUnit
Method to determine if this BaseUnit is equivalent to that Measurable.

Overrides:
isEqual in class BaseUnit
Parameters:
other - the Measurable to compare.
Returns:
true if isParallel(other) and if their respective scales and offsets are equal.

scaleToUnits

final Rational scaleToUnits(Measurable base,
                            Rational value)
                     throws JQuantityException
This method converts value which is expressed in this Units into a value expressed in base units.

Parameters:
base - the units in which we want a value scaled.
value - the value to scale.
Returns:
a Rational which is the new value appropriately scaled.
Throws:
JQuantityException

toString

public java.lang.String toString(int sysIndex)
Specified by:
toString in class UnitsFoundation

toString

public java.lang.String toString()
Description copied from class: Item
This is the default toString method for all Items. Specific classes will override as appropriate.

Overrides:
toString in class UnitsFoundation
Returns:
a String representing this Item by first converting it to a Presentation and then rendering that with no length constraint.

audit

public void audit(java.io.PrintStream out)

present

public Presentation present(AttrMap attributes)
                     throws PresentationException
Convert this Presentable object into a Presentation, according to the set of attributes provided.

Specified by:
present in interface Presentable
Parameters:
attributes - a map of the attributes desired for the construction of the new presentation (may be empty).
Returns:
an appropriate instance of Presentation.
Throws:
PresentationException - in case of parsing error.

makePresentableInstance

public Presentable makePresentableInstance(Presentation presentation)
                                    throws PresentationException
Instance method to convert a Presentation into a Presentable. Ideally, this would be a class method, but such a method cannot be defined in an interface. Nor can it be defined in an abstract class with the intention of overriding it in a subclass. Polymorphism just doesn't work that way.
Therefore, the present value (as in fields) of the instance is essentially ignored - only the methods are important.

Specified by:
makePresentableInstance in interface Presentable
Parameters:
presentation - of a number to be converted into a Presentable number.
Returns:
a number in the form of a Presentable.
Throws:
PresentationException - in case of parsing error.

identity

public final boolean identity()
                       throws JQuantityException
JQuantityException

isAngular

public final boolean isAngular()
                        throws JQuantityException
JQuantityException

getCommonSysIndex

final int getCommonSysIndex(Units that)

audit

final void audit(int indent)

convertToSystem

final Units convertToSystem(int systemIndex)

main

public static void main(java.lang.String[] args)