package com.securitycontrol.common.core.utils.aes;


import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;

/**
 * @author HeiZi
 */
public class ListHelper {

    public static <T> boolean isNotEmpty(List<T> list){
        if(list!=null &&list.size()>0){
            return true;
        }
        return false;
    }
    public static <T> boolean isEmpty(List<T> list){
        return !isNotEmpty(list);
    }
    /**
     * 集合转字符串
     * @param list
     * @param join
     * @return
     */
    public static String joinList(List<String> list,String join){
        String strs=null;
        for (String st:list) {
            if(strs==null){
                strs=st;
            }else{
                strs=strs+join+st;
            }
        }
        return strs;
    }


    public static List<String>  asList(String  arr,String str){
            if(StringHelper.isNotEmpty(arr)){
                return Arrays.asList(arr.split(str));
            }
            return  null;

    }
    /**
     * 集合校验
     * @param keyExtractor
     * @param <T>
     * @return
     */
    public  static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
        Map<Object, Boolean> seen = new ConcurrentHashMap<>(10);
        return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
    }
}
