package com.storlead.framework.common.aviator;

import com.googlecode.aviator.runtime.function.AbstractFunction;
import com.googlecode.aviator.runtime.type.AviatorBoolean;
import com.googlecode.aviator.runtime.type.AviatorObject;

import java.util.Map;

/**
 * @program: sp-sales-platform
 * @description:
 * @author: chenkq
 * @create: 2024-06-18 18:25
 */
public class MapKeyExistsFunction extends AbstractFunction {

    @Override
    public AviatorBoolean call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {

        Map<?, ?> map = (Map<?, ?>) arg1.getValue(env);
        String key = arg2.stringValue(env);
        return AviatorBoolean.valueOf(map.containsKey(key));
    }

    @Override
    public String getName() {
        return "containsKey";
    }


}
