Search in sources :

Example 1 with DistanceUnitType

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

the class NumberFieldActions method convertDistanceUnit.

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

Aggregations

AtlasFieldActionInfo (io.atlasmap.spi.AtlasFieldActionInfo)1 ConvertDistanceUnit (io.atlasmap.v2.ConvertDistanceUnit)1 DistanceUnitType (io.atlasmap.v2.DistanceUnitType)1