Package ucar.units
Interface Unit
-
- All Known Subinterfaces:
DerivedUnit
- All Known Implementing Classes:
BaseUnit,DerivedUnitImpl,LogarithmicUnit,OffsetUnit,ScaledUnit,TimeScaleUnit,UnitImpl,UnknownUnit
public interface UnitInterface for units.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Unitclone(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.doubleconvertTo(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.floatconvertTo(float amount, Unit outputUnit)Converts a numerical value from this unit to another unit.UnitdivideBy(Unit that)Divides this unit by another.UnitdivideInto(Unit that)Divides this unit into another.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)Gets a Converter that converts numeric values from this unit to another, compatible unit.DerivedUnitgetDerivedUnit()Returns the derived unit that underlies this unit.StringgetName()Gets the name of this unit.StringgetPlural()Gets the plural form of the name of this unit.StringgetSymbol()Gets the symbol of this unit.UnitNamegetUnitName()Gets the identifier of this unit.booleanisCompatible(Unit that)Indicates if this unit is compatible with another unit.booleanisDimensionless()Indicates if values in this unit are dimensionless.Unitlog(double base)Returns a logarithmic unit whose reference level is equal to this unit.StringmakeLabel(String quantityID)Makes a label for a named quantity.UnitmultiplyBy(double scale)Multiplies this unit by a scale factor.UnitmultiplyBy(Unit that)Multiplies this unit by another.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 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.
-
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, ifmis a meter unit, thenm.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- ifscaleis 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, ifdegKis a Kelvin unit, thendegK.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
originof 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, 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).- 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, ifmWis a milliwatt unit, thenmW.log(10.)returns a base-ten logarithmic unit with a milliwatt reference level.- Parameters:
base- The logarithmic base. Must be one of2,Math.E, or10.- Throws:
IllegalArgumentException- ifbaseisn'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 ConversionExceptionConverts 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 ConversionExceptionConverts 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 ConversionExceptionConverts 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 ConversionExceptionConverts 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 ConversionExceptionConverts 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 ConversionExceptionConverts 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.
-
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:
trueif and only if this unit is dimensionless.
-
-