Package org.openjdk.jmc.common.unit
Class BinaryUnitSelector
java.lang.Object
org.openjdk.jmc.common.unit.BinaryUnitSelector
- All Implemented Interfaces:
LinearKindOfQuantity.LinearUnitSelector
,TypedUnit.UnitSelector<LinearUnit>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final LinearKindOfQuantity
protected final Map<ScaleFactor,
LinearUnit> -
Constructor Summary
ConstructorsConstructorDescriptionBinaryUnitSelector
(LinearKindOfQuantity kindOfQuantity) BinaryUnitSelector
(LinearKindOfQuantity kindOfQuantity, Iterable<BinaryPrefix> prefixes) -
Method Summary
Modifier and TypeMethodDescriptiongetLargestExactUnit
(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
-
unitCache
-
-
Constructor Details
-
BinaryUnitSelector
-
BinaryUnitSelector
-
-
Method Details
-
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
-