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>
public class DecimalUnitSelector extends Object implements LinearKindOfQuantity.LinearUnitSelector
-
-
Field Summary
Fields Modifier and Type Field Description protected ScaleFactor
baseToAtomFactor
protected LinearUnit
exponentialBaseUnit
protected LinearKindOfQuantity
kindOfQuantity
protected Map<ScaleFactor,LinearUnit>
unitCache
-
Constructor Summary
Constructors Constructor Description DecimalUnitSelector(LinearKindOfQuantity kindOfQuantity)
DecimalUnitSelector(LinearKindOfQuantity kindOfQuantity, Iterable<DecimalPrefix> prefixes)
DecimalUnitSelector(LinearKindOfQuantity kindOfQuantity, LinearUnit exponentialBaseUnit)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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)
-
-
-
Field Detail
-
kindOfQuantity
protected final LinearKindOfQuantity kindOfQuantity
-
exponentialBaseUnit
protected final LinearUnit exponentialBaseUnit
-
baseToAtomFactor
protected final ScaleFactor baseToAtomFactor
-
unitCache
protected final Map<ScaleFactor,LinearUnit> unitCache
-
-
Constructor Detail
-
DecimalUnitSelector
public DecimalUnitSelector(LinearKindOfQuantity kindOfQuantity)
-
DecimalUnitSelector
public DecimalUnitSelector(LinearKindOfQuantity kindOfQuantity, LinearUnit exponentialBaseUnit)
-
DecimalUnitSelector
public DecimalUnitSelector(LinearKindOfQuantity kindOfQuantity, Iterable<DecimalPrefix> prefixes)
-
-
Method Detail
-
cachePlain
protected void cachePlain(int powerOf10, String unitId)
-
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
public LinearUnit getLargestExactUnit(ITypedQuantity<LinearUnit> quantity)
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
-
-