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 DerivedUnitImpl
DIMENSIONLESS
The dimensionless derived unit.
-
Constructor Summary
Constructors Modifier Constructor Description protected
DerivedUnitImpl()
Constructs a dimensionless derived unit from nothing.protected
DerivedUnitImpl(UnitDimension dimension)
Constructs from a unit dimension.protected
DerivedUnitImpl(UnitDimension dimension, UnitName id)
Constructs from a unit dimension and identifiers.protected
DerivedUnitImpl(UnitName id)
Constructs from identifiers.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Unit
clone(UnitName id)
Clones the derived unit changing the identifiers.boolean
equals(Object object)
Indicates if this derived unit is semantically identical to an object.double
fromDerivedUnit(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.float
fromDerivedUnit(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.String
getCanonicalString()
Returns the canonical string representation of the unit.DerivedUnit
getDerivedUnit()
Returns the derived unit that is convertible with this unit.UnitDimension
getDimension()
Returns the unit dimension of this derived unit.QuantityDimension
getQuantityDimension()
Returns the quantity dimension of this derived unit.int
hashCode()
Returns the hash code of this instance.boolean
isCompatible(Unit that)
Indicates if values in this unit are convertible with another unit.boolean
isDimensionless()
Indicates if this derived unit is dimensionless.boolean
isReciprocalOf(DerivedUnit that)
Indicates if this derived unit is the reciprocal of another derived unit (e.g.protected Unit
myDivideBy(Unit that)
Divides this derived unit by another.protected Unit
myDivideInto(Unit that)
Divides this derived unit into another.protected Unit
myMultiplyBy(Unit that)
Multiplies this derived unit by another.protected Unit
myRaiseTo(int power)
Raises this derived unit to a power.protected void
setDimension(UnitDimension dimension)
Sets the unit dimension of this derived unit.double
toDerivedUnit(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.float
toDerivedUnit(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.String
toString()
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:
getDimension
in interfaceDerivedUnit
- Returns:
- The unit dimension of this derived unit.
-
getQuantityDimension
public final QuantityDimension getQuantityDimension()
Returns the quantity dimension of this derived unit.- Specified by:
getQuantityDimension
in 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:
isReciprocalOf
in 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:
getDerivedUnit
in interfaceDerivableUnit
- Specified by:
getDerivedUnit
in interfaceUnit
- Returns:
this
.
-
myMultiplyBy
protected Unit myMultiplyBy(Unit that) throws MultiplyException
Multiplies this derived unit by another.- Specified by:
myMultiplyBy
in 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:
myDivideBy
in 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:
myDivideInto
in 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:
toDerivedUnit
in 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:
toDerivedUnit
in 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:
toDerivedUnit
in 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:
toDerivedUnit
in 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:
fromDerivedUnit
in 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:
fromDerivedUnit
in 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:
fromDerivedUnit
in 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:
fromDerivedUnit
in 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:
isCompatible
in interfaceUnit
- Overrides:
isCompatible
in classUnitImpl
- Parameters:
that
- The other unit.- Returns:
true
if 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:
isDimensionless
in interfaceUnit
- Returns:
true
if 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:
getCanonicalString
in interfaceUnit
- Returns:
- The canonical string representation.
-
-