【发布时间】:2020-02-06 15:58:26
【问题描述】:
我有以下 sn-p,我想知道是否以及如何用 Java-streams/Java 8 API 替换它
List<Borrower> borrowers = creditcomplex.getBorrowers();
for (Borrower borrower : borrowers) {
List<Facility> facilities = borrower.getFaciliies();
for (Facility facility : facilities) {
List<RepaymentSchedule> repaymentScheduleList = facility.getrepaymentSchedule();
if (repaymentScheduleList != null) {
for (RepaymentSchedule repaymentschedule : repaymentScheduleList) {
double[] repayment =
amortizationService.calculateAmortizationSchedule(repaymentschedule);
double[] drawdown =
amortizationService.calculateRepaymentSchedule(repaymentschedule);
double[] outstandingProfie = amortizationService
.calculateOutstandingSchedule(repaymentschedule);
}
}
}
}
【问题讨论】:
-
我可能希望将上述一些功能折叠到(比如说)Borrower 类、Facility 类等中。然后你可以询问这些类并委托,而不是从对象中提取对象对象....有关更多信息,请参阅en.wikipedia.org/wiki/Law_of_Demeter....您可能需要传递 amortizationService,注意...
标签: java arrays collections java-8 java-stream