Search in sources :

Example 1 with VolumeUnitType

use of io.atlasmap.v2.VolumeUnitType 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

AtlasFieldActionInfo (io.atlasmap.spi.AtlasFieldActionInfo)1 ConvertVolumeUnit (io.atlasmap.v2.ConvertVolumeUnit)1 VolumeUnitType (io.atlasmap.v2.VolumeUnitType)1