com.rubecula.jquantity
Class Units

java.lang.Object
  extended bycom.rubecula.util.Item
      extended bycom.rubecula.jquantity.BaseUnit
          extended bycom.rubecula.jquantity.UnitsFoundation
              extended bycom.rubecula.jquantity.Units
All Implemented Interfaces:
com.rubecula.util.Auditable, Cloneable, Comparable, com.rubecula.util.Identifiable, Measurable, Mutable, com.rubecula.util.Nameable, com.rubecula.util.Presentable, Serializable

public class Units
extends UnitsFoundation
implements Measurable, Mutable, com.rubecula.util.Auditable

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.16 $
Author:
Robin Hillyard
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class com.rubecula.jquantity.UnitsFoundation
UnitsFoundation.UnitsException
 
Field Summary
private  Measurable _A
           
private  Measurable _B
           
private  Rational _Offset
           
private  Rational _PowerA
           
private  Rational _PowerB
           
private  Rational _Scale
           
private  SystemFlag _System
           
protected static long $L_M_PER_LIGHTSEC
           
protected static String $S_KG_PER_POUND
           
protected static String $S_M_PER_FOOT
           
static String AA
           
static String AAC
           
static String ABA
           
static String AMP
           
static Units Ampere
           
static String ANGAM
           
static String ANGAS
           
static String ANGD
           
static String ANGG
           
static String ANGR
           
static String ANGX
           
private static Units[][] BaseUnits
           
static Units Candela
           
static Units Centimeter
           
static String CHRG
           
static Units Coulomb
           
static String CUSD
           
static Units Day
           
static String DEGC
           
static String DEGF
           
static String DEGK
           
static String DEGR
           
static Units Degree
           
static Units DollarUS
           
static String DSTA
           
static String DSTAU
           
static String DSTCM
           
static String DSTDM
           
static String DSTF
           
static String DSTHM
           
static String DSTI
           
static String DSTKM
           
static String DSTLS
           
static String DSTLY
           
static String DSTM
           
static String DSTMI
           
static String DSTMM
           
static String DSTY
           
static String ECAP
           
static String ERGB
           
static String ERGC
           
static String ERGE
           
static String ERGF
           
static String ERGJ
           
static String ERGK
           
static String ERGV
           
static Units Foot
           
static String FRCD
           
static String FRCN
           
static String FRCP
           
static String FRCW
           
static String FREQ
           
static Units G
           
static Units Grad
           
static Units Gram
           
static Units GravConstUnits
           
static Units Henry
           
static Units Hertz
           
static Units Hour
           
static Rational Hundred
           
static Rational Hundredth
           
static String INDCT
           
static Units Joule
           
static Units Kelvin
           
static Units Kilogram
           
private static Units KilogramPerSecondSquared
           
static String LIGHT
           
static Units LightSecond
           
static String MASG
           
static String MASK
           
static String MASL
           
static String MASO
           
static String MASP
           
static String MASS
           
static String MAST
           
static Units Meter
           
private static Units MeterCubed
           
private static Units MeterPerSecond
           
static Units MeterPerSecondAllSquared
           
private static Units MetrePerSecondSquared
           
static String MFD
           
static String MFLX
           
static Units Minute
           
static Units Mole
           
static Units Newton
           
static Units None
           
static Units Pascal
           
static Units Pound
           
static String POWH
           
static String POWW
           
static String PRSA
           
static String PRSB
           
static String PRSP
           
static String PRSPSI
           
static String PRST
           
static String QTY
           
static Units Radian
           
static String REST
           
static Units Rightangle
           
static Units Second
           
private static Units SecondSquared
           
static Rational Ten
           
static Rational Tenth
           
static Units Tesla
           
static Rational Thousand
           
static Rational Thousandth
           
static String TIMD
           
static String TIMF
           
static String TIMH
           
static String TIMM
           
static String TIMS
           
static String TIMW
           
static String TIMY
           
static Units Volt
           
static String VOLT
           
static Units Watt
           
