ucar.units
Class LogarithmicUnit

java.lang.Object
  extended by ucar.units.UnitImpl
      extended by ucar.units.LogarithmicUnit
All Implemented Interfaces:
Serializable, DerivableUnit, Unit

public final class LogarithmicUnit
extends UnitImpl
implements DerivableUnit

Provides support for units that are based on a logarithm of the ratio of a physical quantity to an underlying reference level. Instances of this class are immutable.

Version:
$Id: OffsetUnit.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
 
Constructor Summary
LogarithmicUnit(Unit reference, double base)
          Constructs from a reference level and a logarithmic base.
LogarithmicUnit(Unit reference, double base, UnitName id)
          Constructs from a reference level, a logarithmic base, and a unit identifier.
 
Method Summary
 Unit clone(UnitName id)
          Clones this unit, changing the identifier.
 boolean equals(Object object)
          Indicates if this unit is semantically identical to an object.
 double fromDerivedUnit(double amount)
          Converts a value in the convertible derived unit to the equivalent value in this unit.
 double[] fromDerivedUnit(double[] input, double[] output)
          Converts values in the convertible derived unit to the equivalent values in this unit.
 float fromDerivedUnit(float amount)
          Converts a value in the convertible derived unit to the equivalent value in this unit.
 float[] fromDerivedUnit(float[] input, float[] output)
          Converts values in the convertible derived unit to the equivalent values in this unit.
 double getBase()
          Returns the logarithmic base.
 String getCanonicalString()
          Returns the canonical string representation of the unit.
 DerivedUnit getDerivedUnit()
          Returns the derived unit that is convertible with this unit.
 DerivableUnit getReference()
          Returns the reference level.
 int hashCode()
          Returns the hash code of this instance.
 boolean isDimensionless()
          Indicates if this unit is dimensionless.
static void main(String[] args)
          Tests this class.
protected  Unit myDivideBy(Unit that)
          Divide this unit by another unit.
protected  Unit myDivideInto(Unit that)
          Divide this unit into another unit.
protected  Unit myMultiplyBy(Unit that)
          Multiply this unit by another unit.
protected  Unit myRaiseTo(int power)
          Raise this unit to a power.
 double toDerivedUnit(double amount)
          Converts a value in this unit to the equivalent value in the convertible derived unit.
 double[] toDerivedUnit(double[] input, double[] output)
          Converts values in this unit to the equivalent values in the convertible derived unit.
 float toDerivedUnit(float amount)
          Converts a value in this unit to the equivalent value in the convertible derived unit.
 float[] toDerivedUnit(float[] input, float[] output)
          Converts values in this unit to the equivalent values in the convertible derived unit.
 String toString()
          Returns the 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, isCompatible, log, makeLabel, multiplyBy, multiplyBy, raiseTo, shiftTo, shiftTo
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LogarithmicUnit

public LogarithmicUnit(Unit reference,
                       double base)
Constructs from a reference level and a logarithmic base.

Parameters:
reference - The reference level. Must be a DerivableUnit.
base - The logarithmic base. Must be 2, Math.E, or 10.
Throws:
IllegalArgumentException - if reference isn't a DerivableUnit.
IllegalArgumentException - if base isn't one of the allowed values.
NullPointerException - if reference is null.

LogarithmicUnit

public LogarithmicUnit(Unit reference,
                       double base,
                       UnitName id)
Constructs from a reference level, a logarithmic base, and a unit identifier.

Parameters:
reference - The reference level. Must be a DerivableUnit.
base - The logarithmic base. Must be 2, Math.E, or 10.
id - The identifier for the new unit.
Throws:
IllegalArgumentException - if reference isn't a DerivableUnit.
IllegalArgumentException - if base isn't one of the allowed values.
NullPointerException - if reference is null.
Method Detail

getReference

public DerivableUnit getReference()
Returns the reference level.

Returns:
The reference level.

getBase

public double getBase()
Returns the logarithmic base.

Returns:
The logarithmic base of this unit.

clone

public Unit clone(UnitName id)
Clones this unit, changing the identifier.

Specified by:
clone in interface Unit
Parameters:
id - The identifier for the new unit.
Returns:
This unit with its identifier changed.

myMultiplyBy

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

Specified by:
myMultiplyBy in class UnitImpl
Parameters:
that - The unit to multiply this unit by. Must be dimensionless.
Returns:
The product of this unit and that.
Throws:
MultiplyException - Can't multiply these units together.

myDivideBy

protected Unit myDivideBy(Unit that)
                   throws DivideException
Divide this unit by another unit.

