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

com.luues.util.classUtil.ClassUtil Maven / Gradle / Ivy

There is a newer version: 1.3.0.5.RELEASE
Show newest version
package com.luues.util.classUtil;

import org.apache.logging.log4j.util.Strings;
import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Set;

/**
 * Created by Mr-Wu on 2019/12/28.
 */
public class ClassUtil {

    public static  Set> getSubTypesOf(String mypackage, Class tclass){
        Reflections reflections = new Reflections(Strings.isBlank(mypackage) ? "" : mypackage);
        Set> subTypes = reflections.getSubTypesOf(tclass);
        return subTypes;
    }

    public static Set> getTypesAnnotatedWith(Class tClass){
        Reflections reflections = new Reflections("");
        return reflections.getTypesAnnotatedWith(tClass);
    }

    public static Set> getAllClass(String mypackage){
        Reflections reflections = new Reflections(Strings.isBlank(mypackage) ? "" : mypackage, new SubTypesScanner(false));
        return reflections.getSubTypesOf(Object.class);
    }

    /**
     * 该方法是用于相同对象不同属性值的合并,如果两个相同对象中同一属性都有值,那么sourceBean中的值会覆盖tagetBean重点的值
     * @param sourceBean    被提取的对象bean
     * @param targetBean    用于合并的对象bean
     * @return targetBean,合并后的对象
     */
    public static  T combineSydwCore(T sourceBean,T targetBean){
        Class sourceBeanClass = sourceBean.getClass();
        Class targetBeanClass = targetBean.getClass();
        Field[] sourceFields = sourceBeanClass.getDeclaredFields();
        Field[] targetFields = targetBeanClass.getDeclaredFields();
        for(int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy