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>
public class BinaryUnitSelector extends Object implements LinearKindOfQuantity.LinearUnitSelector
 
- 
- 
Field Summary
Fields Modifier and Type Field Description protected LinearKindOfQuantitykindOfQuantityprotected Map<ScaleFactor,LinearUnit>unitCache 
- 
Constructor Summary
Constructors Constructor Description BinaryUnitSelector(LinearKindOfQuantity kindOfQuantity)BinaryUnitSelector(LinearKindOfQuantity kindOfQuantity, Iterable<BinaryPrefix> prefixes) 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LinearUnitgetLargestExactUnit(ITypedQuantity<LinearUnit> quantity)Get the largest unit, if any, in which this quantity can be expressed exactly, typically with an integer.LinearUnitgetPreferredUnit(ITypedQuantity<LinearUnit> quantity, double minNumericalValue, double maxNumericalValue)ITypedQuantity<LinearUnit>snapToBestBetweenHalfAndEqual(ITypedQuantity<LinearUnit> upperLimit) 
 - 
 
- 
- 
Field Detail
- 
kindOfQuantity
protected final LinearKindOfQuantity kindOfQuantity
 
- 
unitCache
protected final Map<ScaleFactor,LinearUnit> unitCache
 
 - 
 
- 
Constructor Detail
- 
BinaryUnitSelector
public BinaryUnitSelector(LinearKindOfQuantity kindOfQuantity)
 
- 
BinaryUnitSelector
public BinaryUnitSelector(LinearKindOfQuantity kindOfQuantity, Iterable<BinaryPrefix> prefixes)
 
 - 
 
- 
Method Detail
- 
getPreferredUnit
public LinearUnit getPreferredUnit(ITypedQuantity<LinearUnit> quantity, double minNumericalValue, double maxNumericalValue)
- Specified by:
 getPreferredUnitin interfaceTypedUnit.UnitSelector<LinearUnit>
 
- 
snapToBestBetweenHalfAndEqual
public ITypedQuantity<LinearUnit> snapToBestBetweenHalfAndEqual(ITypedQuantity<LinearUnit> upperLimit)
- Specified by:
 snapToBestBetweenHalfAndEqualin interfaceLinearKindOfQuantity.LinearUnitSelector
 
- 
getLargestExactUnit
public LinearUnit getLargestExactUnit(ITypedQuantity<LinearUnit> quantity)
Description copied from interface:TypedUnit.UnitSelectorGet 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:
 getLargestExactUnitin interfaceTypedUnit.UnitSelector<LinearUnit>- Returns:
 - a unit or 
null 
 
 - 
 
 -