Specified by:
myDivideBy in class UnitImpl
Parameters:
that - The unit to divide this unit by.
Returns:
The quotient of this unit and that.
Throws:
DivideException - Can't divide these units.

myDivideInto

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

Specified by:
myDivideInto in class UnitImpl
Parameters:
that - The unit to divide this unit into.
Returns:
The quotient of that unit and this unit.
Throws:
DivideException - Can't divide these units.
OperationException - Can't divide these units.

myRaiseTo

protected Unit myRaiseTo(int power)
                  throws RaiseException
Raise this unit to a power.

Specified by:
myRaiseTo in class UnitImpl
Parameters:
power - The power to raise this unit by. The only meaningful values are 0 and 1.
Returns:
The result of raising this unit by the power power.
Throws:
RaiseException - Can't raise this unit to power, which is neither 0 nor 1.

getDerivedUnit

public DerivedUnit getDerivedUnit()
Returns the derived unit that is convertible with this unit.

Specified by:
getDerivedUnit in interface DerivableUnit
Specified by:
getDerivedUnit in interface Unit
Returns:
The derived unit that is convertible with this unit.

toDerivedUnit

public float toDerivedUnit(float amount)
                    throws ConversionException
Converts a value in this unit to the equivalent value in the convertible derived unit.

Specified by:
toDerivedUnit in interface DerivableUnit
Parameters:
amount - The value in this unit.
Returns:
The equivalent value in the convertible derived unit.
Throws:
ConversionException - Can't convert between units.

toDerivedUnit

public double toDerivedUnit(double amount)
                     throws ConversionException
Converts a value in this unit to the equivalent value in the convertible derived unit.

Specified by:
toDerivedUnit in interface DerivableUnit
Parameters:
amount - The value in this unit.
Returns:
The equivalent value in the convertible derived unit.
Throws:
ConversionException - Can't convert between units.

toDerivedUnit

public float[] toDerivedUnit(float[] input,
                             float[] output)
                      throws ConversionException
Converts values in this unit to the equivalent values in the convertible derived unit.

Specified by:
toDerivedUnit in interface DerivableUnit
Parameters:
input - The values in this unit.
output - The equivalent values in the convertible derived unit. May be the same array as input.
Returns:
output.
Throws:
ConversionException - Can't convert between units.

toDerivedUnit

public double[] toDerivedUnit(double[] input,
                              double[] output)
                       throws ConversionException
Converts values in this unit to the equivalent values in the convertible derived unit.

Specified by:
toDerivedUnit in interface DerivableUnit
Parameters:
input - The values in this unit.
output - The equivalent values in the convertible derived unit. May be the same array as input.
Returns:
output.
Throws:
ConversionException - Can't convert between units.

fromDerivedUnit

public float fromDerivedUnit(float amount)
                      throws ConversionException
Converts a value in the convertible derived unit to the equivalent value in this unit.

Specified by:
fromDerivedUnit in interface DerivableUnit
Parameters:
amount - The value in the convertible derived unit.
Returns:
The equivalent value in this unit.
Throws:
ConversionException - Can't convert between units.

fromDerivedUnit

public double fromDerivedUnit(double amount)
                       throws ConversionException
Converts a value in the convertible derived unit to the equivalent value in this unit.

Specified by:
fromDerivedUnit in interface DerivableUnit
Parameters:
amount - The value in the convertible derived unit.
Returns:
The equivalent value in this unit.
Throws:
ConversionException - Can't convert between units.

fromDerivedUnit

public float[] fromDerivedUnit(float[] input,
                               float[] output)
                        throws ConversionException
Converts values in the convertible derived unit to the equivalent values in this unit.

Specified by:
fromDerivedUnit in interface DerivableUnit
Parameters:
input - The values in the convertible derived unit.
output - The equivalent values in this unit. May be the same array as input.
Returns:
output.
Throws:
ConversionException - Can't convert between units.

fromDerivedUnit

public double[] fromDerivedUnit(double[] input,
                                double[] output)
                         throws ConversionException
Converts values in the convertible derived unit to the equivalent values in this unit.

Specified by:
fromDerivedUnit in interface DerivableUnit
Parameters:
input - The values in the convertible derived unit.
output - The equivalent values in this unit. May be the same array as input.
Returns:
output.
Throws:
ConversionException - Can't convert between units.

equals

public boolean equals(Object object)
Indicates if this 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 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 unit is dimensionless.

Specified by:
isDimensionless in interface Unit
Returns:
true, always.

toString

public String toString()
Returns the string representation of this unit.

Specified by:
toString in interface Unit
Overrides:
toString in class UnitImpl
Returns:
The string representation of this 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.