Top Description Inners Fields Constructors Methods
com.ibm.icu.impl.units

public Class ComplexUnitsConverter

extends Object
Class Inheritance
Imports
java.math.BigDecimal, .BigInteger, .RoundingMode, java.util.ArrayList, .Collections, .List, com.ibm.icu.impl.number.DecimalQuantity, .DecimalQuantity_DualStorageBCD, com.ibm.icu.number.Precision, com.ibm.icu.util.Measure

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 and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
public static final BigDecimal
public static final BigDecimal
private MeasureUnitImpl
public List<MeasureUnitImpl.MeasureUnitImplWithIndex>
units_

Individual units of mixed units, sorted big to small, with indices indicating the requested output mixed unit order.

public ArrayList<UnitsConverter>

Constructor Summary

AccessConstructor and Description
public
ComplexUnitsConverter(MeasureUnitImpl
represents the input unit. could be any type. (single, compound or mixed).
targetUnit
,
ConversionRates conversionRates)

Constructs ComplexUnitsConverter for an inputUnit that could be Single, Compound or Mixed.

public
ComplexUnitsConverter(String
represents the source unit identifier. (should be single or compound unit).
inputUnitIdentifier
,
String
represents the output unit identifier. could be any type. (single, compound or mixed).
outputUnitsIdentifier
)

Constructs ComplexUnitsConverter NOTE: - inputUnit and outputUnits must be under the same category - e.g. meter to feet and inches --> all of them are length units.

public
ComplexUnitsConverter(MeasureUnitImpl
represents the source unit. (should be single or compound unit).
inputUnit
,
MeasureUnitImpl
represents the output unit. could be any type. (single, compound or mixed).
outputUnits
,
ConversionRates
a ConversionRates instance containing the unit conversion rates.
conversionRates
)

Constructs ComplexUnitsConverter NOTE: - inputUnit and outputUnits must be under the same category - e.g. meter to feet and inches --> all of them are length units.

Method Summary

Modifier and TypeMethod and Description
private BigDecimal

Returns:

the rounded quantity
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.

public ComplexUnitsConverter.ComplexConverterResult
convert(BigDecimal quantity, Precision rounder)

Returns outputMeasures which is an array with the corresponding values.

public boolean
greaterThanOrEqual(BigDecimal quantity, BigDecimal limit)

Returns true if the specified quantity of the inputUnit, expressed in terms of the biggest unit in the MeasureUnit outputUnit, is greater than or equal to limit.

private void
init(ConversionRates conversionRates)

Sorts units_, which must be populated before calling this, and populates unitsConverters_.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

EPSILONback to summary
public static final BigDecimal EPSILON
EPSILON_MULTIPLIERback to summary
public static final BigDecimal EPSILON_MULTIPLIER
inputUnit_back to summary
private MeasureUnitImpl inputUnit_
units_back to summary
public List<MeasureUnitImpl.MeasureUnitImplWithIndex> units_

Individual units of mixed units, sorted big to small, with indices indicating the requested output mixed unit order.

unitsConverters_back to summary
public ArrayList<UnitsConverter> unitsConverters_

Constructor Detail

ComplexUnitsConverterback to summary
public ComplexUnitsConverter(MeasureUnitImpl targetUnit, ConversionRates conversionRates)

Constructs ComplexUnitsConverter for an inputUnit 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:MeasureUnitImpl

represents the input unit. could be any type. (single, compound or mixed).

ComplexUnitsConverterback to summary
public ComplexUnitsConverter(String inputUnitIdentifier, String outputUnitsIdentifier)

Constructs ComplexUnitsConverter 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:String

represents the source unit identifier. (should be single or compound unit).

outputUnitsIdentifier:String

represents the output unit identifier. could be any type. (single, compound or mixed).

ComplexUnitsConverterback to summary
public ComplexUnitsConverter(MeasureUnitImpl inputUnit, MeasureUnitImpl outputUnits, ConversionRates conversionRates)

Constructs ComplexUnitsConverter 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:MeasureUnitImpl

represents the source unit. (should be single or compound unit).

outputUnits:MeasureUnitImpl

represents the output unit. could be any type. (single, compound or mixed).

conversionRates:ConversionRates

a ConversionRates instance containing the unit conversion rates.

Method Detail

applyRounderback to summary
private 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.

Returns:BigDecimal

the rounded quantity

convertback to summary
public ComplexUnitsConverter.ComplexConverterResult convert(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

greaterThanOrEqualback to summary
public boolean greaterThanOrEqual(BigDecimal quantity, BigDecimal limit)

Returns true if the specified quantity of the inputUnit, expressed in terms of the biggest unit in the MeasureUnit outputUnit, is greater than or equal to limit.

For example, if the input unit is meter and the target unit is foot+inch. Therefore, this function will convert the quantity from meter to foot, then, it will compare the value in foot with the limit.

initback to summary
private void init(ConversionRates conversionRates)

Sorts units_, which must be populated before calling this, and populates unitsConverters_.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
com.ibm.icu.impl.units back to summary

public Class ComplexUnitsConverter.ComplexConverterResult

extends Object
Class Inheritance
  • java.lang.Object
  • com.ibm.icu.impl.units.ComplexUnitsConverter.ComplexConverterResult

Field Summary

Modifier and TypeField and Description
public final int
public final List<Measure>

Constructor Summary

AccessConstructor and Description
pack-priv
ComplexConverterResult(int indexOfQuantity, List<Measure> measures)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

indexOfQuantityback to summary
public final int indexOfQuantity
measuresback to summary
public final List<Measure> measures

Constructor Detail

ComplexConverterResultback to summary
pack-priv ComplexConverterResult(int indexOfQuantity, List<Measure> measures)