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

io.github.kits.ListKit Maven / Gradle / Ivy

The newest version!
package io.github.kits;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 集合工具类
 *
 * @author: kits
 * @date: Create in 2018 05 06 下午3:16
 */
public class ListKit {

	/**
	 * 判断list是否为null
	 *
	 * @param list
	 * @param 
	 * @return
	 */
	public static  boolean isNull(List list) {
		return list == null;
	}

	/**
	 * 判断是否不为null
	 *
	 * @param list
	 * @param 
	 * @return
	 */
	public static  boolean isNotNull(List list) {
		return !isNull(list);
	}

	/**
	 * 判断是否为空
	 *
	 * @param list
	 * @return
	 */
    public static boolean isNullOrEmpty(List list) {
        return list == null || list.isEmpty();
    }

	/**
	 * 判断是否不为空
	 *
	 * @param list
	 * @return
	 */
	public static boolean isNotNullOrEmpty(List list) {
        return !isNullOrEmpty(list);
    }

	/**
	 * 转换为集合
	 *
	 * @param objects
	 * @param 
	 * @return
	 */
    @SafeVarargs
	public static  List asList(T... objects) {
        if (objects == null || objects.length == 0) {
            return null;
        }
		return Arrays.asList(objects);
    }

	/**
	 * 将数组添加到集合中
	 *
	 * @param 			泛型约束
	 * @param targetList    目标集合
	 * @param resource        资源数组
	 */
	@SafeVarargs
	public static  void add2List(List targetList, T... resource) {
		if (isNotNull(targetList)) {
			List newList = Stream.of(resource)
									.filter(t -> !(t instanceof Field) || !((Field) t).getName().equals("serialVersionUID"))
									.collect(Collectors.toList());
			if (isNotNullOrEmpty(newList)) {
				targetList.addAll(newList);
			}
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy