public class LinearUnitConverter extends Object implements UnitConverter
value(ref) = value(specific) * factor + offset
Modifier and Type | Field and Description |
---|---|
private double |
factor |
private double |
offset |
Constructor and Description |
---|
LinearUnitConverter(double factor,
double offset)
Create a new unit converter.
|
LinearUnitConverter(double factor,
double offset,
double referenceFactor,
double referenceOffset)
Create a unit converter that converts between two units that
are both related to a third "common" unit by given factors and offsets.
|
LinearUnitConverter(Unit unit)
Create a new unit converter that converts to/from a
given unit.
|
LinearUnitConverter(Unit specific,
Unit reference)
Create a new unit converter that converts to/from
given specific and reference unit.
|
Modifier and Type | Method and Description |
---|---|
double |
convertToReferenceUnit(double specific)
value(ref) = value(specific) * factor + offset
|
double |
convertToSpecificUnit(double ref)
value(specific) = (value(ref) - offset) / factor
|
public LinearUnitConverter(double factor, double offset)
factor
- The factor to use when converting valuesoffset
- The offset to use when converting valuespublic LinearUnitConverter(double factor, double offset, double referenceFactor, double referenceOffset)
value(ref) * factor(ref) + offset(ref) ==
value(specific) * factor(specfic) + offset(specific)
which is equivalent to :
factor = factor(specific) / factor(ref) offset = (offset(specific) - offset(ref)) / factor(ref)
factor
- The factor of the specific unitoffset
- The offset of the specific unitreferenceFactor
- The factor of the reference unitreferenceOffset
- The offset of the specific unitpublic LinearUnitConverter(Unit unit)
Quantity.getReferenceUnit()
for the given specific
unit's quantity.unit
- The specific unitpublic double convertToReferenceUnit(double specific)
convertToReferenceUnit
in interface UnitConverter
specific
- The value to convertpublic double convertToSpecificUnit(double ref)
convertToSpecificUnit
in interface UnitConverter
ref
- The reference value