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 classTimeScaleUnit.MyConverterProvides 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 Unitclone(UnitName id)Clones this unit, changing the identifier.booleanequals(Object object)Indicates if this unit is semantically identical to an object.StringgetCanonicalString()Returns the canonical string representation of the unit.ConvertergetConverterTo(Unit outputUnit)Returns a Converter for converting numeric values from this unit to another unit.DerivedUnitgetDerivedUnit()Returns the derived unit underlying the reference time unit.DategetOrigin()Returns the time origin.UnitgetUnit()Returns the reference unit.inthashCode()Returns the hash code of this instance.booleanisCompatible(Unit that)Indicates if numeric values in this unit are convertible to another unit.booleanisDimensionless()Indicates if this unit is dimensionless.protected UnitmyDivideBy(Unit that)Divides this unit by another unit.protected UnitmyDivideInto(Unit that)Divides this unit into another unit.protected UnitmyMultiplyBy(Unit that)Multiplies this unit by another unit.protected UnitmyRaiseTo(int power)Raises this unit to a power.UnitshiftTo(double origin)Returns a unit identical to this instance but whose origin (i.e., zero value) has been shifted to the given value.UnitshiftTo(Date origin)Returns a unit identical to this instance but whose origin (i.e., zero value) has been shifted to the given time.StringtoString()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-unitis 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-unitis 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:UnitReturns a unit identical to this instance but whose origin (i.e., zero value) has been shifted to the given value. For example, ifdegKis a Kelvin unit, thendegK.shiftTo(273.15)is a Celsius unit.- Specified by:
shiftToin interfaceUnit- Overrides:
shiftToin 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
originof 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:UnitReturns a unit identical to this instance but whose origin (i.e., zero value) has been shifted to the given time. For example, ifsecis 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:
shiftToin interfaceUnit- Overrides:
shiftToin 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:
myMultiplyByin 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:
myDivideByin 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:
myDivideIntoin 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:
myRaiseToin 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:
getConverterToin interfaceUnit- Overrides:
getConverterToin classUnitImpl- Parameters:
outputUnit- The other unit. Shall be a TimeScaleUnit.- Returns:
- A Converter.
- Throws:
ConversionException-outputUnitis not a TimeScaleUnit.
-
isCompatible
public final boolean isCompatible(Unit that)
Indicates if numeric values in this unit are convertible to another unit.- Specified by:
isCompatiblein interfaceUnit- Overrides:
isCompatiblein classUnitImpl- Parameters:
that- The other unit.- Returns:
trueif 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.
-
-