Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleOutputAttributeAggregator class
package org.wso2.siddhi.extension;

import org.wso2.siddhi.core.query.selector.attribute.handler.OutputAttributeAggregator;
import org.wso2.siddhi.query.api.definition.Attribute.Type;
import java.text.DecimalFormat;

public class CurrencyConversionAggregatorDouble implements OutputAttributeAggregator {
    private static final long serialVersionUID = 1358667430272544590L;


    @Override
    public Type getReturnType() {
        return Type.DOUBLE;
    }


    @Override
    public Object processAdd(Object obj) {
        double amountEUR = 0D;
        if (obj instanceof Object[]) {
            Object[] objArray = (Object[]) obj;
            double amountUSD = (Double)objArray[0];
            double conversionRate = (Double)objArray[1];
            amountEUR = Double.valueOf(new DecimalFormat("#.##").format(amountUSD * conversionRate));
        }
        return amountEUR;
    }


    @Override
    public Object processRemove(Object obj) {
        double amountEUR = 0D;
        if (obj instanceof Object[]) {
            Object[] objArray = (Object[]) obj;
            double amountUSD = (Double)objArray[0];
            double conversionRate = (Double)objArray[1];
            amountEUR = Double.valueOf(new DecimalFormat("#.##").format(amountUSD * conversionRate));
        }
        return amountEUR;
    }


    @Override
    public OutputAttributeAggregator newInstance() {
        return new CurrencyConversionAggregatorDouble();
    }
 
    @Override
    public void destroy() {
    }
}