Package org.openjdk.jmc.common.unit
Interface TypedUnit.UnitSelector<U extends TypedUnit<U>>
-
- All Known Subinterfaces:
LinearKindOfQuantity.LinearUnitSelector
- All Known Implementing Classes:
BinaryUnitSelector
,CustomUnitSelector
,DecimalUnitSelector
public static interface TypedUnit.UnitSelector<U extends TypedUnit<U>>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description U
getLargestExactUnit(ITypedQuantity<U> quantity)
Get the largest unit, if any, in which this quantity can be expressed exactly, typically with an integer.U
getPreferredUnit(ITypedQuantity<U> quantity, double minNumericalValue, double maxNumericalValue)
-
-
-
Method Detail
-
getPreferredUnit
U getPreferredUnit(ITypedQuantity<U> quantity, double minNumericalValue, double maxNumericalValue)
-
getLargestExactUnit
U getLargestExactUnit(ITypedQuantity<U> quantity)
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.
- Returns:
- a unit or
null
-
-