ucar.units
Class DerivedUnitImpl

java.lang.Object
  extended by ucar.units.UnitImpl
      extended by ucar.units.DerivedUnitImpl
All Implemented Interfaces:
Serializable, DerivableUnit, DerivedUnit, Unit
Direct Known Subclasses:
BaseUnit

public class DerivedUnitImpl
extends UnitImpl
implements DerivedUnit, DerivableUnit

Provides support for a concrete implementation of derived units.

Version:
$Id: DerivedUnitImpl.java 64 2006-07-12 22:30:50Z edavis $
Author:
Steven R. Emmerson
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class ucar.units.UnitImpl
UnitImpl.MyConverter
 
Field Summary
static DerivedUnitImpl DIMENSIONLESS
          The dimensionless derived unit.
 
Constructor Summary
protected DerivedUnitImpl()
          Constructs a dimensionless derived unit from nothing.
protected DerivedUnitImpl(UnitDimension dimension)
          Constructs from a unit dimension.
protected DerivedUnitImpl(UnitDimension dimension, UnitName id)
          Constructs from a unit dimension and identifiers.
protected DerivedUnitImpl(UnitName id)
          Constructs from identifiers.
 
Method Summary
 Unit clone(UnitName id)
          Clones the derived unit changing the identifiers.
 boolean equals(Object object)
          Indicates if this derived unit is semantically identical to an object.
 double fromDerivedUnit(double amount)
          Converts a numerical value to this unit from the derived unit.
 double[] fromDerivedUnit(double[] input, double[] output)
          Converts numerical values to this unit from the derived unit.
 float fromDerivedUnit(float amount)
          Converts a numerical value to this unit from the derived unit.
 float[] fromDerivedUnit(float[] input, float[] output)
          Converts numerical values to this unit from the derived unit.
 String getCanonicalString()
          Returns the canonical string representation of the unit.
 DerivedUnit getDerivedUnit()
          Returns the derived unit that is convertible with this unit.
 UnitDimension getDimension()
          Returns the unit dimension of this derived unit.
 QuantityDimension getQuantityDimension()
          Returns the quantity dimension of this derived unit.
 int hashCode()
          Returns the hash code of this instance.
 boolean isCompatible(Unit that)
          Indicates if values in this unit are convertible with another unit.
 boolean isDimensionless()
          Indicates if this derived unit is dimensionless.
 boolean isReciprocalOf(DerivedUnit that)
          Indicates if this derived unit is the reciprocal of another derived unit (e.g.
static void main(String[] args)
          Tests this class.
protected  Unit myDivideBy(Unit that)
          Divides this derived unit by another.
protected  Unit myDivideInto(Unit that)
          Divides this derived unit into another.
protected  Unit myMultiplyBy(Unit that)
          Multiplies this derived unit by another.
protected  Unit myRaiseTo(int power)
          Raises this derived unit to a power.
protected  void setDimension(UnitDimension dimension)
          Sets the unit dimension of this derived unit.
 double toDerivedUnit(double amount)
          Converts a numerical value from this unit to the derived unit.
 double[] toDerivedUnit(double[] input, double[] output)
          Converts numerical values from this unit to the derived unit.
 float toDerivedUnit(float amount)
          Converts a numerical value from this unit to the derived unit.
 float[] toDerivedUnit(float[] input, float[] output)
          Converts numerical values from this unit to the derived unit.
 String toString()
          Returns a string representation of this unit.
 
Methods inherited from class ucar.units.UnitImpl
convertTo, convertTo, convertTo, convertTo, convertTo, convertTo, divideBy, divideInto, getConverterTo, getName, getPlural, getSymbol, getUnitName, log, makeLabel, multiplyBy, multiplyBy, raiseTo, shiftTo, shiftTo
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ucar.units.Unit
convertTo, convertTo, convertTo, convertTo, convertTo, convertTo, divideBy, divideInto, getConverterTo, getName, getPlural, getSymbol, getUnitName, log, makeLabel, multiplyBy, multiplyBy, raiseTo, shiftTo, shiftTo
 

Field Detail

DIMENSIONLESS

public static final DerivedUnitImpl DIMENSIONLESS
The dimensionless derived unit.

Constructor Detail

DerivedUnitImpl

protected DerivedUnitImpl()
Constructs a dimensionless derived unit from nothing.


DerivedUnitImpl

protected DerivedUnitImpl(UnitDimension dimension)
Constructs from a unit dimension. This is a trusted constructor for use by subclasses only.

Parameters:
dimension - The unit dimension.

DerivedUnitImpl

protected DerivedUnitImpl(UnitName id)
Constructs from identifiers. This is a trusted constructor for use by subclasses only.

Parameters:
id - The identifiers for the unit.

DerivedUnitImpl

protected DerivedUnitImpl(UnitDimension dimension,
                          UnitName id)
Constructs from a unit dimension and identifiers. This is a trusted constructor for use by subclasses only.

Parameters:
dimension - The unit dimension.
id - The identifiers for the unit.
Method Detail

setDimension

protected void setDimension(UnitDimension dimension)
Sets the unit dimension of this derived unit. This is a trusted method for use by subclasses only and should be called only once immediately after construction of this superinstance.

Parameters:
dimension - The unit dimension.

getDimension

public final UnitDimension getDimension()
Returns the unit dimension of this derived unit.

Specified by:
getDimension in interface DerivedUnit
Returns:
The unit dimension of this derived unit.

getQuantityDimension

public final QuantityDimension getQuantityDimension()
Returns the quantity dimension of this derived unit.

Specified by:
getQuantityDimension in interface DerivedUnit
Returns:
The quantity dimension of this derived unit.

isReciprocalOf

public final boolean isReciprocalOf(DerivedUnit that)
Indicates if this derived unit is the reciprocal of another derived unit (e.g. "second" and "hertz").

Specified by:
isReciprocalOf in interface DerivedUnit
Parameters:
that - The other, derived unit.

getDerivedUnit

public final DerivedUnit getDerivedUnit()
Returns the derived unit that is convertible with this unit. Obviously, the method returns this derived unit.

Specified by:
getDerivedUnit in interface DerivableUnit
Specified by:
getDerivedUnit in interface Unit
Returns:
this.

clone

public final Unit clone(UnitName id)
Clones the derived unit changing the identifiers.

Specified by:
clone in interface Unit
Parameters:
id - The identifiers for the new unit.
Returns:
The new unit.

myMultiplyBy

protected Unit myMultiplyBy(Unit that)
                     throws MultiplyException
Multiplies this derived unit by another.

Specified by:
myMultiplyBy in class UnitImpl
Parameters:
that - The other unit.
Returns:
The product of the two units.
Throws:
MultiplyException - Can't multiply these units.

myDivideBy

protected Unit myDivideBy(Unit that)
                   throws OperationException
Divides this derived unit by another.

Specified by:
myDivideBy in class UnitImpl
Parameters:
that - The other unit.
Returns:
The quotient of the two units.
Throws:
OperationException - Can't divide these units.

myDivideInto

protected Unit myDivideInto(Unit that)
                     throws OperationException
Divides this derived unit into another.

Specified by:
myDivideInto in class UnitImpl
Parameters:
that - The other unit.
Returns:
The quotient of the two units.
Throws:
OperationException - Can't divide these units.

myRaiseTo

protected Unit myRaiseTo(int power)
Raises this derived unit to a power.

Specified by:
myRaiseTo in class UnitImpl
Parameters:
power - The power.
Returns:
This derived unit raised to the given power.

toDerivedUnit

public final float toDerivedUnit(float amount)
Converts a numerical value from this unit to the derived unit. Obviously, the numerical value is unchanged.

Specified by:
toDerivedUnit in interface DerivableUnit
Parameters:
amount - The numerical values in this unit.
Returns:
The numerical value in the derived unit.

toDerivedUnit

public final double toDerivedUnit(double amount)
Converts a numerical value from this unit to the derived unit. Obviously, the numerical value is unchanged.

Specified by:
toDerivedUnit in interface DerivableUnit
Parameters:
amount - The numerical values in this unit.
Returns:
The numerical value in the derived unit.

toDerivedUnit

public final float[] toDerivedUnit(float[] input,
                                   float[] output)
Converts numerical values from this unit to the derived unit. Obviously, the numerical values are unchanged.

Specified by:
toDerivedUnit in interface DerivableUnit
Parameters:
input - The numerical values in this unit.
output - The numerical values in the derived unit. May be the same array as input.
Returns:
output.

toDerivedUnit

public final double[] toDerivedUnit(double[] input,
                                    double[] output)
Converts numerical values from this unit to the derived unit. Obviously, the numerical values are unchanged.

Specified by:
toDerivedUnit in interface DerivableUnit
Parameters:
input - The numerical values in this unit.
output - The numerical values in the derived unit. May be the same array as input.
Returns:
output.

fromDerivedUnit

public final float fromDerivedUnit(float amount)
Converts a numerical value to this unit from the derived unit. Obviously, the numerical value is unchanged.

Specified by:
fromDerivedUnit in interface DerivableUnit
Parameters:
amount - The numerical values in the derived unit.
Returns:
The numerical value in this unit.

fromDerivedUnit

public final double fromDerivedUnit(double amount)
Converts a numerical value to this unit from the derived unit. Obviously, the numerical value is unchanged.

Specified by:
fromDerivedUnit in interface DerivableUnit
Parameters:
amount - The numerical values in the derived unit.
Returns:
The numerical value in this unit.

fromDerivedUnit

public final float[] fromDerivedUnit(float[] input,
                                     float[] output)
Converts numerical values to this unit from the derived unit. Obviously, the numerical values are unchanged.

Specified by:
fromDerivedUnit in interface DerivableUnit
Parameters:
input - The numerical values in the derived unit.
output - The numerical values in this unit. May be the same array as input.
Returns:
output.

fromDerivedUnit

public final double[] fromDerivedUnit(double[] input,
                                      double[] output)
Converts numerical values to this unit from the derived unit. Obviously, the numerical values are unchanged.

Specified by:
fromDerivedUnit in interface DerivableUnit
Parameters:
input - The numerical values in the derived unit.
output - The numerical values in this unit. May be the same array as input.
Returns:
output.

isCompatible

public final boolean isCompatible(Unit that)
Indicates if values in this unit are convertible with another unit.

Specified by:
isCompatible in interface Unit
Overrides:
isCompatible in class UnitImpl
Parameters:
that - The other unit.
Returns:
true if and only if values in this unit are convertible to values in that.

equals

public boolean equals(Object object)
Indicates if this derived unit is semantically identical to an object.

Specified by:
equals in interface Unit
Overrides:
equals in class Object
Parameters:
object - The object
Returns:
true if and only if this derived unit is semantically identical to object.

hashCode

public int hashCode()
Returns the hash code of this instance.

Specified by:
hashCode in class UnitImpl
Returns:
The hash code of this instance.

isDimensionless

public boolean isDimensionless()
Indicates if this derived unit is dimensionless.

Specified by:
isDimensionless in interface Unit
Returns:
true if and only if this derived unit is dimensionless.

toString

public String toString()
Returns a string representation of this unit. If the symbol or name is available, then that is returned; otherwise, the corresponding expression in base units is returned.

Specified by:
toString in interface Unit
Overrides:
toString in class UnitImpl
Returns:
The string expression for this derived unit.

getCanonicalString

public String getCanonicalString()
Returns the canonical string representation of the unit.

Specified by:
getCanonicalString in interface Unit
Returns:
The canonical string representation.

main

public static void main(String[] args)
                 throws Exception
Tests this class.

Throws:
Exception


Copyright © 1999-2011 UCAR/Unidata. All Rights Reserved.