edu.iris.Fissures.model
Class UnitImpl

java.lang.Object
  extended by edu.iris.Fissures.Unit
      extended by edu.iris.Fissures.model.UnitImpl
All Implemented Interfaces:
java.io.Serializable, org.omg.CORBA.portable.IDLEntity, org.omg.CORBA.portable.Streamable, org.omg.CORBA.portable.StreamableValue, org.omg.CORBA.portable.ValueBase

public class UnitImpl
extends edu.iris.Fissures.Unit

encapsulates the meaning of a unit. All units are products of SI primitive units.

It has 4 main parts and can be viewed as (m * 10^p u) ^ e where: m is the multiplicative factor, p is the power of ten, u is either a SI base unit, or a composite unit, e is the exponent.

For example, the unit per inch might be represented as (2.54 * 10^0 (1.0 * 10^-2 METER) ) ^ -1 as one inch is 2.54 centimeters, which is 10-2 METERS. The -1 takes care of the per part.

See Also:
Serialized Form

Field Summary
static UnitImpl ACCELERATION
           
static UnitImpl AMPERE
           
static UnitImpl AREA
           
static int ATTO
           
static UnitImpl CANDELA
          just because we can
static UnitImpl CELSIUS
           
static java.lang.String CELSIUS_NAME
           
static int CENTI
           
static UnitImpl CENTIMETER
           
static UnitImpl CENTIMETER_PER_SECOND
           
static UnitImpl CENTIMETER_PER_SECOND_PER_SECOND
           
static UnitImpl COULOMB
           
static UnitImpl COUNT
           
static UnitImpl CUBIC_CENTIMETER
           
static UnitImpl CUBIC_METER
           
static UnitImpl CUBIC_METER_PER_CUBIC_METER
           
static UnitImpl DAY
           
protected  java.lang.Integer dbid
           
static int DECI
           
static UnitImpl DEGREE
           
static int DEKA
           
static UnitImpl DENSITY
           
static UnitImpl DIMENSIONLESS
           
static UnitImpl DIMENSONLESS
          This is a big dumb, butis the easiest way to create a non-unit.
static UnitImpl DYNE
           
static UnitImpl ENERGY
           
static int EXA
           
static UnitImpl FAHRENHEIT
           
static java.lang.String FAHRENHEIT_NAME
           
static int FEMTO
           
static UnitImpl FOOT
           
static UnitImpl FORCE
           
static UnitImpl FORTNIGHT
           
static UnitImpl FURLONG
           
static int GIGA
           
static UnitImpl GRAM
           
static UnitImpl GRAM_PER_CUBIC_CENTIMETER
           
static UnitImpl GREGORIAN_YEAR
          365.2425 days
static int HECTO
           
static UnitImpl HERTZ
           
protected  java.util.List<UnitImpl> hibernateSubUnitList
           
static UnitImpl HOUR
           
static UnitImpl INCH
           
static UnitImpl JOULE
           
static UnitImpl KELVIN
           
static java.lang.String KELVIN_NAME
          temperature
static int KILO
           
static UnitImpl KILOCOUNT
           
static UnitImpl KILOGRAM
           
static UnitImpl KILOGRAM_PER_CUBIC_METER
           
static UnitImpl KILOMETER
           
static UnitImpl KILOMETER_PER_SECOND
           
static UnitImpl KILOMETER_PER_SECOND_PER_SECOND
           
static UnitImpl LEAGUE
           
static UnitImpl LEAP_YEAR
          leap year of 366 days
static UnitImpl LENGTH
           
static UnitImpl LITER
           
static UnitImpl MASS
           
static int MEGA
           
static UnitImpl MEGACOUNT
           
static UnitImpl METER
           
static UnitImpl METER_PER_METER
           
static UnitImpl METER_PER_SECOND
           
static UnitImpl METER_PER_SECOND_PER_SECOND
           
static int MICRO
           
static UnitImpl MICROCOUNT
           
static UnitImpl MICROMETER
           
static UnitImpl MICROMETER_PER_SECOND
           
static UnitImpl MICROMETER_PER_SECOND_PER_SECOND
           
static UnitImpl MICRON
           
