Package ucar.units
Class TimeScaleUnit
- java.lang.Object
-
- ucar.units.UnitImpl
-
- ucar.units.TimeScaleUnit
-
- All Implemented Interfaces:
Serializable
,Unit
@Immutable 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.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
TimeScaleUnit.MyConverter
Provides support for Converter-s.
-
Constructor Summary
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.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(double origin)
Returns a unit identical to this instance but whose origin (i.e., zero value) has been shifted to the given value.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.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
-
-
-
-
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, ifdegK
is a Kelvin unit, thendegK.shiftTo(273.15)
is a Celsius unit.- Specified by:
shiftTo
in interfaceUnit
- Overrides:
shiftTo
in classUnitImpl
- 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, ifsec
is a second unit, thensec.shiftTo(new Date(0L)
is the unit corresponding to seconds since the epoch (1970-01-01 00:00:00 UTC).- Specified by:
shiftTo
in interfaceUnit
- Overrides:
shiftTo
in classUnitImpl
- 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 classUnitImpl
- 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 classUnitImpl
- 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 classUnitImpl
- 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 classUnitImpl
- 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 interfaceUnit
- Overrides:
getConverterTo
in classUnitImpl
- 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 interfaceUnit
- Overrides:
isCompatible
in classUnitImpl
- Parameters:
that
- The other unit.- Returns:
true
if and only if numeric values in this unit are convertible tothat
.
-
equals
public boolean equals(Object object)
Indicates if this unit is semantically identical to an object.
-
hashCode
public int hashCode()
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.
-
getCanonicalString
public String getCanonicalString()
Returns the canonical string representation of the unit.- Returns:
- The canonical string representation.
-
-