ucar.units
Class TimeScaleUnit

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

public final class TimeScaleUnit
extends UnitImpl

Provides support for a reference time unit whose origin is at a certain time. Instances of this class are immutable.

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

Nested Class Summary
protected static class TimeScaleUnit.MyConverter
          Provides support for Converter-s.
 
Constructor Summary
TimeScaleUnit(Unit unit, Date origin)
          Constructs from a reference unit and a time origin.
TimeScaleUnit(Unit unit, Date origin, UnitName id)
          Constructs from a reference unit, a time origin, and an 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.
 String getCanonicalString()
          Returns the canonical string representation of the unit.
 Converter getConverterTo(Unit outputUnit)
          Returns a Converter for converting numeric values from this unit to another unit.
 DerivedUnit getDerivedUnit()
          Returns the derived unit underlying the reference time unit.
 Date getOrigin()
          Returns the time origin.
 Unit getUnit()
          Returns the reference unit.
 int hashCode()
          Returns the hash code of this instance.
 boolean isCompatible(Unit that)
          Indicates if numeric values in this unit are convertible to another unit.
 boolean isDimensionless()
          Indicates if this unit is dimensionless.
static void main(String[] args)
          Tests this class.
protected  Unit myDivideBy(Unit that)
          Divides this unit by another unit.
protected  Unit myDivideInto(Unit that)
          Divides this unit into another unit.
protected  Unit myMultiplyBy(Unit that)
          Multiplies this unit by another unit.
protected  Unit myRaiseTo(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 this unit.
 
Methods inherited from class ucar.units.UnitImpl
convertTo, convertTo, convertTo, convertTo, convertTo, convertTo, divideBy, divideInto, getName, getPlural, getSymbol, getUnitName, log, makeLabel, multiplyBy, multiplyBy, raiseTo
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TimeScaleUnit

public TimeScaleUnit(Unit unit,
                     Date origin)
              throws BadUnitException,
                     UnitSystemException
Constructs from a reference unit and a time origin.

Parameters:
unit - The reference time unit.
origin - The time origin.
Throws:
BadUnitException - unit is not a unit of time.
UnitSystemException

TimeScaleUnit

public TimeScaleUnit(Unit unit,
                     Date origin,
                     UnitName id)
              throws BadUnitException,
                     UnitSystemException
Constructs from a reference unit, a time origin, and an identifier.

Parameters:
unit - The reference time unit.
origin - The time origin.
id - The identifier.
Throws:
BadUnitException - unit is not a unit of time.
UnitSystemException
Method Detail

getUnit

public Unit getUnit()
Returns the reference unit.

Returns:
The reference unit.

getOrigin

public Date getOrigin()
Returns the time origin.

Returns:
The time origin.

clone

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

Parameters:
id - The new identifier.
Returns:
This unit with the new identifier.

shiftTo

public Unit shiftTo(double origin)
             throws ShiftException
Description copied from interface: Unit
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.

Specified by:
shiftTo in interface Unit
Overrides:
shiftTo in class UnitImpl
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

public Unit shiftTo(Date origin)
             throws ShiftException
Description copied from interface: Unit
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).

Specified by:
shiftTo in interface Unit
Overrides:
shiftTo in class UnitImpl
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.

myMultiplyBy

protected Unit myMultiplyBy(Unit that)
                     throws MultiplyException
Multiplies this unit by another unit. This operation is invalid.

Specified by:
myMultiplyBy in class UnitImpl
Parameters:
that - The other unit.
Returns:
The product of multiplying this unit by the other unit.
Throws:
MultiplyException - Illegal operation. Always thrown.

myDivideBy

protected Unit myDivideBy(Unit that)
                   throws DivideException
Divides this unit by another unit. This operation is invalid.

Specified by:
myDivideBy in class UnitImpl
Parameters:
that - The other unit.
Returns:
The quotient of dividing this unit by the other unit.
Throws:
DivideException - Illegal operation. Always thrown.

myDivideInto

protected Unit myDivideInto(Unit that)
                     throws DivideException
Divides this unit into another unit. This operation is invalid.

Specified by:
myDivideInto in class UnitImpl
Parameters:
that - The other unit.
Returns:
The quotient of dividing this unit into the other unit.
Throws:
DivideException - Illegal operation. Always thrown.

myRaiseTo

protected Unit myRaiseTo(int power)
                  throws RaiseException
Raises this unit to a power. This operation is invalid.

Specified by:
myRaiseTo in class UnitImpl
Parameters:
power - The power.
Returns:
The result of raising this unit to the power.
Throws:
RaiseException - Illegal operation. Always thrown.

getDerivedUnit

public DerivedUnit getDerivedUnit()
Returns the derived unit underlying the reference time unit.

Returns:
The derived unit underlying the reference time unit.

getConverterTo

public Converter getConverterTo(Unit outputUnit)
                         throws ConversionException
Returns a Converter for converting numeric values from this unit to another unit.

Specified by:
getConverterTo in interface Unit
Overrides:
getConverterTo in class UnitImpl
Parameters:
outputUnit - The other unit. Shall be a TimeScaleUnit.
Returns:
A Converter.
Throws:
ConversionException - outputUnit is not a TimeScaleUnit.

isCompatible

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

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

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. TimeScaleUnit-s are never dimensionless.

Returns:
false.

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.

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.