package com.eactive.eai.transformer.function.generic;

import java.util.Stack;

import org.nfunk.jep.ParseException;
import org.nfunk.jep.function.PostfixMathCommand;


public class ToDouble extends PostfixMathCommand {
    public ToDouble() {
        numberOfParameters = 1;
    }

    public void run(Stack inStack) throws ParseException {
        checkStack(inStack);

        Object p1 = inStack.pop();

        if (p1 instanceof byte[]) {
            inStack.push(Double.valueOf(new String((byte[]) p1)));
        } else if (p1 instanceof String) {
            inStack.push(Double.valueOf((String) p1));
        } else {
            throw new ParseException("Invalid parameter type, p1 is not string/bytes");
        }
    }
}