static UnitImpl MICRON_PER_SECOND
           
static UnitImpl MICROSECOND
           
static UnitImpl MILE
           
static int MILLI
           
static UnitImpl MILLICOUNT
           
static UnitImpl MILLIMETER
           
static UnitImpl MILLIMETER_PER_SECOND
           
static UnitImpl MILLIMETER_PER_SECOND_PER_SECOND
           
static UnitImpl MILLISECOND
           
static UnitImpl MINUTE
           
static UnitImpl MOLE
           
static int NANO
           
static UnitImpl NANOMETER
           
static UnitImpl NANOMETER_PER_SECOND
           
static UnitImpl NANOMETER_PER_SECOND_PER_SECOND
           
static UnitImpl NANOSECOND
           
static UnitImpl NEWTON
           
static int NONE
           
protected static int numPrimitives
          The CORBA struct that contains the unit data.
static UnitImpl PASCAL
           
static int PETA
           
static int PICO
           
static UnitImpl PICOMETER
           
static UnitImpl RADIAN
           
static UnitImpl RADIAN_PER_SECOND
           
static UnitImpl ROD
           
static UnitImpl SECOND
           
static UnitImpl SQUARE_CENTIMETER
           
static UnitImpl SQUARE_METER
           
static UnitImpl TENTHMILLISECOND
          tenth of a milliseconds, useful for SEED time format.
static int TERA
           
static UnitImpl TESLA
           
static UnitImpl TIME
           
static UnitImpl UNKNOWN
          This is an even dumber unit, exists so that we can fudge places where a unit is required, but the code can't create it, perhaps in loading from a string.
static UnitImpl VELOCITY
           
static UnitImpl VOLT
           
static UnitImpl VOLT_PER_METER
           
static UnitImpl VOLUME
           
static UnitImpl WEBER
           
static UnitImpl WEEK
           
static UnitImpl YARD
           
static UnitImpl YEAR
          normal year of 365 days
static int YOCTO
           
static int YOTTA
           
static int ZEPTO
           
static int ZETTA
           
 
Fields inherited from class edu.iris.Fissures.Unit
elements, exponent, multi_factor, name, power, the_unit_base
 
Constructor Summary
protected UnitImpl()
           
protected UnitImpl(int power, java.lang.String name, double multi, int exponent)
           
  UnitImpl(edu.iris.Fissures.Unit[] subunits, int power, java.lang.String name, double multi, int exponent)
           
  UnitImpl(edu.iris.Fissures.UnitBase baseUnit, int exponent, int power)
          creates a simple unit, ie only one type of base unit to a exponent with a power for the power of ten.
  UnitImpl(edu.iris.Fissures.UnitBase base, int power, java.lang.String name, double multi, int exponent)
          creates a simple unit, ie only one type of base unit to a exponent with a power for the power of ten and with a multiplicative factor and a name.
 
Method Summary
static java.lang.String baseToString(edu.iris.Fissures.UnitBase b)
           
static java.io.Serializable createEmpty()
           
static UnitImpl createUnitImpl(edu.iris.Fissures.Unit inUnit)
          A factory method to make sure that the input edu.iris.Fissures.unit is in fact a edu.iris.Fissurs.model.UnitImpl, to avoid class cast errors.
static UnitImpl divide(UnitImpl a, UnitImpl b)
          creates a new unit that is the product of the first unit and the inverse of the second unit.
static UnitImpl divide(UnitImpl a, UnitImpl b, java.lang.String name)
          creates a new unit that is the product of the first unit and the inverse of the second unit.
 boolean equals(java.lang.Object o)
           
 int[] getBaseExponents()
          Returns the exponents of the subunits of this unit.
 edu.iris.Fissures.UnitBase getBaseUnit()
           
 int getBaseUnitInt()
          for use by hibernate
 java.lang.Integer getDbid()
           
 int getExponent()
          Returns the exponent for this unit.
 double getMultiFactor()
          Returns the multiplicative factor for this unit.
static int getNumPrimitives()
          convoluted way to find out how many different unit primitives there are, since edu.iris.Fissures.UnitBase provides no accessor method and to avoid hard coding the value.
 int getNumSubUnits()
          Returns the number of subunits.
 int getPower()
          Returns the power of ten for this unit.
