public class BinaryUnitSelector extends Object implements LinearKindOfQuantity.LinearUnitSelector
Modifier and Type | Field and Description |
---|---|
protected LinearKindOfQuantity |
kindOfQuantity |
protected Map<ScaleFactor,LinearUnit> |
unitCache |
Constructor and Description |
---|
BinaryUnitSelector(LinearKindOfQuantity kindOfQuantity) |
BinaryUnitSelector(LinearKindOfQuantity kindOfQuantity,
Iterable<BinaryPrefix> prefixes) |
Modifier and Type | Method and Description |
---|---|
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 Map<ScaleFactor,LinearUnit> unitCache
public BinaryUnitSelector(LinearKindOfQuantity kindOfQuantity)
public BinaryUnitSelector(LinearKindOfQuantity kindOfQuantity, Iterable<BinaryPrefix> prefixes)
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.