hbthlw
8/6/2018 - 11:23 AM

[Java8高阶函数] #java8

[Java8高阶函数] #java8

    @Test
    public void testCalculateDailySettlement() {
      
        loopDays(checkDate -> settlementManager.calculateDailySettlement(checkDate));

    }    
    
    //应用优先使用默认的接口函数,此处应当使用Consumer<T>
    public interface Block<T> {
        void apply(T t);
    }

    public void loopDays(Block<Date> block) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, 2018);
        calendar.set(Calendar.MONTH, Calendar.JUNE);
        calendar.set(Calendar.DATE, 25);

        Calendar july = Calendar.getInstance();

        do {
            Date checkDate = calendar.getTime();
            block.apply(checkDate);
            calendar.add(Calendar.DATE, 1);
        } while (calendar.before(july));
    }