static java.lang.String getPrefix(int power)
           
 UnitImpl getReducedUnit()
          Reduces the unit to its most basic SI form, combining all terms possible and bringing any constant factors out.
 UnitImpl getSubUnit(int i)
          Returns the ith subunit of this Unit.
 UnitImpl[] getSubUnits()
           
 java.util.List<UnitImpl> getSubUnitsList()
           
 double getTotalMultiFactor()
          Calcultes the total power of ten for this unit relative to the base units.
 int getTotalPower()
          Calcultes the total power of ten for this unit relative to the MKS base units.
static UnitImpl getUnitFromString(java.lang.String unitName)
           
 int hashCode()
           
 UnitImpl inverse()
          creates and inverse to this unit with a given name.
 UnitImpl inverse(java.lang.String name)
           
 boolean isBaseUnit()
           
 boolean isConvertableTo(UnitImpl otherUnits)
          decides whether this unit is convertable to another unit.
 boolean isNamed()
           
static UnitImpl multiply(double f, UnitImpl u)
          creates a new unit that is the product of a float multiplicative factor and a unit, without a given name.
static UnitImpl multiply(double f, UnitImpl u, java.lang.String name)
          creates a new unit that is the product of a float multiplicative factor and a unit with a name.
static UnitImpl multiply(UnitImpl[] units)
          creates a new unit that is the product of the units.
static UnitImpl multiply(UnitImpl[] units, java.lang.String name)
          creates a new unit that is the product of the units.
static UnitImpl multiply(UnitImpl a, UnitImpl b)
          creates a new unit that is the product of the two units.
static UnitImpl multiply(UnitImpl a, UnitImpl b, java.lang.String name)
          creates a new unit that is the product of the two units.
protected  void setBaseUnitInt(int base)
          for use by hibernate
protected  void setDbid(java.lang.Integer dbid)
           
protected  void setSubUnits(UnitImpl[] u)
          for use by hibernate
protected  void setSubUnitsList(java.util.List<UnitImpl> list)
           
 void toLongString()
           
 java.lang.String toString()
           
 
Methods inherited from class edu.iris.Fissures.Unit
_read, _truncatable_ids, _type, _write
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

numPrimitives

protected static int numPrimitives
The CORBA struct that contains the unit data. It is composed of

the_unit_base - the base unit, if this is of type BASE, or COMPOSITE if not elements - the elements that make up this composite unit, if this is of type COMPOSITE power - the power of ten for this unit, for example 3 for KILO name - a string name for the unit, for example millisecond or foot multi_factor - multiplicative factor, for example 2.54 together with centimeters would give inches exponent - the exponent of the unit, for example -1 for per second


YOTTA

public static final int YOTTA
See Also:
Constant Field Values

ZETTA

public static final int ZETTA
See Also:
Constant Field Values

EXA

public static final int EXA
See Also:
Constant Field Values

PETA

public static final int PETA
See Also:
Constant Field Values

TERA

public static final int TERA
See Also:
Constant Field Values

GIGA

public static final int GIGA
See Also:
Constant Field Values

MEGA

public static final int MEGA
See Also:
Constant Field Values

KILO

public static final int KILO
See Also:
Constant Field Values

HECTO

public static final int HECTO
See Also:
Constant Field Values

DEKA

public static final int DEKA
See Also:
Constant Field Values

NONE

public static final int NONE
See Also:
Constant Field Values

DECI

public static final int DECI
See Also:
Constant Field Values

CENTI

public static final int CENTI
See Also:
Constant Field Values

MILLI

public static final int MILLI
See Also:
Constant Field Values

MICRO

public static final int MICRO
See Also:
Constant Field Values

NANO

public static final int NANO
See Also:
Constant Field Values

PICO

public static final int PICO
See Also:
Constant Field Values

FEMTO

public static final int FEMTO
See Also:
Constant Field Values

ATTO

public static final int ATTO
See Also:
Constant Field Values

ZEPTO

public static final int ZEPTO
See Also:
Constant Field Values

YOCTO

public static final int YOCTO
See Also:
Constant Field Values

METER

public static final UnitImpl METER

LENGTH

public static final UnitImpl LENGTH

KILOMETER

public static final UnitImpl KILOMETER

CENTIMETER

public static final UnitImpl CENTIMETER

MILLIMETER

public static final UnitImpl MILLIMETER

MICROMETER

public static final UnitImpl MICROMETER

MICRON

public static final UnitImpl MICRON

NANOMETER

public static final UnitImpl NANOMETER

PICOMETER

public static final UnitImpl PICOMETER

INCH

public static final UnitImpl INCH

FOOT

public static final UnitImpl FOOT

MILE

public static final UnitImpl MILE

YARD

public static final UnitImpl YARD

ROD

public static final UnitImpl ROD

FURLONG

public static final UnitImpl FURLONG

LEAGUE

public static final UnitImpl LEAGUE

SECOND

public static final UnitImpl SECOND

TIME

public static final UnitImpl TIME

MINUTE

public static final UnitImpl MINUTE

HOUR

public static final UnitImpl HOUR

DAY

public static final UnitImpl DAY

WEEK

public static final UnitImpl WEEK

FORTNIGHT

public static final UnitImpl FORTNIGHT

YEAR

public static final UnitImpl YEAR
normal year of 365 days


LEAP_YEAR

public static final UnitImpl LEAP_YEAR
leap year of 366 days


GREGORIAN_YEAR

public static final UnitImpl GREGORIAN_YEAR
365.2425 days


MILLISECOND

public static final UnitImpl MILLISECOND

TENTHMILLISECOND

public static final UnitImpl TENTHMILLISECOND
tenth of a milliseconds, useful for SEED time format.


MICROSECOND

public static final UnitImpl MICROSECOND

NANOSECOND

public static final UnitImpl NANOSECOND

HERTZ

public static final UnitImpl HERTZ

SQUARE_METER

public static final UnitImpl SQUARE_METER

AREA

public static final UnitImpl AREA

SQUARE_CENTIMETER

public static final UnitImpl SQUARE_CENTIMETER

CUBIC_METER

public static final UnitImpl CUBIC_METER

VOLUME

public static final UnitImpl VOLUME

CUBIC_CENTIMETER

public static final UnitImpl CUBIC_CENTIMETER

LITER

public static final UnitImpl LITER

GRAM

public static final UnitImpl GRAM

KILOGRAM

public static final UnitImpl KILOGRAM

MASS

public static final UnitImpl MASS

DENSITY

public static final UnitImpl DENSITY

GRAM_PER_CUBIC_CENTIMETER

public static final UnitImpl GRAM_PER_CUBIC_CENTIMETER

KILOGRAM_PER_CUBIC_METER

public static final UnitImpl KILOGRAM_PER_CUBIC_METER

VELOCITY

public static final UnitImpl VELOCITY

METER_PER_SECOND

public static final UnitImpl METER_PER_SECOND

KILOMETER_PER_SECOND

public static final UnitImpl KILOMETER_PER_SECOND

CENTIMETER_PER_SECOND

public static final UnitImpl CENTIMETER_PER_SECOND

MILLIMETER_PER_SECOND

public static final UnitImpl MILLIMETER_PER_SECOND

MICROMETER_PER_SECOND

public static final UnitImpl MICROMETER_PER_SECOND

MICRON_PER_SECOND

public static final UnitImpl MICRON_PER_SECOND

NANOMETER_PER_SECOND

public static final UnitImpl NANOMETER_PER_SECOND

METER_PER_SECOND_PER_SECOND

public static final UnitImpl METER_PER_SECOND_PER_SECOND

ACCELERATION

public static final UnitImpl ACCELERATION

KILOMETER_PER_SECOND_PER_SECOND

public static final UnitImpl KILOMETER_PER_SECOND_PER_SECOND

CENTIMETER_PER_SECOND_PER_SECOND

public static final UnitImpl CENTIMETER_PER_SECOND_PER_SECOND

MILLIMETER_PER_SECOND_PER_SECOND

public static final UnitImpl MILLIMETER_PER_SECOND_PER_SECOND

