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

com.gitee.feizns.convert.method.valueof.AbstractMethodSelectionStrategyByParameter Maven / Gradle / Ivy

There is a newer version: 5.5-RELEASE
Show newest version
package com.gitee.feizns.convert.method.valueof;

import com.gitee.feizns.convert.method.MethodSelectionStrategy;
import com.gitee.feizns.convert.method.MethodWrapper;
import com.gitee.feizns.reflect.ClassUtils;

import java.lang.reflect.Method;
import java.util.Queue;

/**
 * @author feizns
 * @since 2019/5/29
 */
public abstract class AbstractMethodSelectionStrategyByParameter implements MethodSelectionStrategy {

    @Override
    public MethodWrapper find(Class targetType, Object original, Method... methods) {
        Queue> classes = ClassUtils.getClassesAndInterfaces(original.getClass());
        while ( classes.isEmpty() == false ) {
            Class item = classes.remove();
            for (Method method : methods) {
                if ( isYou(method, item) )
                    return getInvokeStrategy(method, targetType, original);
            }
        }
        return null;
    }

    /**
     * 寻找具体的方法
     * @param method
     * @param inheritanceClz
     * @return
     */
    protected abstract boolean isYou(Method method, Class inheritanceClz);

    /**
     * 方法调用的具体策略
     * @param method
     * @param targetType
     * @param original
     * @return
     */
    protected abstract MethodWrapper getInvokeStrategy(Method method, Class targetType, Object original);

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy