All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gitee.feizns.convert.method.valueof.handle.TwoParameterValueOfHandler Maven / Gradle / Ivy

package com.gitee.feizns.convert.method.valueof.handle;

import com.gitee.feizns.reflect.MethodUtils;

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

/**
 * valueOf(Class, source):的筛选过程与调用过程
 * @author feizns
 * @since 2019/6/22 0022
 */
public class TwoParameterValueOfHandler extends AbstractConverterMethodSelectionHandler {

    public TwoParameterValueOfHandler(Class sourceType, Class targetType) {
        super(sourceType, targetType);
    }

    @Override
    protected Method[] getMethods(Class type, Class sourceType, Class targetType) {
        return Arrays.stream(type.getMethods())
                .filter(method -> method.getName().equals("valueOf"))
                .filter(method -> Modifier.isStatic(method.getModifiers()))
                .filter(method -> method.getParameterCount() == 2)
                .filter(method -> method.getParameterTypes()[0] == Class.class)
                .toArray(Method[]::new);
    }

    @Override
    protected Object invoke(Method method, Object source, Class sourceType, Class targetType) {
        return MethodUtils.invoke(method, targetType, source);
    }

    @Override
    protected Class getParameterType(Method method) {
        return method.getParameterTypes()[1];
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy