Package com.ibm.icu.impl.units
Class ComplexUnitsConverter
- java.lang.Object
-
- com.ibm.icu.impl.units.ComplexUnitsConverter
-
public class ComplexUnitsConverter extends java.lang.Object
Converts from single or compound unit to single, compound or mixed units. For example, frommeter
tofoot+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 theUnitsConverter
to perform the conversion.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ComplexUnitsConverter.ComplexConverterResult
-
Field Summary
Fields Modifier and Type Field Description static java.math.BigDecimal
EPSILON
static java.math.BigDecimal
EPSILON_MULTIPLIER
private MeasureUnitImpl
inputUnit_
java.util.List<MeasureUnitImpl.MeasureUnitImplWithIndex>
units_
Individual units of mixed units, sorted big to small, with indices indicating the requested output mixed unit order.java.util.ArrayList<UnitsConverter>
unitsConverters_
-
Constructor Summary
Constructors Constructor Description ComplexUnitsConverter(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(java.lang.String inputUnitIdentifier, java.lang.String outputUnitsIdentifier)
ConstructsComplexUnitsConverter
NOTE: - inputUnit and outputUnits must be under the same category - e.g.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.math.BigDecimal
applyRounder(java.util.List<java.math.BigInteger> intValues, java.math.BigDecimal quantity, Precision rounder)
Applies the rounder to the quantity (last element) and bubble up any carried value to all the intValues.ComplexUnitsConverter.ComplexConverterResult
convert(java.math.BigDecimal quantity, Precision rounder)
Returns outputMeasures which is an array with the corresponding values.boolean
greaterThanOrEqual(java.math.BigDecimal quantity, java.math.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_.java.lang.String
toString()
-
-
-
Field Detail
-
EPSILON
public static final java.math.BigDecimal EPSILON
-
EPSILON_MULTIPLIER
public static final java.math.BigDecimal EPSILON_MULTIPLIER
-
unitsConverters_
public java.util.ArrayList<UnitsConverter> unitsConverters_
-
units_
public java.util.List<MeasureUnitImpl.MeasureUnitImplWithIndex> units_
Individual units of mixed units, sorted big to small, with indices indicating the requested output mixed unit order.
-
inputUnit_
private MeasureUnitImpl inputUnit_
-
-
Constructor Detail
-
ComplexUnitsConverter
public ComplexUnitsConverter(MeasureUnitImpl targetUnit, ConversionRates conversionRates)
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
public ComplexUnitsConverter(java.lang.String inputUnitIdentifier, java.lang.String outputUnitsIdentifier)
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 Detail
-
init
private void init(ConversionRates conversionRates)
Sorts units_, which must be populated before calling this, and populates unitsConverters_.
-
greaterThanOrEqual
public boolean greaterThanOrEqual(java.math.BigDecimal quantity, java.math.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
.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
public ComplexUnitsConverter.ComplexConverterResult convert(java.math.BigDecimal quantity, Precision rounder)
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
private java.math.BigDecimal applyRounder(java.util.List<java.math.BigInteger> intValues, java.math.BigDecimal quantity, Precision rounder)
Applies the rounder to the quantity (last element) and bubble up any carried value to all the intValues.- Returns:
- the rounded quantity
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-