Search in sources :

Example 1 with MassUnitType

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

the class NumberFieldActions method convertMassUnit.

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

Aggregations

AtlasFieldActionInfo (io.atlasmap.spi.AtlasFieldActionInfo)1 ConvertMassUnit (io.atlasmap.v2.ConvertMassUnit)1 MassUnitType (io.atlasmap.v2.MassUnitType)1