2.17.2: 2011-06-17

## net.sf.basedb.util.units Class LinearUnitConverter

```java.lang.Object
net.sf.basedb.util.units.LinearUnitConverter
```
All Implemented Interfaces:
UnitConverter

`public class LinearUnitConverterextends Objectimplements UnitConverter`

A linear unit converter is a converter implementation were all units can be converted to another unit using a multiplication factor and/or an offset. The formula used in this converter is:

`value(ref) = value(specific) * factor + offset`

Version:
2.9
Author:
Nicklas
\$Date\$

Field Summary
`private  double` `factor`

`private  double` `offset`

Constructor Summary
```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.

Method Summary
` double` `convertToReferenceUnit(double specific)`
value(ref) = value(specific) * factor + offset
` double` `convertToSpecificUnit(double ref)`
value(specific) = (value(ref) - offset) / factor

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### factor

`private final double factor`

### offset

`private final double offset`
Constructor Detail

### LinearUnitConverter

```public LinearUnitConverter(double factor,
double offset)```
Create a new unit converter.

Parameters:
`factor` - The factor to use when converting values
`offset` - The offset to use when converting values

### LinearUnitConverter

```public 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. The formula used is: ```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)
```

Parameters:
`factor` - The factor of the specific unit
`offset` - The offset of the specific unit
`referenceFactor` - The factor of the reference unit
`referenceOffset` - The offset of the specific unit

### LinearUnitConverter

`public LinearUnitConverter(Unit unit)`
Create a new unit converter that converts to/from a given unit. The reference unit is the unit given by `Quantity.getReferenceUnit()` for the given specific unit's quantity.

Parameters:
`unit` - The specific unit

### LinearUnitConverter

```public LinearUnitConverter(Unit specific,
Unit reference)```
Create a new unit converter that converts to/from given specific and reference unit.

Parameters:
`specific` - The specific unit
`reference` - The reference unit
Method Detail

### convertToReferenceUnit

`public double convertToReferenceUnit(double specific)`
value(ref) = value(specific) * factor + offset

Specified by:
`convertToReferenceUnit` in interface `UnitConverter`
Parameters:
`specific` - The value to convert
Returns:
The converted value

### convertToSpecificUnit

`public double convertToSpecificUnit(double ref)`
value(specific) = (value(ref) - offset) / factor

Specified by:
`convertToSpecificUnit` in interface `UnitConverter`
Parameters:
`ref` - The reference value
Returns:
The converted value

2.17.2: 2011-06-17