package com.eactive.eai.custom.transformer.function.userdefined;

import java.util.Stack;

import org.apache.commons.lang.StringUtils;
import org.nfunk.jep.ParseException;
import org.nfunk.jep.function.PostfixMathCommand;


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

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

        Object p1 = inStack.pop();

        String strInStack = "";
        String resultStr = "";
        if (p1 instanceof byte[]) {
        	strInStack = new String((byte[]) p1);
        } else if (p1 instanceof String) {
        	strInStack = (String) p1;
        } else {
            throw new ParseException("Invalid parameter type, p1 is not string/bytes");
        }

        if (StringUtils.equalsIgnoreCase(strInStack, "Y")) {
    		resultStr = "True";
    	} else {
    		resultStr = "False";
    	}
    	inStack.push(resultStr);
    }
}
