public class DecimalUnitSelector extends Object implements LinearKindOfQuantity.LinearUnitSelector
Modifier and Type | Field and Description |
---|---|
protected ScaleFactor |
baseToAtomFactor |
protected LinearUnit |
exponentialBaseUnit |
protected LinearKindOfQuantity |
kindOfQuantity |
protected Map<ScaleFactor,LinearUnit> |
unitCache |
Constructor and Description |
---|
DecimalUnitSelector(LinearKindOfQuantity kindOfQuantity) |
DecimalUnitSelector(LinearKindOfQuantity kindOfQuantity,
Iterable<DecimalPrefix> prefixes) |
DecimalUnitSelector(LinearKindOfQuantity kindOfQuantity,
LinearUnit exponentialBaseUnit) |
Modifier and Type | Method and Description |
---|---|
protected void |
cachePlain(int powerOf10,
String unitId) |
LinearUnit |
getLargestExactUnit(ITypedQuantity<LinearUnit> quantity)
Get the largest unit, if any, in which this quantity can be expressed exactly, typically
with an integer.
|
LinearUnit |
getPreferredUnit(ITypedQuantity<LinearUnit> quantity,
double minNumericalValue,
double maxNumericalValue) |
ITypedQuantity<LinearUnit> |
snapToBestBetweenHalfAndEqual(ITypedQuantity<LinearUnit> upperLimit) |
protected final LinearKindOfQuantity kindOfQuantity
protected final LinearUnit exponentialBaseUnit
protected final ScaleFactor baseToAtomFactor
protected final Map<ScaleFactor,LinearUnit> unitCache
public DecimalUnitSelector(LinearKindOfQuantity kindOfQuantity)
public DecimalUnitSelector(LinearKindOfQuantity kindOfQuantity, LinearUnit exponentialBaseUnit)
public DecimalUnitSelector(LinearKindOfQuantity kindOfQuantity, Iterable<DecimalPrefix> prefixes)
protected void cachePlain(int powerOf10, String unitId)
public LinearUnit getPreferredUnit(ITypedQuantity<LinearUnit> quantity, double minNumericalValue, double maxNumericalValue)
getPreferredUnit
in interface TypedUnit.UnitSelector<LinearUnit>
public ITypedQuantity<LinearUnit> snapToBestBetweenHalfAndEqual(ITypedQuantity<LinearUnit> upperLimit)
snapToBestBetweenHalfAndEqual
in interface LinearKindOfQuantity.LinearUnitSelector
public LinearUnit getLargestExactUnit(ITypedQuantity<LinearUnit> quantity)
TypedUnit.UnitSelector
IQuantity.doubleValue()
== 0.0
), quantity.getUnit()
will be returned. Thus, if you want to find out a maximum common unit
for a set of quantities (not recommended), only use the non-zero quantities.
Note that this may be a fairly expensive operation, and isn't intended to be used excessively. The only valid use case is for guessing the original unit in which a quantity was expressed, after it has been stored or transmitted using a legacy mechanism with a fixed unit.
getLargestExactUnit
in interface TypedUnit.UnitSelector<LinearUnit>
null
Copyright © 2020. All rights reserved.