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

import java.util.Stack;

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


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

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

        Object p1 = inStack.pop();

        if (p1 instanceof String) {
            String str = (String) p1;
            inStack.push(new Integer(str.length()));
        } else if (p1 instanceof byte[]) {
//            byte[] str = (byte[]) p1;
            inStack.push(((byte[]) p1).length);
        } else {
            throw new ParseException("Invalid parameter type");
        }
    }
}
