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); });
2、optional类
避免空指针