Package com.ibm.icu.impl.units
Class ComplexUnitsConverter
java.lang.Object
com.ibm.icu.impl.units.ComplexUnitsConverter
Converts from single or compound unit to single, compound or mixed units. For example, from
meter
to foot+inch
.
DESIGN: This class uses UnitsConverter
in order to perform the single converter (i.e. converters from
a single unit to another single unit). Therefore, ComplexUnitsConverter
class contains multiple
instances of the UnitsConverter
to perform the conversion.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BigDecimal
static final BigDecimal
private MeasureUnitImpl
Individual units of mixed units, sorted big to small, with indices indicating the requested output mixed unit order. -
Constructor Summary
ConstructorsConstructorDescriptionComplexUnitsConverter
(MeasureUnitImpl targetUnit, ConversionRates conversionRates) ConstructsComplexUnitsConverter
for aninputUnit
that could be Single, Compound or Mixed.ComplexUnitsConverter
(MeasureUnitImpl inputUnit, MeasureUnitImpl outputUnits, ConversionRates conversionRates) ConstructsComplexUnitsConverter
NOTE: - inputUnit and outputUnits must be under the same category - e.g.ComplexUnitsConverter
(String inputUnitIdentifier, String outputUnitsIdentifier) ConstructsComplexUnitsConverter
NOTE: - inputUnit and outputUnits must be under the same category - e.g. -
Method Summary
Modifier and TypeMethodDescriptionprivate BigDecimal
applyRounder
(List<BigInteger> intValues, BigDecimal quantity, Precision rounder) Applies the rounder to the quantity (last element) and bubble up any carried value to all the intValues.convert
(BigDecimal quantity, Precision rounder) Returns outputMeasures which is an array with the corresponding values.boolean
greaterThanOrEqual
(BigDecimal quantity, BigDecimal limit) Returns true if the specifiedquantity
of theinputUnit
, expressed in terms of the biggest unit in the MeasureUnitoutputUnit
, is greater than or equal tolimit
.private void
init
(ConversionRates conversionRates) Sorts units_, which must be populated before calling this, and populates unitsConverters_.toString()
-
Field Details
-
EPSILON
-
EPSILON_MULTIPLIER
-
unitsConverters_
-
units_
Individual units of mixed units, sorted big to small, with indices indicating the requested output mixed unit order. -
inputUnit_
-
-
Constructor Details
-
ComplexUnitsConverter
ConstructsComplexUnitsConverter
for aninputUnit
that could be Single, Compound or Mixed. In case of: 1- Single and Compound units, the conversion will not perform anything, the input will be equal to the output. 2- Mixed Unit the conversion will consider the input in the biggest unit. and will convert it to be spread throw the input units. For example: if input unit is "inch-and-foot", and the input is 2.5. The converter will consider the input value in "foot", because foot is the biggest unit. Then, it will convert 2.5 feet to "inch-and-foot".- Parameters:
targetUnit
- represents the input unit. could be any type. (single, compound or mixed).
-
ComplexUnitsConverter
ConstructsComplexUnitsConverter
NOTE: - inputUnit and outputUnits must be under the same category - e.g. meter to feet and inches --> all of them are length units.- Parameters:
inputUnitIdentifier
- represents the source unit identifier. (should be single or compound unit).outputUnitsIdentifier
- represents the output unit identifier. could be any type. (single, compound or mixed).
-
ComplexUnitsConverter
public ComplexUnitsConverter(MeasureUnitImpl inputUnit, MeasureUnitImpl outputUnits, ConversionRates conversionRates) ConstructsComplexUnitsConverter
NOTE: - inputUnit and outputUnits must be under the same category - e.g. meter to feet and inches --> all of them are length units.- Parameters:
inputUnit
- represents the source unit. (should be single or compound unit).outputUnits
- represents the output unit. could be any type. (single, compound or mixed).conversionRates
- a ConversionRates instance containing the unit conversion rates.
-
-
Method Details
-
init
Sorts units_, which must be populated before calling this, and populates unitsConverters_. -
greaterThanOrEqual
Returns true if the specifiedquantity
of theinputUnit
, expressed in terms of the biggest unit in the MeasureUnitoutputUnit
, is greater than or equal tolimit
.For example, if the input unit is
meter
and the target unit isfoot+inch
. Therefore, this function will convert thequantity
frommeter
tofoot
, then, it will compare the value infoot
with thelimit
. -
convert
Returns outputMeasures which is an array with the corresponding values. - E.g. converting meters to feet and inches. 1 meter --> 3 feet, 3.3701 inches NOTE: the smallest element is the only element that could have fractional values. And all other elements are floored to the nearest integer -
applyRounder
Applies the rounder to the quantity (last element) and bubble up any carried value to all the intValues.- Returns:
- the rounded quantity
-
toString
-