MICROMETER_PER_SECOND_PER_SECOND

public static final UnitImpl MICROMETER_PER_SECOND_PER_SECOND

NANOMETER_PER_SECOND_PER_SECOND

public static final UnitImpl NANOMETER_PER_SECOND_PER_SECOND

FORCE

public static final UnitImpl FORCE

NEWTON

public static final UnitImpl NEWTON

PASCAL

public static final UnitImpl PASCAL

CUBIC_METER_PER_CUBIC_METER

public static final UnitImpl CUBIC_METER_PER_CUBIC_METER

METER_PER_METER

public static final UnitImpl METER_PER_METER

JOULE

public static final UnitImpl JOULE

ENERGY

public static final UnitImpl ENERGY

DYNE

public static final UnitImpl DYNE

AMPERE

public static final UnitImpl AMPERE

COULOMB

public static final UnitImpl COULOMB

VOLT

public static final UnitImpl VOLT

WEBER

public static final UnitImpl WEBER

TESLA

public static final UnitImpl TESLA

VOLT_PER_METER

public static final UnitImpl VOLT_PER_METER

RADIAN

public static final UnitImpl RADIAN

DEGREE

public static final UnitImpl DEGREE

COUNT

public static final UnitImpl COUNT

MILLICOUNT

public static final UnitImpl MILLICOUNT

MICROCOUNT

public static final UnitImpl MICROCOUNT

KILOCOUNT

public static final UnitImpl KILOCOUNT

MEGACOUNT

public static final UnitImpl MEGACOUNT

DIMENSONLESS

public static final UnitImpl DIMENSONLESS
This is a big dumb, butis the easiest way to create a non-unit. It is also different from COUNT because COUNT is a primitive base unit, and hence is not convertable to this.


DIMENSIONLESS

public static final UnitImpl DIMENSIONLESS

KELVIN_NAME

public static final java.lang.String KELVIN_NAME
temperature

See Also:
Constant Field Values

KELVIN

public static final UnitImpl KELVIN

CELSIUS_NAME

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

CELSIUS

public static final UnitImpl CELSIUS

FAHRENHEIT_NAME

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

FAHRENHEIT

public static final UnitImpl FAHRENHEIT

CANDELA

public static final UnitImpl CANDELA
just because we can


MOLE

public static final UnitImpl MOLE

UNKNOWN

public static final UnitImpl UNKNOWN
This is an even dumber unit, exists so that we can fudge places where a unit is required, but the code can't create it, perhaps in loading from a string. DMC uses this in responses when they get something like TC - TEMPERATURE IN DEGREES CELSIUS that is not parsible and has not been special-cased in their code.


RADIAN_PER_SECOND

public static final UnitImpl RADIAN_PER_SECOND

dbid

protected java.lang.Integer dbid

hibernateSubUnitList

protected java.util.List<UnitImpl> hibernateSubUnitList
Constructor Detail

UnitImpl

protected UnitImpl()

UnitImpl

protected UnitImpl(int power,
                   java.lang.String name,
                   double multi,
                   int exponent)

UnitImpl

public UnitImpl(edu.iris.Fissures.UnitBase baseUnit,
                int exponent,
                int power)
creates a simple unit, ie only one type of base unit to a exponent with a power for the power of ten.


UnitImpl

public UnitImpl(edu.iris.Fissures.Unit[] subunits,
                int power,
                java.lang.String name,
                double multi,
                int exponent)

UnitImpl

public UnitImpl(edu.iris.Fissures.UnitBase base,
                int power,
                java.lang.String name,
                double multi,
                int exponent)
creates a simple unit, ie only one type of base unit to a exponent with a power for the power of ten and with a multiplicative factor and a name.

Method Detail

createEmpty

public static java.io.Serializable createEmpty()

createUnitImpl

public static UnitImpl createUnitImpl(edu.iris.Fissures.Unit inUnit)
A factory method to make sure that the input edu.iris.Fissures.unit is in fact a edu.iris.Fissurs.model.UnitImpl, to avoid class cast errors. The implementation will only create a new object if the inUnit is not an instance of UnitImpl.


getNumSubUnits

