/**
     * Consumer<T> :消费型接口
     *      void accept(T t)
     * Supplier<T t> :供给型接口
     *      T get();
     * Function<T t,R r> :函数型接口
     *      R apply(T t);
     * Predicate<T t> :断言型接口
     *      boolean test(T t);
     */
	//消费型接口
    @Test
    public void test1(){
        happy(10000,(m)->System.out.print("本次购买开心消费:"+m+"元"));
    }
    public void happy(double money, Consumer<Double> consumer){
        consumer.accept(money);
    }

    //供给型接口
    @Test
    public void test2(){
        List<Double> list = getNumList(10, () ->  Math.random() * 100);
        for (double num:list){
            System.out.println(num);
        }
    }
    public List<Double> getNumList(int num, Supplier<Double> sup){
        List<Double> list = new ArrayList<>();
        for (int i=0;i<num;i++){
            double n = sup.get();
            list.add(n);
        }
        return list;
    }

    //函数型接口
    @Test
    public void test3(){
        String strTrim=strHandler("\t\t\t TAO",(str)->str.trim());
        System.out.println(strTrim);

        String substring=strHandler("dasdasda",(str)->str.substring(2,5));
        System.out.println(substring);
    }
    public String strHandler(String str, Function<String,String> fun){
        return fun.apply(str);
    }

    //断言型接口
    @Test
    public void test4(){
        List<String> list = Arrays.asList("Hello", "atguigu", "Lambda", "www", "ok");
        List<String> strList = filterStr(list, (s) -> s.length() > 3);
        for (String str:strList){
            System.out.println(str);
        }
    }
    public List<String> filterStr(List<String> list, Predicate<String> pre){
        List<String> strList = new ArrayList<>();
        for (String str:list){
            if (pre.test(str)){
                strList.add(str);
            }
        }
        return strList;
    }