package com.lz.modules.app.utils;

import org.apache.shiro.util.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class BeanConversionUtils {
    private static Logger logger = LoggerFactory.getLogger(BeanConversionUtils.class);

    public static <T, F> List<F> listCopyToAnotherList(Class<F> target, List<T> soueceList) {
        if (!CollectionUtils.isEmpty(soueceList)) {
            List<F> targetList = new ArrayList<F>();
            for (T t : soueceList) {
                try {
                    F f = target.newInstance();
                    BeanUtils.copyProperties(t, f);
                    targetList.add(f);
                } catch (Exception e) {
                    logger.error(e.getMessage());
                }
            }
            return targetList;
        } else {
            return null;
        }
    }

}
