Package ucar.units
Class DerivedUnitImpl
- java.lang.Object
-
- ucar.units.UnitImpl
-
- ucar.units.DerivedUnitImpl
-
- All Implemented Interfaces:
Serializable,DerivableUnit,DerivedUnit,Unit
- Direct Known Subclasses:
BaseUnit
public class DerivedUnitImpl extends UnitImpl implements DerivedUnit, DerivableUnit
Provides support for a concrete implementation of derived units.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ucar.units.UnitImpl
UnitImpl.MyConverter
-
-
Field Summary
Fields Modifier and Type Field Description static DerivedUnitImplDIMENSIONLESSThe dimensionless derived unit.
-
Constructor Summary
Constructors Modifier Constructor Description protectedDerivedUnitImpl()Constructs a dimensionless derived unit from nothing.protectedDerivedUnitImpl(UnitDimension dimension)Constructs from a unit dimension.protectedDerivedUnitImpl(UnitDimension dimension, UnitName id)Constructs from a unit dimension and identifiers.protectedDerivedUnitImpl(UnitName id)Constructs from identifiers.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Unitclone(UnitName id)Clones the derived unit changing the identifiers.booleanequals(Object object)Indicates if this derived unit is semantically identical to an object.doublefromDerivedUnit(double amount)Converts a numerical value to this unit from the derived unit.double[]fromDerivedUnit(double[] input, double[] output)Converts numerical values to this unit from the derived unit.floatfromDerivedUnit(float amount)Converts a numerical value to this unit from the derived unit.float[]fromDerivedUnit(float[] input, float[] output)Converts numerical values to this unit from the derived unit.StringgetCanonicalString()Returns the canonical string representation of the unit.DerivedUnitgetDerivedUnit()Returns the derived unit that is convertible with this unit.UnitDimensiongetDimension()Returns the unit dimension of this derived unit.QuantityDimensiongetQuantityDimension()Returns the quantity dimension of this derived unit.inthashCode()Returns the hash code of this instance.booleanisCompatible(Unit that)Indicates if values in this unit are convertible with another unit.booleanisDimensionless()Indicates if this derived unit is dimensionless.booleanisReciprocalOf(DerivedUnit that)Indicates if this derived unit is the reciprocal of another derived unit (e.g.protected UnitmyDivideBy(Unit that)Divides this derived unit by another.protected UnitmyDivideInto(Unit that)Divides this derived unit into another.protected UnitmyMultiplyBy(Unit that)Multiplies this derived unit by another.protected UnitmyRaiseTo(int power)Raises this derived unit to a power.protected voidsetDimension(UnitDimension dimension)Sets the unit dimension of this derived unit.doubletoDerivedUnit(double amount)Converts a numerical value from this unit to the derived unit.double[]toDerivedUnit(double[] input, double[] output)Converts numerical values from this unit to the derived unit.floattoDerivedUnit(float amount)Converts a numerical value from this unit to the derived unit.float[]toDerivedUnit(float[] input, float[] output)Converts numerical values from this unit to the derived unit.StringtoString()Returns a string representation of this unit.-
Methods inherited from class ucar.units.UnitImpl
convertTo, convertTo, convertTo, convertTo, convertTo, convertTo, divideBy, divideInto, getConverterTo, getName, getPlural, getSymbol, getUnitName, log, makeLabel, multiplyBy, multiplyBy, raiseTo, shiftTo, shiftTo
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ucar.units.Unit
convertTo, convertTo, convertTo, convertTo, convertTo, convertTo, divideBy, divideInto, getConverterTo, getName, getPlural, getSymbol, getUnitName, log, makeLabel, multiplyBy, multiplyBy, raiseTo, shiftTo, shiftTo
-
-
-
-
Field Detail
-
DIMENSIONLESS
public static final DerivedUnitImpl DIMENSIONLESS
The dimensionless derived unit.
-
-
Constructor Detail
-
DerivedUnitImpl
protected DerivedUnitImpl()
Constructs a dimensionless derived unit from nothing.
-
DerivedUnitImpl
protected DerivedUnitImpl(UnitDimension dimension)
Constructs from a unit dimension. This is a trusted constructor for use by subclasses only.- Parameters:
dimension- The unit dimension.
-
DerivedUnitImpl
protected DerivedUnitImpl(UnitName id)
Constructs from identifiers. This is a trusted constructor for use by subclasses only.- Parameters:
id- The identifiers for the unit.
-
DerivedUnitImpl
protected DerivedUnitImpl(UnitDimension dimension, UnitName id)
Constructs from a unit dimension and identifiers. This is a trusted constructor for use by subclasses only.- Parameters:
dimension- The unit dimension.id- The identifiers for the unit.
-
-
Method Detail
-
setDimension
protected void setDimension(UnitDimension dimension)
Sets the unit dimension of this derived unit. This is a trusted method for use by subclasses only and should be called only once immediately after construction of this superinstance.- Parameters:
dimension- The unit dimension.
-
getDimension
public final UnitDimension getDimension()
Returns the unit dimension of this derived unit.- Specified by:
getDimensionin interfaceDerivedUnit- Returns:
- The unit dimension of this derived unit.
-
getQuantityDimension
public final QuantityDimension getQuantityDimension()
Returns the quantity dimension of this derived unit.- Specified by:
getQuantityDimensionin interfaceDerivedUnit- Returns:
- The quantity dimension of this derived unit.
-
isReciprocalOf
public final boolean isReciprocalOf(DerivedUnit that)
Indicates if this derived unit is the reciprocal of another derived unit (e.g. "second" and "hertz").- Specified by:
isReciprocalOfin interfaceDerivedUnit- Parameters:
that- The other, derived unit.
-
getDerivedUnit
public final DerivedUnit getDerivedUnit()
Returns the derived unit that is convertible with this unit. Obviously, the method returns this derived unit.- Specified by:
getDerivedUnitin interfaceDerivableUnit- Specified by:
getDerivedUnitin interfaceUnit- Returns:
this.
-
myMultiplyBy
protected Unit myMultiplyBy(Unit that) throws MultiplyException
Multiplies this derived unit by another.- Specified by:
myMultiplyByin classUnitImpl- Parameters:
that- The other unit.- Returns:
- The product of the two units.
- Throws:
MultiplyException- Can't multiply these units.
-
myDivideBy
protected Unit myDivideBy(Unit that) throws OperationException
Divides this derived unit by another.- Specified by:
myDivideByin classUnitImpl- Parameters:
that- The other unit.- Returns:
- The quotient of the two units.
- Throws:
OperationException- Can't divide these units.
-
myDivideInto
protected Unit myDivideInto(Unit that) throws OperationException
Divides this derived unit into another.- Specified by:
myDivideIntoin classUnitImpl- Parameters:
that- The other unit.- Returns:
- The quotient of the two units.
- Throws:
OperationException- Can't divide these units.
-
myRaiseTo
protected Unit myRaiseTo(int power)
Raises this derived unit to a power.
-
toDerivedUnit
public final float toDerivedUnit(float amount)
Converts a numerical value from this unit to the derived unit. Obviously, the numerical value is unchanged.- Specified by:
toDerivedUnitin interfaceDerivableUnit- Parameters:
amount- The numerical values in this unit.- Returns:
- The numerical value in the derived unit.
-
toDerivedUnit
public final double toDerivedUnit(double amount)
Converts a numerical value from this unit to the derived unit. Obviously, the numerical value is unchanged.- Specified by:
toDerivedUnitin interfaceDerivableUnit- Parameters:
amount- The numerical values in this unit.- Returns:
- The numerical value in the derived unit.
-
toDerivedUnit
public final float[] toDerivedUnit(float[] input, float[] output)Converts numerical values from this unit to the derived unit. Obviously, the numerical values are unchanged.- Specified by:
toDerivedUnitin interfaceDerivableUnit- Parameters:
input- The numerical values in this unit.output- The numerical values in the derived unit. May be the same array asinput.- Returns:
output.
-
toDerivedUnit
public final double[] toDerivedUnit(double[] input, double[] output)Converts numerical values from this unit to the derived unit. Obviously, the numerical values are unchanged.- Specified by:
toDerivedUnitin interfaceDerivableUnit- Parameters:
input- The numerical values in this unit.output- The numerical values in the derived unit. May be the same array asinput.- Returns:
output.
-
fromDerivedUnit
public final float fromDerivedUnit(float amount)
Converts a numerical value to this unit from the derived unit. Obviously, the numerical value is unchanged.- Specified by:
fromDerivedUnitin interfaceDerivableUnit- Parameters:
amount- The numerical values in the derived unit.- Returns:
- The numerical value in this unit.
-
fromDerivedUnit
public final double fromDerivedUnit(double amount)
Converts a numerical value to this unit from the derived unit. Obviously, the numerical value is unchanged.- Specified by:
fromDerivedUnitin interfaceDerivableUnit- Parameters:
amount- The numerical values in the derived unit.- Returns:
- The numerical value in this unit.
-
fromDerivedUnit
public final float[] fromDerivedUnit(float[] input, float[] output)Converts numerical values to this unit from the derived unit. Obviously, the numerical values are unchanged.- Specified by:
fromDerivedUnitin interfaceDerivableUnit- Parameters:
input- The numerical values in the derived unit.output- The numerical values in this unit. May be the same array asinput.- Returns:
output.
-
fromDerivedUnit
public final double[] fromDerivedUnit(double[] input, double[] output)Converts numerical values to this unit from the derived unit. Obviously, the numerical values are unchanged.- Specified by:
fromDerivedUnitin interfaceDerivableUnit- Parameters:
input- The numerical values in the derived unit.output- The numerical values in this unit. May be the same array asinput.- Returns:
output.
-
isCompatible
public final boolean isCompatible(Unit that)
Indicates if values in this unit are convertible with another unit.- Specified by:
isCompatiblein interfaceUnit- Overrides:
isCompatiblein classUnitImpl- Parameters:
that- The other unit.- Returns:
trueif and only if values in this unit are convertible to values inthat.
-
equals
public boolean equals(Object object)
Indicates if this derived 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 derived unit is dimensionless.- Specified by:
isDimensionlessin interfaceUnit- Returns:
trueif and only if this derived unit is dimensionless.
-
toString
public String toString()
Returns a string representation of this unit. If the symbol or name is available, then that is returned; otherwise, the corresponding expression in base units is returned.
-
getCanonicalString
public String getCanonicalString()
Returns the canonical string representation of the unit.- Specified by:
getCanonicalStringin interfaceUnit- Returns:
- The canonical string representation.
-
-