Search in sources :

Example 1 with ConvertAreaUnit

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

the class NumberFieldActionsTest method testConvertAreaUnitIllegalArgumentException.

@Test
public void testConvertAreaUnitIllegalArgumentException() {
    assertThrows(IllegalArgumentException.class, () -> {
        assertEquals(0, NumberFieldActions.convertAreaUnit(new ConvertAreaUnit(), null).intValue());
        NumberFieldActions.convertAreaUnit(new ConvertAreaUnit(), 5);
    });
}
Also used : ConvertAreaUnit(io.atlasmap.v2.ConvertAreaUnit) Test(org.junit.jupiter.api.Test)

Example 2 with ConvertAreaUnit

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

the class NumberFieldActions method convertAreaUnit.

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

Example 3 with ConvertAreaUnit

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

the class NumberFieldActions method convertAreaUnit.

/**
 * Converts area unit.
 * @param convertAreaUnit action model
 * @param input source
 * @return converted
 */
@AtlasActionProcessor
public static Number convertAreaUnit(ConvertAreaUnit convertAreaUnit, Number input) {
    if (input == null) {
        return 0;
    }
    if (convertAreaUnit == null || convertAreaUnit.getFromUnit() == null || convertAreaUnit.getToUnit() == null) {
        throw new IllegalArgumentException("ConvertAreaUnit must be specified  with fromUnit and toUnit");
    }
    AreaUnitType fromUnit = convertAreaUnit.getFromUnit();
    AreaUnitType toUnit = convertAreaUnit.getToUnit();
    double rate = areaConvertionTable.get(fromUnit).get(toUnit);
    return doMultiply(input, rate);
}
Also used : AreaUnitType(io.atlasmap.v2.AreaUnitType) AtlasActionProcessor(io.atlasmap.spi.AtlasActionProcessor)

Example 4 with ConvertAreaUnit

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

the class NumberFieldActionsTest method testConvertAreaUnit.

@Test
public void testConvertAreaUnit() {
    ConvertAreaUnit action = new ConvertAreaUnit();
    action.setFromUnit(AreaUnitType.SQUARE_METER);
    action.setToUnit(AreaUnitType.SQUARE_METER);
    assertEquals(1.0, NumberFieldActions.convertAreaUnit(action, 1.0));
    action.setToUnit(AreaUnitType.SQUARE_FOOT);
    assertEquals(21.527820833419447, NumberFieldActions.convertAreaUnit(action, 2.0));
    action.setToUnit(AreaUnitType.SQUARE_MILE);
    assertEquals(1.1583064756273378, NumberFieldActions.convertAreaUnit(action, 3000000.0));
    action.setFromUnit(AreaUnitType.SQUARE_FOOT);
    action.setToUnit(AreaUnitType.SQUARE_METER);
    assertEquals(3.7161215999999997, NumberFieldActions.convertAreaUnit(action, 40.0));
    action.setToUnit(AreaUnitType.SQUARE_FOOT);
    assertEquals(5.0, NumberFieldActions.convertAreaUnit(action, 5.0));
    action.setToUnit(AreaUnitType.SQUARE_MILE);
    assertEquals(2.1522038567493116, NumberFieldActions.convertAreaUnit(action, 60000000.0));
    action.setFromUnit(AreaUnitType.SQUARE_MILE);
    action.setToUnit(AreaUnitType.SQUARE_METER);
    assertEquals(18129916.772352, NumberFieldActions.convertAreaUnit(action, 7.0));
    action.setToUnit(AreaUnitType.SQUARE_FOOT);
    assertEquals(223027200.0, NumberFieldActions.convertAreaUnit(action, 8.0));
    action.setToUnit(AreaUnitType.SQUARE_MILE);
    assertEquals(9.0, NumberFieldActions.convertAreaUnit(action, 9.0));
    assertNotNull(NumberFieldActions.convertAreaUnit(action, new BigDecimal("9")));
}
Also used : ConvertAreaUnit(io.atlasmap.v2.ConvertAreaUnit) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Aggregations

ConvertAreaUnit (io.atlasmap.v2.ConvertAreaUnit)3 AreaUnitType (io.atlasmap.v2.AreaUnitType)2 Test (org.junit.jupiter.api.Test)2 AtlasActionProcessor (io.atlasmap.spi.AtlasActionProcessor)1 AtlasFieldActionInfo (io.atlasmap.spi.AtlasFieldActionInfo)1 BigDecimal (java.math.BigDecimal)1