public final class LinearUnit extends Unit
Modifier and Type | Method and Description |
---|---|
protected double |
convertFromBase(double value)
Converts from a value expressed in this unit's base unit to a value expressed in this unit.
|
protected double |
convertToBase(double value)
Converts from a value expressed in this unit to a value expressed in this unit's base unit.
|
LinearUnit |
dividedBy(double divisor)
Divides this unit by a scalar.
|
LinearUnit |
dividedBy(LinearUnit divisor)
Returns the quotient of this unit and another.
|
boolean |
equals(java.lang.Object obj)
Uses the base and conversion factor of units to test for equality.
|
static LinearUnit |
fromUnitValue(Unit unit,
double value)
Gets a
LinearUnit from a unit and a value. |
static LinearUnit |
fromUnitValue(Unit unit,
double value,
NameSymbol ns)
Gets a
LinearUnit from a unit and a value. |
double |
getConversionFactor() |
int |
hashCode()
Uses the base and conversion factor to compute a hash code.
|
boolean |
isBase() |
boolean |
isCoherent() |
LinearUnit |
minus(LinearUnit subtrahendend)
Returns the difference of this unit and another.
|
LinearUnit |
plus(LinearUnit addend)
Returns the sum of this unit and another.
|
LinearUnit |
times(double multiplier)
Multiplies this unit by a scalar.
|
LinearUnit |
times(LinearUnit multiplier)
Returns the product of this unit and another.
|
LinearUnit |
toExponent(int exponent)
Returns this unit but to an exponent.
|
java.lang.String |
toString() |
static LinearUnit |
valueOf(ObjectProduct<BaseUnit> unitBase,
double conversionFactor)
Gets a
LinearUnit from a unit base and a conversion factor. |
static LinearUnit |
valueOf(ObjectProduct<BaseUnit> unitBase,
double conversionFactor,
NameSymbol ns)
Gets a
LinearUnit from a unit base and a conversion factor. |
LinearUnit |
withName(NameSymbol ns) |
LinearUnit |
withPrefix(UnitPrefix prefix)
Returns the result of applying
prefix to this unit. |
canConvertTo, convertTo, fromConversionFunctions, fromConversionFunctions, getBase, getDimension, getOtherNames, getPrimaryName, getSymbol
public static LinearUnit fromUnitValue(Unit unit, double value)
LinearUnit
from a unit and a value. For example, converts '59 °F' to a linear unit with the value
of '288.15 K'unit
- unit to convertvalue
- value to convertLinearUnit
java.lang.NullPointerException
- if unit is nullpublic static LinearUnit fromUnitValue(Unit unit, double value, NameSymbol ns)
LinearUnit
from a unit and a value. For example, converts '59 °F' to a linear unit with the value
of '288.15 K'unit
- unit to convertvalue
- value to convertns
- name(s) and symbol of unitLinearUnit
java.lang.NullPointerException
- if unit or ns is nullpublic static LinearUnit valueOf(ObjectProduct<BaseUnit> unitBase, double conversionFactor)
LinearUnit
from a unit base and a conversion factor. In other words, gets the product of
unitBase
and conversionFactor
, expressed as a LinearUnit
.unitBase
- unit base to multiply byconversionFactor
- number to multiply base byjava.lang.NullPointerException
- if unitBase is nullpublic static LinearUnit valueOf(ObjectProduct<BaseUnit> unitBase, double conversionFactor, NameSymbol ns)
LinearUnit
from a unit base and a conversion factor. In other words, gets the product of
unitBase
and conversionFactor
, expressed as a LinearUnit
.unitBase
- unit base to multiply byconversionFactor
- number to multiply base byns
- name(s) and symbol of unitjava.lang.NullPointerException
- if unitBase is nullprotected double convertFromBase(double value)
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
.
conversionFactor
convertFromBase
in class Unit
value
- value expressed in base unitprotected double convertToBase(double value)
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
.
conversionFactor
convertToBase
in class Unit
value
- value expressed in this unitpublic LinearUnit dividedBy(double divisor)
divisor
- scalar to divide bypublic LinearUnit dividedBy(LinearUnit divisor)
divisor
- unit to divide byjava.lang.NullPointerException
- if divisor
is nullpublic boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public double getConversionFactor()
public int hashCode()
hashCode
in class java.lang.Object
public boolean isBase()
BaseUnit
(i.e. there is a BaseUnit b
where
b.asLinearUnit().equals(this)
returns true
.)public boolean isCoherent()
public LinearUnit minus(LinearUnit subtrahendend)
Two units can be subtracted if they have the same base. Note that Unit.canConvertTo(org.unitConverter.unit.Unit)
can be used to determine
this. If subtrahend
does not meet this condition, an IllegalArgumentException
will be thrown.
subtrahend
- unit to subtractjava.lang.IllegalArgumentException
- if subtrahend
is not compatible for subtraction as described abovejava.lang.NullPointerException
- if subtrahend
is nullpublic LinearUnit plus(LinearUnit addend)
Two units can be added if they have the same base. Note that Unit.canConvertTo(org.unitConverter.unit.Unit)
can be used to determine this.
If addend
does not meet this condition, an IllegalArgumentException
will be thrown.
addend
- unit to addjava.lang.IllegalArgumentException
- if addend
is not compatible for addition as described abovejava.lang.NullPointerException
- if addend
is nullpublic LinearUnit times(double multiplier)
multiplier
- scalar to multiply bypublic LinearUnit times(LinearUnit multiplier)
multiplier
- unit to multiply byjava.lang.NullPointerException
- if multiplier
is nullpublic LinearUnit toExponent(int exponent)
exponent
- exponent to exponentiate unit topublic java.lang.String toString()
public LinearUnit withName(NameSymbol ns)
public LinearUnit withPrefix(UnitPrefix prefix)
prefix
to this unit.
If this unit and the provided prefix have a primary name, the returned unit will have a primary name (prefix's
name + unit's name).
If this unit and the provided prefix have a symbol, the returned unit will have a symbol.
This method ignores alternate names of both this unit and the provided prefix.
prefix
- prefix to applyjava.lang.NullPointerException
- if prefix is null