Package ucar.units
Class UnitImpl
- java.lang.Object
-
- ucar.units.UnitImpl
-
- All Implemented Interfaces:
Serializable,Unit
- Direct Known Subclasses:
DerivedUnitImpl,LogarithmicUnit,OffsetUnit,ScaledUnit,TimeScaleUnit
@Immutable public abstract class UnitImpl extends Object implements Unit, Serializable
Provides support for classes that implement units.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classUnitImpl.MyConverterProvides support for converting numeric values from this unit to another unit.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description double[]convertTo(double[] amounts, Unit outputUnit)Converts numeric values from this unit to another unit.double[]convertTo(double[] input, Unit outputUnit, double[] output)Converts numeric values from this unit to another unit.doubleconvertTo(double amount, Unit outputUnit)Converts a numeric value from this unit to another unit.float[]convertTo(float[] amounts, Unit outputUnit)Converts numeric values from this unit to another unit.float[]convertTo(float[] input, Unit outputUnit, float[] output)Converts numeric values from this unit to another unit.floatconvertTo(float amount, Unit outputUnit)Converts a numeric value from this unit to another unit.UnitdivideBy(Unit that)Divides this unit by another.UnitdivideInto(Unit that)Divides this unit into another.ConvertergetConverterTo(Unit outputUnit)Gets a Converter for converting numeric values from this unit to another, compatible unit.StringgetName()Gets the name of the unit.StringgetPlural()Gets the plural form of the name of the unit.StringgetSymbol()Gets the symbol for the unit.UnitNamegetUnitName()Gets the identifier of this unit.abstract inthashCode()Returns the hash code of this instance.booleanisCompatible(Unit that)Indicates if numeric values in this unit are convertible with another unit.Unitlog(double base)Returns a logarithmic unit whose reference level is equal to this unit.StringmakeLabel(String quantityID)Returns a label for a quantity in this unit.UnitmultiplyBy(double scale)Multiplies this unit by a scale factor.UnitmultiplyBy(Unit that)Multiplies this unit by another.protected abstract UnitmyDivideBy(Unit unit)Divides this unit by another.protected abstract UnitmyDivideInto(Unit unit)Divides this unit into another.protected abstract UnitmyMultiplyBy(Unit that)Multiplies this unit by another.protected abstract UnitmyRaiseTo(int power)Raises this unit to a power.UnitraiseTo(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 java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ucar.units.Unit
clone, equals, getCanonicalString, getDerivedUnit, isDimensionless
-
-
-
-
Constructor Detail
-
UnitImpl
protected UnitImpl()
Constructs with no ID.
-
UnitImpl
protected UnitImpl(UnitName id)
Constructs with the given ID.- Parameters:
id- The id of the unit (e.g. "foot"). May be null.
-
-
Method Detail
-
getUnitName
public final UnitName getUnitName()
Gets the identifier of this unit.- Specified by:
getUnitNamein interfaceUnit- Returns:
- The ID of this unit. May be
null.
-
getName
public final String getName()
Gets the name of the unit.
-
getPlural
public final String getPlural()
Gets the plural form of the name of the unit.
-
getSymbol
public final String getSymbol()
Gets the symbol for the unit.
-
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- 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- 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.
-
multiplyBy
public final Unit multiplyBy(Unit that) throws MultiplyException
Multiplies this unit by another.- Specified by:
multiplyByin interfaceUnit- Parameters:
that- The other unit.- Returns:
- The product of this unit multiplied by the other unit.
- Throws:
MultiplyException- Can't multiply these units.
-
multiplyBy
public Unit multiplyBy(double scale) throws MultiplyException
Description copied from interface:UnitMultiplies this unit by a scale factor. For example, ifmis a meter unit, thenm.multiplyBy(1e-2)returns a centimeter unit.- Specified by:
multiplyByin interfaceUnit- Parameters:
scale- The scale factor.- Returns:
- The result of multiplying this unit by the scale factor.
- Throws:
MultiplyException- ifscaleis zero.
-
myMultiplyBy
protected abstract Unit myMultiplyBy(Unit that) throws MultiplyException
Multiplies this unit by another.- Parameters:
that- The other unit.- Returns:
- The product of this unit multiplied by the other unit.
- Throws:
MultiplyException- Can't multiply these units.
-
divideBy
public final Unit divideBy(Unit that) throws OperationException
Divides this unit by another.- Specified by:
divideByin interfaceUnit- Parameters:
that- The other unit.- Returns:
- The quotient of this unit divided by the other unit.
- Throws:
OperationException- Can't divide these units.
-
myDivideBy
protected abstract Unit myDivideBy(Unit unit) throws OperationException
Divides this unit by another.- Parameters:
unit- The other unit.- Returns:
- The quotient of this unit divided by the other unit.
- Throws:
OperationException- Can't divide these units.
-
divideInto
public final Unit divideInto(Unit that) throws OperationException
Divides this unit into another.- Specified by:
divideIntoin interfaceUnit- Parameters:
that- The other unit.- Returns:
- The quotient of this unit divided into the other unit.
- Throws:
OperationException- Can't divide these units.
-
myDivideInto
protected abstract Unit myDivideInto(Unit unit) throws OperationException
Divides this unit into another.- Parameters:
unit- The other unit.- Returns:
- The quotient of this unit divided into the other unit.
- Throws:
OperationException- Can't divide these units.
-
raiseTo
public final Unit raiseTo(int power) throws RaiseException
Raises this unit to a power.- Specified by:
raiseToin interfaceUnit- Parameters:
power- The power.- Returns:
- The result of raising this unit to the power.
- Throws:
RaiseException- Can't raise this unit to a power.
-
myRaiseTo
protected abstract Unit myRaiseTo(int power) throws RaiseException
Raises this unit to a power.- Parameters:
power- The power.- Returns:
- The result of raising this unit to the power.
- Throws:
RaiseException- Can't raise this unit to a power.
-
log
public Unit log(double base)
Description copied from interface:UnitReturns a logarithmic unit whose reference level is equal to this unit. For example, ifmWis a milliwatt unit, thenmW.log(10.)returns a base-ten logarithmic unit with a milliwatt reference level.
-
getConverterTo
public Converter getConverterTo(Unit outputUnit) throws ConversionException
Gets a Converter for converting numeric values from this unit to another, compatible unit.- Specified by:
getConverterToin interfaceUnit- Parameters:
outputUnit- The unit to which to convert the numeric values.- Returns:
- A converter of values from this unit to the other unit.
- Throws:
ConversionException- The units aren't convertible.
-
convertTo
public float convertTo(float amount, Unit outputUnit) throws ConversionExceptionConverts a numeric value from this unit to another unit.- Specified by:
convertToin interfaceUnit- Parameters:
amount- The numeric value.outputUnit- The unit to which to convert the numeric value.- Returns:
- The numeric value in the output unit.
- Throws:
ConversionException- The units aren't convertible.
-
convertTo
public double convertTo(double amount, Unit outputUnit) throws ConversionExceptionConverts a numeric value from this unit to another unit.- Specified by:
convertToin interfaceUnit- Parameters:
amount- The numeric value.outputUnit- The unit to which to convert the numeric value.- Returns:
- The numeric value in the output unit.
- Throws:
ConversionException- The units aren't convertible.
-
convertTo
public float[] convertTo(float[] amounts, Unit outputUnit) throws ConversionExceptionConverts numeric values from this unit to another unit.- Specified by:
convertToin interfaceUnit- Parameters:
amounts- The numeric values.outputUnit- The unit to which to convert the numeric values.- Returns:
- The numeric values in the output unit in allocated space.
- Throws:
ConversionException- The units aren't convertible.
-
convertTo
public double[] convertTo(double[] amounts, Unit outputUnit) throws ConversionExceptionConverts numeric values from this unit to another unit.- Specified by:
convertToin interfaceUnit- Parameters:
amounts- The numeric values.outputUnit- The unit to which to convert the numeric values.- Returns:
- The numeric values in the output unit in allocated space.
- Throws:
ConversionException- The units aren't convertible.
-
convertTo
public float[] convertTo(float[] input, Unit outputUnit, float[] output) throws ConversionExceptionConverts numeric values from this unit to another unit.- Specified by:
convertToin interfaceUnit- Parameters:
input- The input numeric values.outputUnit- The unit to which to convert the numeric values.output- The output numeric values. May be the same array as the input values.- Returns:
- The numeric values in the output unit.
- Throws:
ConversionException- The units aren't convertible.
-
convertTo
public double[] convertTo(double[] input, Unit outputUnit, double[] output) throws ConversionExceptionConverts numeric values from this unit to another unit.- Specified by:
convertToin interfaceUnit- Parameters:
input- The input numeric values.outputUnit- The unit to which to convert the numeric values.output- The output numeric values. May be the same array as the input values.- Returns:
- The numeric values in the output unit.
- Throws:
ConversionException- The units aren't convertible.
-
isCompatible
public boolean isCompatible(Unit that)
Indicates if numeric values in this unit are convertible with another unit.- Specified by:
isCompatiblein interfaceUnit- Parameters:
that- The other unit.- Returns:
trueif and only if numeric values in this unit are convertible the other unit.
-
hashCode
public abstract int hashCode()
Returns the hash code of this instance.
-
toString
public String toString()
Returns the string representation of this unit.
-
-