Search in sources :

Example 1 with ConvertVolumeUnit

use of io.atlasmap.v2.ConvertVolumeUnit in project atlasmap by atlasmap.

the class NumberFieldActionsTest method testConvertVolumeUnit.

@Test
public void testConvertVolumeUnit() {
    ConvertVolumeUnit action = new ConvertVolumeUnit();
    action.setFromUnit(VolumeUnitType.CUBIC_METER);
    action.setToUnit(VolumeUnitType.CUBIC_METER);
    assertEquals(1.0, NumberFieldActions.convertVolumeUnit(action, 1.0));
    action.setToUnit(VolumeUnitType.LITTER);
    assertEquals(2000.0, NumberFieldActions.convertVolumeUnit(action, 2.0));
    action.setToUnit(VolumeUnitType.CUBIC_FOOT);
    assertEquals(105.94400016446578, NumberFieldActions.convertVolumeUnit(action, 3.0));
    action.setToUnit(VolumeUnitType.GALLON_US_FLUID);
    assertEquals(1056.68820944, NumberFieldActions.convertVolumeUnit(action, 4.0));
    action.setFromUnit(VolumeUnitType.LITTER);
    action.setToUnit(VolumeUnitType.CUBIC_METER);
    assertEquals(5.0, NumberFieldActions.convertVolumeUnit(action, 5000.0));
    action.setToUnit(VolumeUnitType.LITTER);
    assertEquals(6.0, NumberFieldActions.convertVolumeUnit(action, 6.0));
    action.setToUnit(VolumeUnitType.CUBIC_FOOT);
    assertEquals(2.4720266705042016, NumberFieldActions.convertVolumeUnit(action, 70.0));
    action.setToUnit(VolumeUnitType.GALLON_US_FLUID);
    assertEquals(2.11337641888, NumberFieldActions.convertVolumeUnit(action, 8.0));
    action.setFromUnit(VolumeUnitType.CUBIC_FOOT);
    action.setToUnit(VolumeUnitType.CUBIC_METER);
    assertEquals(2.54851619328, NumberFieldActions.convertVolumeUnit(action, 90.0));
    action.setToUnit(VolumeUnitType.LITTER);
    assertEquals(28.316846591999997, NumberFieldActions.convertVolumeUnit(action, 1.0));
    action.setToUnit(VolumeUnitType.CUBIC_FOOT);
    assertEquals(2.0, NumberFieldActions.convertVolumeUnit(action, 2.0));
    action.setToUnit(VolumeUnitType.GALLON_US_FLUID);
    assertEquals(22.441558441715735, NumberFieldActions.convertVolumeUnit(action, 3.0));
    action.setFromUnit(VolumeUnitType.GALLON_US_FLUID);
    action.setToUnit(VolumeUnitType.CUBIC_METER);
    assertEquals(1.5141647135893872, NumberFieldActions.convertVolumeUnit(action, 400.0));
    action.setToUnit(VolumeUnitType.LITTER);
    assertEquals(18.92705891986734, NumberFieldActions.convertVolumeUnit(action, 5.0));
    action.setToUnit(VolumeUnitType.CUBIC_FOOT);
    assertEquals(8.020833333277116, NumberFieldActions.convertVolumeUnit(action, 60.0));
    action.setToUnit(VolumeUnitType.GALLON_US_FLUID);
    assertEquals(7.0, NumberFieldActions.convertVolumeUnit(action, 7.0));
}
Also used : ConvertVolumeUnit(io.atlasmap.v2.ConvertVolumeUnit) Test(org.junit.Test)

Example 2 with ConvertVolumeUnit

use of io.atlasmap.v2.ConvertVolumeUnit in project atlasmap by atlasmap.

the class NumberFieldActions method convertVolumeUnit.

@AtlasFieldActionInfo(name = "ConvertVolumeUnit", sourceType = FieldType.NUMBER, targetType = FieldType.NUMBER, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static Number convertVolumeUnit(Action action, Number input) {
    if (input == null) {
        return 0;
    }
    if (action == null || !(action instanceof ConvertVolumeUnit) || ((ConvertVolumeUnit) action).getFromUnit() == null || ((ConvertVolumeUnit) action).getToUnit() == null) {
        throw new IllegalArgumentException("ConvertVolumeUnit must be specfied  with fromUnit and toUnit");
    }
    VolumeUnitType fromUnit = ((ConvertVolumeUnit) action).getFromUnit();
    VolumeUnitType toUnit = ((ConvertVolumeUnit) action).getToUnit();
    double rate = volumeConvertionTable.get(fromUnit).get(toUnit);
    return doMultiply(input, rate);
}
Also used : ConvertVolumeUnit(io.atlasmap.v2.ConvertVolumeUnit) VolumeUnitType(io.atlasmap.v2.VolumeUnitType) AtlasFieldActionInfo(io.atlasmap.spi.AtlasFieldActionInfo)

Aggregations

ConvertVolumeUnit (io.atlasmap.v2.ConvertVolumeUnit)2 AtlasFieldActionInfo (io.atlasmap.spi.AtlasFieldActionInfo)1 VolumeUnitType (io.atlasmap.v2.VolumeUnitType)1 Test (org.junit.Test)1