Package org.openjdk.jmc.common.unit
Class DecimalUnitSelector
java.lang.Object
org.openjdk.jmc.common.unit.DecimalUnitSelector
- All Implemented Interfaces:
LinearKindOfQuantity.LinearUnitSelector
,TypedUnit.UnitSelector<LinearUnit>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ScaleFactor
protected final LinearUnit
protected final LinearKindOfQuantity
protected final Map<ScaleFactor,
LinearUnit> -
Constructor Summary
ConstructorsConstructorDescriptionDecimalUnitSelector
(LinearKindOfQuantity kindOfQuantity) DecimalUnitSelector
(LinearKindOfQuantity kindOfQuantity, Iterable<DecimalPrefix> prefixes) DecimalUnitSelector
(LinearKindOfQuantity kindOfQuantity, LinearUnit exponentialBaseUnit) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
cachePlain
(int powerOf10, String unitId) getLargestExactUnit
(ITypedQuantity<LinearUnit> quantity) Get the largest unit, if any, in which this quantity can be expressed exactly, typically with an integer.getPreferredUnit
(ITypedQuantity<LinearUnit> quantity, double minNumericalValue, double maxNumericalValue) snapToBestBetweenHalfAndEqual
(ITypedQuantity<LinearUnit> upperLimit)
-
Field Details
-
kindOfQuantity
-
exponentialBaseUnit
-
baseToAtomFactor
-
unitCache
-
-
Constructor Details
-
DecimalUnitSelector
-
DecimalUnitSelector
-
DecimalUnitSelector
-
-
Method Details
-
cachePlain
-
getPreferredUnit
public LinearUnit getPreferredUnit(ITypedQuantity<LinearUnit> quantity, double minNumericalValue, double maxNumericalValue) - Specified by:
getPreferredUnit
in interfaceTypedUnit.UnitSelector<LinearUnit>
-
snapToBestBetweenHalfAndEqual
public ITypedQuantity<LinearUnit> snapToBestBetweenHalfAndEqual(ITypedQuantity<LinearUnit> upperLimit) - Specified by:
snapToBestBetweenHalfAndEqual
in interfaceLinearKindOfQuantity.LinearUnitSelector
-
getLargestExactUnit
Description copied from interface:TypedUnit.UnitSelector
Get the largest unit, if any, in which this quantity can be expressed exactly, typically with an integer. If the quantity has zero magnitude (
),IQuantity.doubleValue()
== 0.0quantity.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.
- Specified by:
getLargestExactUnit
in interfaceTypedUnit.UnitSelector<LinearUnit>
- Returns:
- a unit or
null
-