ucar.units
Interface Unit

All Known Subinterfaces:
DerivedUnit
All Known Implementing Classes:
BaseUnit, DerivedUnitImpl, LogarithmicUnit, OffsetUnit, ScaledUnit, TimeScaleUnit, UnitImpl, UnknownUnit

public interface Unit

Interface for units.

Version:
$Id: Unit.java 64 2006-07-12 22:30:50Z edavis $
Author:
Steven R. Emmerson

Method Summary
 Unit clone(UnitName id)
          Clones this unit, changing the identifier.
 double[] convertTo(double[] amounts, Unit outputUnit)
          Converts numerical values from this unit to another unit.
 double[] convertTo(double[] input, Unit outputUnit, double[] output)
          Converts numerical values from this unit to another unit.
 double convertTo(double amount, Unit outputUnit)
          Converts a numerical value from this unit to another unit.
 float[] convertTo(float[] amounts, Unit outputUnit)
          Converts numerical values from this unit to another unit.
 float[] convertTo(float[] input, Unit outputUnit, float[] output)
          Converts numerical values from this unit to another unit.
 float convertTo(float amount, Unit outputUnit)
          Converts a numerical value from this unit to another unit.
 Unit divideBy(Unit that)
          Divides this unit by another.
 Unit divideInto(Unit that)
          Divides this unit into another.
 boolean equals(Object object)
          Indicates if this unit is semantically identical to an object.
 String getCanonicalString()
          Returns the canonical string representation of the unit.
 Converter getConverterTo(Unit outputUnit)
          Gets a Converter that converts numeric values from this unit to another, compatible unit.
 DerivedUnit getDerivedUnit()
          Returns the derived unit that underlies this unit.
 String getName()
          Gets the name of this unit.
 String getPlural()
          Gets the plural form of the name of this unit.
 String getSymbol()
          Gets the symbol of this unit.
 UnitName getUnitName()
          Gets the identifier of this unit.
 boolean isCompatible(Unit that)
          Indicates if this unit is compatible with another unit.
 boolean isDimensionless()
          Indicates if values in this unit are dimensionless.
 Unit log(double base)
          Returns a logarithmic unit whose reference level is equal to this unit.
 String makeLabel(String quantityID)
          Makes a label for a named quantity.
 Unit multiplyBy(double scale)
          Multiplies this unit by a scale factor.
 Unit multiplyBy(Unit that)
          Multiplies this unit by another.
 Unit raiseTo(int power)
          Raises this unit to a power.
 Unit shiftTo(Date origin)
          Returns a unit identical to this instance but whose origin (i.e., zero value) has been shifted to the given time.
 Unit shiftTo(double origin)
          Returns a unit identical to this instance but whose origin (i.e., zero value) has been shifted to the given value.
 String toString()
          Returns the string representation of the unit.
 

Method Detail

getUnitName

UnitName getUnitName()
Gets the identifier of this unit.

Returns:
The identifier of this unit. May be null.

getName

String getName()
Gets the name of this unit.

Returns:
The name of this unit. May be null.

getPlural

String getPlural()
Gets the plural form of the name of this unit.

Returns:
The plural of the name of this unit. May be null.

getSymbol

String getSymbol()
Gets the symbol of this unit.

Returns:
The symbol for this unit. May be null.

toString

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

Overrides:
toString in class Object
Returns:
The string representation of the unit

getCanonicalString

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

Returns:
The canonical string representation.

getDerivedUnit

DerivedUnit getDerivedUnit()
Returns the derived unit that underlies this unit.

Returns:
The derived unit that underlies this unit.

clone

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

Parameters:
id - The identifier for the new unit.
Returns:
The new unit.

multiplyBy

Unit multiplyBy(Unit that)
                throws MultiplyException
Multiplies this unit by another.

Parameters:
that - The other unit.
Returns:
The product of multiplying this unit by the other unit.
Throws:
MultiplyException - Can't multiply these units.

multiplyBy

Unit multiplyBy(double scale)
                throws MultiplyException
Multiplies this unit by a scale factor. For example, if m is a meter unit, then m.multiplyBy(1e-2) returns a centimeter unit.

Parameters:
scale - The scale factor.
Returns:
The result of multiplying this unit by the scale factor.
Throws:
MultiplyException - if scale is zero.

divideBy

Unit divideBy(Unit that)
              throws OperationException
Divides this unit by another.

Parameters:
that - The other unit.
Returns:
The quotient of dividing this unit by the other unit.
Throws:
OperationException - Can't divide these units.

divideInto

Unit divideInto(Unit that)
                throws OperationException
Divides this unit into another.

Parameters:
that - The other unit.
Returns:
The quotient of dividing this unit into the other unit.
Throws:
OperationException - Can't divide these units.

raiseTo

Unit raiseTo(int power)
             throws RaiseException
