public final class BaseUnit extends Unit
Note that BaseUnits must have names and symbols. This is because they are used for toString code. Therefore,
the Optionals provided by Unit.getPrimaryName()
and Unit.getSymbol()
will always contain a value.
Modifier and Type | Method and Description |
---|---|
LinearUnit |
asLinearUnit()
Returns a
LinearUnit with this unit as a base and a conversion factor of 1. |
double |
convertFromBase(double value)
Converts from a value expressed in this unit's base unit to a value expressed in this unit.
|
double |
convertToBase(double value)
Converts from a value expressed in this unit to a value expressed in this unit's base unit.
|
BaseDimension |
getBaseDimension() |
java.lang.String |
toString() |
static BaseUnit |
valueOf(BaseDimension dimension,
java.lang.String name,
java.lang.String symbol)
Gets a base unit from the dimension it measures, its name and its symbol.
|
static BaseUnit |
valueOf(BaseDimension dimension,
java.lang.String name,
java.lang.String symbol,
java.util.Set<java.lang.String> otherNames)
Gets a base unit from the dimension it measures, its name and its symbol.
|
BaseUnit |
withName(NameSymbol ns) |
canConvertTo, convertTo, fromConversionFunctions, fromConversionFunctions, getBase, getDimension, getOtherNames, getPrimaryName, getSymbol
public static BaseUnit valueOf(BaseDimension dimension, java.lang.String name, java.lang.String symbol)
dimension
- dimension measured by this unitname
- name of unitsymbol
- symbol of unitpublic static BaseUnit valueOf(BaseDimension dimension, java.lang.String name, java.lang.String symbol, java.util.Set<java.lang.String> otherNames)
dimension
- dimension measured by this unitname
- name of unitsymbol
- symbol of unitpublic LinearUnit asLinearUnit()
LinearUnit
with this unit as a base and a conversion factor of 1. This operation must be done
in order to allow units to be created with operations.LinearUnit
public double convertFromBase(double value)
Unit
This must be the inverse of convertToBase
, so convertFromBase(convertToBase(value))
must be equal
to value
for any value, ignoring precision loss by roundoff error.
If this unit is a base unit, this method should return value
.
convertFromBase
in class Unit
value
- value expressed in base unitpublic double convertToBase(double value)
Unit
This must be the inverse of convertFromBase
, so convertToBase(convertFromBase(value))
must be
equal to value
for any value, ignoring precision loss by roundoff error.
If this unit is a base unit, this method should return value
.
convertToBase
in class Unit
value
- value expressed in this unitpublic final BaseDimension getBaseDimension()
public BaseUnit withName(NameSymbol ns)