package com.engine.salary.util;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

public class DataUtil {

    public static <T> List<T> castList(Object obj, Class<T> clazz) {

        List<T> result = new ArrayList<T>();
        if (obj.getClass().isArray()) {
            int len = Array.getLength(obj);
            for (int i = 0; i < len; i++) {
                Object o = Array.get(obj, i);
                result.add(clazz.cast(o));
            }
        } else if (obj instanceof List<?>) {
            for (Object o : (List<?>) obj) {
                result.add(clazz.cast(o));
            }
        }
        return result;
    }

}