Raises this unit to a power.

Parameters:
power - The power.
Returns:
This result of raising this unit to the power.
Throws:
RaiseException - Can't raise this unit to a power.

shiftTo

Unit shiftTo(double origin)
             throws ShiftException
Returns a unit identical to this instance but whose origin (i.e., zero value) has been shifted to the given value. For example, if degK is a Kelvin unit, then degK.shiftTo(273.15) is a Celsius unit.

Parameters:
origin - The new origin in units of this instance.
Returns:
A unit convertible with this instance but whose zero value is equal to the value origin of this instance.
Throws:
ShiftException - if the corresponding new unit can't be created.

shiftTo

Unit shiftTo(Date origin)
             throws ShiftException
Returns a unit identical to this instance but whose origin (i.e., zero value) has been shifted to the given time. For example, if sec is a second unit, then sec.shiftTo(new Date(0L) is the unit corresponding to seconds since the epoch (1970-01-01 00:00:00 UTC).

Parameters:
origin - The new origin.
Returns:
A unit whose zero value is the time given by origin.
Throws:
ShiftException - if the corresponding new unit can't be created. For example, if this instance isn't a unit of time.

log

Unit log(double base)
Returns a logarithmic unit whose reference level is equal to this unit. For example, if mW is a milliwatt unit, then mW.log(10.) returns a base-ten logarithmic unit with a milliwatt reference level.

Parameters:
base - The logarithmic base. Must be one of 2, Math.E , or 10.
Throws:
IllegalArgumentException - if base isn't one of the allowed values.

getConverterTo

Converter getConverterTo(Unit outputUnit)
                         throws ConversionException
Gets a Converter that converts numeric values from this unit to another, compatible unit.

Parameters:
outputUnit - The unit to which to convert the numerical values.
Returns:
A converter of numeric values from this unit to the other unit.
Throws:
ConversionException - The units aren't compatible.

convertTo

float convertTo(float amount,
                Unit outputUnit)
                throws ConversionException
Converts a numerical value from this unit to another unit.

Parameters:
amount - The numerical value in this unit.
outputUnit - The unit to which to convert the numerical value.
Returns:
The numerical value in the output unit.
Throws:
ConversionException - The units aren't compatible.

convertTo

double convertTo(double amount,
                 Unit outputUnit)
                 throws ConversionException
Converts a numerical value from this unit to another unit.

Parameters:
amount - The numerical value in this unit.
outputUnit - The unit to which to convert the numerical value.
Returns:
The numerical value in the output unit.
Throws:
ConversionException - The units aren't compatible.

convertTo

float[] convertTo(float[] amounts,
                  Unit outputUnit)
                  throws ConversionException
Converts numerical values from this unit to another unit.

Parameters:
amounts - The numerical values in this unit.
outputUnit - The unit to which to convert the numerical values.
Returns:
The numerical values in the output unit. in allocated space.
Throws:
ConversionException - The units aren't compatible.

convertTo

double[] convertTo(double[] amounts,
                   Unit outputUnit)
                   throws ConversionException
Converts numerical values from this unit to another unit.

Parameters:
amounts - The numerical values in this unit.
outputUnit - The unit to which to convert the numerical values.
Returns:
The numerical values in the output unit. in allocated space.
Throws:
ConversionException - The units aren't compatible.

convertTo

float[] convertTo(float[] input,
                  Unit outputUnit,
                  float[] output)
                  throws ConversionException
Converts numerical values from this unit to another unit.

Parameters:
input - The numerical values in this unit.
outputUnit - The unit to which to convert the numerical values.
output - The output numerical values. May be the same array as the input values.
Returns:
output.
Throws:
ConversionException - The units aren't compatible.

convertTo

double[] convertTo(double[] input,
                   Unit outputUnit,
                   double[] output)
                   throws ConversionException
Converts numerical values from this unit to another unit.

Parameters:
input - The numerical values in this unit.
outputUnit - The unit to which to convert the numerical values.
output - The output numerical values. May be the same array as the input values.
Returns:
output.
Throws:
ConversionException - The units aren't compatible.

isCompatible

boolean isCompatible(Unit that)
Indicates if this unit is compatible with another unit.

Parameters:
that - The other unit.
Returns:
True iff values in this unit are convertible to values in the other unit.

equals

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

Overrides:
equals in class Object
Parameters:
object - The object.
Returns:
true if and only if this unit is semantically identical to the object.

makeLabel

String makeLabel(String quantityID)
Makes a label for a named quantity.

Parameters:
quantityID - An identifier of the quantity for which the label is intended (e.g. "altitude").
Returns:
A label (e.g. "altitude/km").

isDimensionless

boolean isDimensionless()
Indicates if values in this unit are dimensionless.

Returns:
true if and only if this unit is dimensionless.


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