java1.8特性

java1.8特性

1、lambda表达式

Java8为集合类引入了另一个重要概念:流(stream)。一个流通常以一个集合类实例为其数据源,然后在其上定义各种操作
例如
.filter
.forEach
dueEntry.stream().map(f -> f.getKey()).forEach(index -> {

            // 每一期的还款金额信息
            String body = repayMessage.getRepayDetails().get(index);
            JSONObject repayObj = JSON.parseObject(body);
            // 本金
            BigDecimal principal = new BigDecimal(repayObj.getDoubleValue("principal"));
            // 利息
            BigDecimal interest = new BigDecimal(repayObj.getDoubleValue("interest"));
            // 应发放积分
            Integer point = countUserPoint(principal, interest);

            // 是否有发放记录查询
            UserPointHistory history = new UserPointHistory();
            history.setIncomeType(IncomeType.REPAY.getName());
            history.setType(PointType.INCOME.getValue());
            history.setUserId(loan.getBorrowerId());
            history.setApplicationId(repayMessage.getApplication_id());
            history.setIndex(Integer.valueOf(index));
            if (userPointHistoryMapper.countByHistory(history) > 0) {
                logger.warn("UserPoint warn:repay重复的积分插入,applicationId:{}", repayMessage.getApplication_id());
                return;
            }
            // 发放积分
            providePoints(loan.getBorrowerId(), IncomeType.REPAY, repayMessage.getApplication_id(), Integer.valueOf(index), point);
        });
View Code

 2、optional类

 避免空指针

posted @ 2018-07-04 16:47  YOU_CAN  阅读(339)  评论(0编辑  收藏  举报