public final class Unit extends Object
This class is immutable.
Constructor and Description |
---|
Unit(String name,
String symbol,
double a,
double b,
double c,
double d)
Create a new unit.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object object) |
double |
fromBase(double baseValue)
Convert the specified value given in base unit to this unit.
|
String |
getName()
Return name of this unit.
|
String |
getSymbol()
Return symbol of this unit.
|
int |
hashCode() |
double |
toBase(double value)
Convert the specified value to base unit in the quantity of this unit.
|
String |
toString() |
public Unit(String name, String symbol, double a, double b, double c, double d)
The conversion consists of four factors that are applied as follows when value is to be converted to base unit:
base = (a * value + b) / (c * value + d);For most conversion only a is needed. In these cases b, c and d should be set to 0.0, 0.0 and 1.0 respectively. For units like temperature a shift (b) is used as well, while c and d is in practice never used.
name
- Name of unit such as "meter". Non-null.symbol
- Symbol of unit such as "m". Non-null.a
- Conversion factor a for converting to base unit.b
- Conversion factor b for converting to base unit.c
- Conversion factor c for converting to base unit.d
- Conversion factor d for converting to base unit.IllegalArgumentException
- If name or symbol is null.public String getName()
public String getSymbol()
public double toBase(double value)
value
- Value to convert.public double fromBase(double baseValue)
baseValue
- Base value to convert.Copyright © 2020 Petroware AS - https://petroware.no