/*
 * Copyright (c) 2009 JSCAPE
 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * JSCAPE. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 * the terms of the license agreement you entered into with JSCAPE.
 *
 */

package com.jscape.util.reflection;

import com.jscape.util.functor.UnaryPredicate;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;

/**
 * @author Alex Usun
 */
public class MethodParametersEqual
        extends UnaryPredicate<Method> {

    private final boolean explicit;
    private final Class[] parameterTypes;

    public MethodParametersEqual(boolean explicit, Class... parameterTypes) {
        this.explicit = explicit;
        this.parameterTypes = parameterTypes;
    }

    public MethodParametersEqual(boolean explicit, Collection<Class> parameterTypes) {
        this(explicit, parameterTypes.toArray(new Class[parameterTypes.size()]));
    }

    public boolean evaluate(Method value) {
        return ReflectionTools.match(value.getParameterTypes(), this.parameterTypes, this.explicit);
    }

    @Override
    public String toString() {
        return "MethodParametersEqual {"
                + "explicit=" + this.explicit
                + ", parameterTypes=" + Arrays.asList(this.parameterTypes)
                + '}';
    }

}
