/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */

package net.ranides.assira.reflection.impl.bean;

import net.ranides.assira.functional.VarFunction;
import net.ranides.assira.reflection.BeanMethod;
import net.ranides.assira.reflection.IClass;
import net.ranides.assira.reflection.IClasses;
import net.ranides.assira.reflection.IMethod;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class RBeanMethod implements BeanMethod {
    
    private final IMethod method;
    
    RBeanMethod(IMethod method) {
        this.method = method;
    }

    @Override
    public String name() {
        return method.name();
    }

    @Override
    public VarFunction bind(Object that) {
        if(null == that) {
            throw new IllegalArgumentException("non-static method requires non-null 'this'");
        }
        return method.bind(that);
    }

    @Override
    public Object apply(Object that) {
        return method.apply(that);
    }

    @Override
    public Object apply(Object that, Object... arguments) {
        return method.apply(that, arguments);
    }
    
    @Override
    public boolean matches(IClass<?>... arguments) {
        return matches(IClasses.typeinfo(arguments));
    }

    @Override
    public boolean matches(IClasses arguments) {
        return method.matches(arguments);
    }

    @Override
    public boolean accepts(Object... arguments) {
        return method.accepts(arguments);
    }
    
}
