Package org.openjdk.jmc.common.unit
Class CustomUnitSelector
java.lang.Object
org.openjdk.jmc.common.unit.CustomUnitSelector
- All Implemented Interfaces:
LinearKindOfQuantity.LinearUnitSelector
,TypedUnit.UnitSelector<LinearUnit>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final LinearKindOfQuantity.LinearUnitSelector
protected final LinearKindOfQuantity
protected final LinearKindOfQuantity.LinearUnitSelector
protected final ArrayList<ITypedQuantity<LinearUnit>>
protected final double[]
protected final LinearUnit[]
protected final double[]
-
Constructor Summary
ConstructorsConstructorDescriptionCustomUnitSelector
(LinearKindOfQuantity kindOfQuantity, LinearKindOfQuantity.LinearUnitSelector smallSelector, Collection<LinearUnit> units, LinearKindOfQuantity.LinearUnitSelector bigSelector, SortedSet<ITypedQuantity<LinearUnit>> ticks) -
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
-
unitMultiplierArr
protected final double[] unitMultiplierArr -
unitArr
-
tickMultiplierArr
protected final double[] tickMultiplierArr -
tickList
-
smallSelector
-
bigSelector
-
-
Constructor Details
-
CustomUnitSelector
public CustomUnitSelector(LinearKindOfQuantity kindOfQuantity, LinearKindOfQuantity.LinearUnitSelector smallSelector, Collection<LinearUnit> units, LinearKindOfQuantity.LinearUnitSelector bigSelector, SortedSet<ITypedQuantity<LinearUnit>> ticks)
-
-
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
-