public int getNumSubUnits()
Returns the number of subunits. For example meters per second would have 2 subunits and meters per second per second could have either 2 or 3 depending on how it was constructed. A base unit has 0 subunits.


getSubUnit

public UnitImpl getSubUnit(int i)
Returns the ith subunit of this Unit.


getSubUnits

public UnitImpl[] getSubUnits()

setSubUnits

protected void setSubUnits(UnitImpl[] u)
for use by hibernate


isBaseUnit

public boolean isBaseUnit()

getBaseUnit

public edu.iris.Fissures.UnitBase getBaseUnit()

getBaseUnitInt

public int getBaseUnitInt()
for use by hibernate


setBaseUnitInt

protected void setBaseUnitInt(int base)
for use by hibernate


getNumPrimitives

public static int getNumPrimitives()
convoluted way to find out how many different unit primitives there are, since edu.iris.Fissures.UnitBase provides no accessor method and to avoid hard coding the value.


getReducedUnit

public UnitImpl getReducedUnit()
Reduces the unit to its most basic SI form, combining all terms possible and bringing any constant factors out.


getBaseExponents

public int[] getBaseExponents()
Returns the exponents of the subunits of this unit. They are indexed by the integers defined in edu.iris.Fissures.UnitImplBase. This is used primarily to determine if to units can be converted from one to the other.


getExponent

public int getExponent()
Returns the exponent for this unit. This ignores any exponents from any subunits.


getTotalPower

public int getTotalPower()
Calcultes the total power of ten for this unit relative to the MKS base units. Used to convert from one set of units to another.


getPower

public int getPower()
Returns the power of ten for this unit. This ignores any powers from any subunits.


getTotalMultiFactor

public double getTotalMultiFactor()
Calcultes the total power of ten for this unit relative to the base units. Used to convert from one set of units to another.


getMultiFactor

public double getMultiFactor()
Returns the multiplicative factor for this unit. This ignores any multiplicative factors from any subunits.


isConvertableTo

public boolean isConvertableTo(UnitImpl otherUnits)
decides whether this unit is convertable to another unit.


isNamed

public boolean isNamed()

baseToString

public static java.lang.String baseToString(edu.iris.Fissures.UnitBase b)

toLongString

public void toLongString()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

hashCode

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

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

inverse

public UnitImpl inverse()
creates and inverse to this unit with a given name.


inverse

public UnitImpl inverse(java.lang.String name)

multiply

public static UnitImpl multiply(double f,
                                UnitImpl u)
creates a new unit that is the product of a float multiplicative factor and a unit, without a given name.


multiply

public static UnitImpl multiply(double f,
                                UnitImpl u,
                                java.lang.String name)
creates a new unit that is the product of a float multiplicative factor and a unit with a name.


multiply

public static UnitImpl multiply(UnitImpl a,
                                UnitImpl b)
creates a new unit that is the product of the two units.


multiply

public static UnitImpl multiply(UnitImpl a,
                                UnitImpl b,
                                java.lang.String name)
creates a new unit that is the product of the two units.


multiply

public static UnitImpl multiply(UnitImpl[] units)
creates a new unit that is the product of the units.


multiply

public static UnitImpl multiply(UnitImpl[] units,
                                java.lang.String name)
creates a new unit that is the product of the units.


divide

public static UnitImpl divide(UnitImpl a,
                              UnitImpl b)
creates a new unit that is the product of the first unit and the inverse of the second unit.


divide

public static UnitImpl divide(UnitImpl a,
                              UnitImpl b,
                              java.lang.String name)
creates a new unit that is the product of the first unit and the inverse of the second unit.


getPrefix

public static final java.lang.String getPrefix(int power)

getUnitFromString

public static final UnitImpl getUnitFromString(java.lang.String unitName)
                                        throws java.lang.NoSuchFieldException
Throws:
java.lang.NoSuchFieldException

setDbid

protected void setDbid(java.lang.Integer dbid)

getDbid

public java.lang.Integer getDbid()

getSubUnitsList

public java.util.List<UnitImpl> getSubUnitsList()

setSubUnitsList

protected void setSubUnitsList(java.util.List<UnitImpl> list)