static Units Weber
           
 
Fields inherited from class com.rubecula.jquantity.UnitsFoundation
_Name
 
Fields inherited from class com.rubecula.util.Item
JQUANTITY_TEST
 
Constructor Summary
(package private) Units(Measurable base)
           
(package private) Units(String name, Measurable base)
           
(package private) Units(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(PrintStream out)
           
 Object clone()
          Creates and returns a copy of this Units.
(package private)  Units combine(Rational powerA, Measurable B, Rational powerB)
           
 int compareTo(Measurable val)
          Compares this Units with the specified Measurable.
 int compareTo(Object val)
          Compares this Units with the specified Object.
 Measurable 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)
           
private  String getDescription()
           
 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.
 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.
 boolean isMutable()
          This method indicates whether this particular instance is mutable, i.e. it has not been designated a constant.
static void main(String[] args)
           
 com.rubecula.util.Presentable makePresentableInstance(com.rubecula.util.Presentation presentation)
          Instance method to convert a Presentation into a Presentable.
(package private)  Units minus()
           
private  void monitor(String method, String arg0, String arg1, String arg2)
           
private static Rational nonZeroDivide(Rational num, long denom)
           
 com.rubecula.util.Presentation present(com.rubecula.util.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(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.
 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.
private static boolean stringComposite(String string)
           
(package private)  Units sum(Measurable addend)
           
static Measurable Sum(Measurable x, Measurable y)
           
(package private)  Units sum(Measurable addend, Rational power)
           
 String toString()
           
 String toString(int sysIndex)
           
 
Methods inherited from class com.rubecula.jquantity.UnitsFoundation
audit, audit, audit, getIdentifier, isNumber, monitor, normalize, setIdentifier, setName, setName, setName, setName, setName, setName
 
Methods inherited from class com.rubecula.jquantity.BaseUnit
isParallel, isParallelInSystem
 
Methods inherited from class com.rubecula.util.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
 
Methods inherited from interface com.rubecula.jquantity.Measurable
isNumber, isParallel
 
Methods inherited from interface com.rubecula.util.Identifiable
getIdentifier
 
Methods inherited from interface com.rubecula.util.Auditable
audit, audit, audit
 

Field Detail

_System

private final SystemFlag _System

_Scale

private final Rational _Scale

_Offset

private final Rational _Offset

_PowerA

private final Rational _PowerA

_A

private final Measurable _A

_PowerB

private final Rational _PowerB

_B

private final Measurable _B

ABA

public static final String ABA
See Also:
Constant Field Values

ANGD

public static final String ANGD
See Also:
Constant Field Values

ANGR

public static final String ANGR
See Also:
Constant Field Values

ANGX

public static final String ANGX
See Also:
Constant Field Values

ANGG

public static final String ANGG
See Also:
Constant Field Values

ANGAS

public static final String ANGAS
See Also:
Constant Field Values

ANGAM

public static final String ANGAM
See Also:
Constant Field Values

CUSD

public static final String CUSD
See Also:
Constant Field Values

DEGF

public static final String DEGF
See Also:
Constant Field Values

DEGC

public static final String DEGC
See Also:
Constant Field Values

DEGK

public static final String DEGK
See Also:
Constant Field Values

DEGR

public static final String DEGR
See Also:
Constant Field Values

DSTM

public static final String DSTM
See Also:
Constant Field Values

DSTDM

public static final String DSTDM
See Also:
Constant Field Values

DSTHM

public static final String DSTHM
See Also:
Constant Field Values

DSTKM

public static final String DSTKM
See Also:
Constant Field Values

DSTCM

public static final String DSTCM
See Also:
Constant Field Values

DSTMM

public static final String DSTMM
See Also:
Constant Field Values

DSTA

public static final String DSTA
See Also:
Constant Field Values

DSTF

public static final String DSTF
See Also:
Constant Field Values

DSTI

public static final String DSTI
See Also:
Constant Field Values

DSTY

public static final String DSTY
See Also:
Constant Field Values

DSTMI

public static final String DSTMI
See Also:
Constant Field Values

DSTAU

public static final String DSTAU
See Also:
Constant Field Values

DSTLS

public static final String DSTLS
See Also:
Constant Field Values

DSTLY

public static final String DSTLY
See Also:
Constant Field Values

TIMS

public static final String TIMS
See Also:
Constant Field Values

TIMM

public static final String TIMM
See Also:
Constant Field Values

TIMH

public static final String TIMH
See Also:
Constant Field Values

TIMD

public static final String TIMD
See Also:
Constant Field Values

TIMY

public static final String TIMY
See Also:
Constant Field Values

TIMW

public static final String TIMW
See Also:
Constant Field Values

TIMF

public static final String TIMF
See Also:
Constant Field Values

MASK

public static final String MASK
See Also:
Constant Field Values

MASG

public static final String MASG
See Also:
Constant Field Values

MASP

public static final String MASP
See Also:
Constant Field Values

MASO

public static final String MASO
See Also:
Constant Field Values

MASS

public static final String MASS
See Also:
Constant Field Values

MASL

public static final String MASL
See Also:
Constant Field Values

MAST

public static final String MAST
See Also:
Constant Field Values

AMP

public static final String AMP
See Also:
Constant Field Values

CHRG

public static final String CHRG
See Also:
Constant Field Values

ERGJ

public static final String ERGJ
See Also:
Constant Field Values

ERGK

public static final String ERGK
See Also:
Constant Field Values

ERGB

public static final String ERGB
See Also:
Constant Field Values

ERGC

public static final String ERGC
See Also:
Constant Field Values

ERGV

public static final String ERGV
See Also:
Constant Field Values

ERGE

public static final String ERGE
See Also:
Constant Field Values

ERGF

public static final String ERGF
See Also:
Constant Field Values

POWW

public static final String POWW
See Also:
Constant Field Values

POWH

public static final String POWH
See Also:
Constant Field Values

LIGHT

public static final String LIGHT
See Also:
Constant Field Values

QTY

public static final String QTY
See Also:
Constant Field Values

VOLT

public static final String VOLT
See Also:
Constant Field Values

FREQ

public static final String FREQ
See Also:
Constant Field Values

FRCN

public static final String FRCN
See Also:
Constant Field Values

FRCD

public static final String FRCD
See Also:
Constant Field Values

FRCP

public static final String FRCP
See Also:
Constant Field Values

FRCW

public static final String FRCW
See Also:
Constant Field Values

PRSP

public static final String PRSP
See Also:
Constant Field Values

PRST

public static final String PRST
See Also:
Constant Field Values

PRSB

public static final String PRSB
See Also:
Constant Field Values

PRSA

public static final String PRSA
See Also:
Constant Field Values

PRSPSI

public static final String PRSPSI
See Also:
Constant Field Values

REST

public static final String REST
See Also:
Constant Field Values

ECAP

public static final String ECAP
See Also:
Constant Field Values

MFLX

public static final String MFLX
See Also:
Constant Field Values

INDCT

public static final String INDCT
See Also:
Constant Field Values

MFD

public static final String MFD
See Also:
Constant Field Values

AA

public static final String AA
See Also:
Constant Field Values

AAC

public static final String AAC
See Also:
Constant Field Values

Ten

public static Rational Ten

Tenth

public static Rational Tenth

Hundred

public static Rational Hundred

Hundredth

public static Rational Hundredth

Thousand

public static Rational Thousand

Thousandth

public static Rational Thousandth

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

public static final Units Radian

Ampere

public static final Units Ampere

Kelvin

public static final Units Kelvin

Candela

public static final Units Candela

Mole

public static final Units Mole

DollarUS

public static final Units DollarUS

Minute

public static final Units Minute

Hour

public static final Units Hour

Day

public static final Units Day

Hertz

public static final Units Hertz

Degree

public static final Units Degree

Rightangle

public static final Units Rightangle

Grad

public static final Units Grad

Coulomb

public static final Units Coulomb

MeterPerSecond

private static final Units MeterPerSecond

MeterCubed

private static final Units MeterCubed

SecondSquared

private static final Units SecondSquared

MetrePerSecondSquared

private static final Units MetrePerSecondSquared

KilogramPerSecondSquared

private static final Units KilogramPerSecondSquared

Newton

public static final Units Newton

Pascal

public static final Units Pascal

GravConstUnits

public static final Units GravConstUnits

MeterPerSecondAllSquared

public static final Units MeterPerSecondAllSquared

Joule

public static final Units Joule

G

public static final Units G

Watt

public static final Units Watt

Volt

public static final Units Volt

Weber

public static final Units Weber

Henry

public static final Units Henry

Tesla

public static final Units Tesla

Gram

public static final Units Gram

Centimeter

public static final Units Centimeter

$L_M_PER_LIGHTSEC

protected static final long $L_M_PER_LIGHTSEC
See Also:
Constant Field Values

$S_M_PER_FOOT

protected static final String $S_M_PER_FOOT
See Also:
Constant Field Values

$S_KG_PER_POUND

protected static final String $S_KG_PER_POUND
See Also:
Constant Field Values

LightSecond

public static final Units LightSecond

Pound

public static final Units Pound

Foot

public static final Units Foot

BaseUnits

private static final Units[][] BaseUnits
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(String name,
      Measurable base,
      SystemFlag flag)

Units

Units(String name,
      Measurable base)

Units

Units(Measurable base)
Method Detail

hashCode

public final int hashCode()

clone

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

Returns:
a clone of this instance.
Throws:
Exception - : not Cloneable (should be impossible)
See Also:
Cloneable

compareTo

public int compareTo(Measurable 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(Object val)
Compares this Units with the specified Object.

Specified by:
compareTo in interface Comparable
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

public 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
Throws:
JQuantityException

rename

final Units rename(String name)

getSystem

public SystemFlag getSystem()
Specified by:
getSystem in interface Measurable

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 interface: Measurable
Method to reduce a Units tree to a single flattened version.

Specified by:
flatten in interface Measurable
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 String toString(int sysIndex)
Specified by:
toString in class UnitsFoundation

toString

public String toString()
Overrides:
toString in class UnitsFoundation

audit

public void audit(PrintStream out)

present

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

Specified by:
present in interface com.rubecula.util.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:
com.rubecula.util.PresentationException - in case of parsing error.

makePresentableInstance

public com.rubecula.util.Presentable makePresentableInstance(com.rubecula.util.Presentation presentation)
                                                      throws com.rubecula.util.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 com.rubecula.util.Presentable
Parameters:
presentation - of a number to be converted into a Presentable number.
Returns:
a number in the form of a Presentable.
Throws:
com.rubecula.util.PresentationException - in case of parsing error.

getDescription

private String getDescription()

stringComposite

private static boolean stringComposite(String string)

identity

public final boolean identity()
                       throws JQuantityException
Throws:
JQuantityException

isAngular

public final boolean isAngular()
                        throws JQuantityException
Throws:
JQuantityException

getCommonSysIndex

final int getCommonSysIndex(Units that)

audit

final void audit(int indent)

monitor

private void monitor(String method,
                     String arg0,
                     String arg1,
                     String arg2)

nonZeroDivide

private static Rational nonZeroDivide(Rational num,
                                      long denom)

convertToSystem

public final Measurable convertToSystem(int systemIndex)
Parameters:
systemIndex - the system in which we want the returned value to be.
Returns:
a Units which is parallel to this but in the system defined by systemIndex.

main

public static void main(String[] args)

isMutable

public boolean isMutable()
Description copied from interface: Mutable
This method indicates whether this particular instance is mutable, i.e. it has not been designated a constant.

Specified by:
isMutable in interface Mutable
Returns:
true if this instance can be mutated, otherwise false (it is constant).

Sum

public static Measurable Sum(Measurable x,
                             Measurable y)