public class ComplexUnitsConverter extends Object
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.
| Modifier and Type | Class and Description |
|---|---|
static class |
ComplexUnitsConverter.ComplexConverterResult |
| Modifier and Type | Field and Description |
|---|---|
static BigDecimal |
EPSILON |
static BigDecimal |
EPSILON_MULTIPLIER |
List<MeasureUnitImpl.MeasureUnitImplWithIndex> |
units_
Individual units of mixed units, sorted big to small, with indices
indicating the requested output mixed unit order.
|
ArrayList<UnitsConverter> |
unitsConverters_ |
| Constructor and Description |
|---|
ComplexUnitsConverter(MeasureUnitImpl targetUnit,
ConversionRates conversionRates)
Constructs
ComplexUnitsConverter for an inputUnit that could be Single, Compound or
Mixed. |
ComplexUnitsConverter(MeasureUnitImpl inputUnit,
MeasureUnitImpl outputUnits,
ConversionRates conversionRates)
Constructs
ComplexUnitsConverter NOTE: - inputUnit and outputUnits must be under the same category -
e.g. |
ComplexUnitsConverter(String inputUnitIdentifier,
String outputUnitsIdentifier)
Constructs
ComplexUnitsConverter NOTE: - inputUnit and outputUnits must be under the same category -
e.g. |
| Modifier and Type | Method and Description |
|---|---|
ComplexUnitsConverter.ComplexConverterResult |
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 specified
quantity of the inputUnit, expressed in terms of the biggest
unit in the MeasureUnit outputUnit, is greater than or equal to limit. |
String |
toString() |
public static final BigDecimal EPSILON
public static final BigDecimal EPSILON_MULTIPLIER
public ArrayList<UnitsConverter> unitsConverters_
public List<MeasureUnitImpl.MeasureUnitImplWithIndex> units_
public ComplexUnitsConverter(MeasureUnitImpl targetUnit, ConversionRates conversionRates)
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".targetUnit - represents the input unit. could be any type. (single, compound or mixed).public ComplexUnitsConverter(String inputUnitIdentifier, String outputUnitsIdentifier)
ComplexUnitsConverter NOTE: - inputUnit and outputUnits must be under the same category -
e.g. meter to feet and inches --> all of them are length units.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).public ComplexUnitsConverter(MeasureUnitImpl inputUnit, MeasureUnitImpl outputUnits, ConversionRates conversionRates)
ComplexUnitsConverter NOTE: - inputUnit and outputUnits must be under the same category -
e.g. meter to feet and inches --> all of them are length units.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.public boolean greaterThanOrEqual(BigDecimal quantity, BigDecimal limit)
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.
public ComplexUnitsConverter.ComplexConverterResult convert(BigDecimal quantity, Precision rounder)