在我已经过滤掉子对象之后,我需要能够访问groupCoverPeriod对象。如何使用流进行此操作..我编写了以下代码,但是在** groupCoverPeriod *处出错(请忽略代码中带前缀和后缀的**)
boolean isCalMethodCal=newInsurancePeriod.getPensionGroup().getGroupCoverPeriods().stream()
.filter(groupCoverPeriod -> groupCoverPeriod.getStartDate().isBefore(newInsurancePeriod.getStartDate()) && (
Objects.isNull(newInsurancePeriod.getEndDate()) || groupCoverPeriod.getStartDate().isAfter(newInsurancePeriod.getEndDate())))
.filter(groupCoverPeriod -> !groupCoverPeriod.getCalcMethod().equalsIgnoreCase("kiinnitetty"))
.flatMap(groupCoverPeriod -> groupCoverPeriod.getInsuranceCoverInfos().stream())
.filter(ici -> ici.getBenefitType().equalsIgnoreCase("VE"))
.anyMatch(ici -> !ici.getOverServiceNotification().equals(true)
|| !ici.getConsideredEarningsInRTAge().equals(true)
|| (ici.getConsideredStatutoryEarningsInRTAge().equalsIgnoreCase("6300") && beginDate >= 6300)
|| (ici.getConsideredStatutoryEarningsInRTAge().equalsIgnoreCase("6500") && beginDate >= 6500)
|| (ici.getDeferralIncreaseSupplementaryPension().equalsIgnoreCase("ei") || ici.getDeferralIncreaseSupplementaryPension().equalsIgnoreCase("elakemuunnos"))
|| (**groupCoverPeriod**.getTerminationAge().equalsIgnoreCase("yhteinen") && groupCoverPeriod.getGroupSuplInsuranceRTAge() >= beginDate)
|| (**groupCoverPeriod**.getTerminationAge().equalsIgnoreCase("yksilollinen") && insurancePeriod.getPersonsCoverInfo().getAgeForSupplementaryPension() >= beginDate)
|| (**groupCoverPeriod**.getTerminationAge().equalsIgnoreCase("wtyel_vahvistettu") && Integer.parseInt(ykService.getPersonBirthYear(newInsurancePeriod.getPerson().getPersonNumber())) >= beginDate)
|| (**groupCoverPeriod**.getTerminationAge().equalsIgnoreCase("wtyel_ennustettu") && Integer.parseInt(ykService.getPersonBirthYear(newInsurancePeriod.getPerson().getPersonNumber())) >= beginDate));
我什至尝试过,但这没有返回预期的结果。
newInsurancePeriod.getPensionGroup().getGroupCoverPeriods().stream()
.filter(groupCoverPeriod -> groupCoverPeriod.getStartDate().isBefore(newInsurancePeriod.getStartDate()) && (
Objects.isNull(newInsurancePeriod.getEndDate()) || groupCoverPeriod.getStartDate().isAfter(newInsurancePeriod.getEndDate())))
.filter(groupCoverPeriod -> !groupCoverPeriod.getCalcMethod().equalsIgnoreCase("kiinnitetty"))
.forEach(groupCoverPeriod -> {
boolean isCalMethodCal = groupCoverPeriod.getInsuranceCoverInfos().stream()
.filter(ici -> ici.getBenefitType().equalsIgnoreCase("VE"))
.anyMatch(ici -> !ici.getOverServiceNotification().equals(true)
|| !ici.getConsideredEarningsInRTAge().equals(true)
|| (ici.getConsideredStatutoryEarningsInRTAge().equalsIgnoreCase("6300") && beginDate >= 6300)
|| (ici.getConsideredStatutoryEarningsInRTAge().equalsIgnoreCase("6500") && beginDate >= 6500)
|| (ici.getDeferralIncreaseSupplementaryPension().equalsIgnoreCase("ei") || ici.getDeferralIncreaseSupplementaryPension().equalsIgnoreCase("elakemuunnos"))
|| (groupCoverPeriod.getTerminationAge().equalsIgnoreCase("yhteinen") && groupCoverPeriod.getGroupSuplInsuranceRTAge() >= beginDate)
|| (groupCoverPeriod.getTerminationAge().equalsIgnoreCase("yksilollinen") && insurancePeriod.getPersonsCoverInfo().getAgeForSupplementaryPension() >= beginDate)
|| (groupCoverPeriod.getTerminationAge().equalsIgnoreCase("wtyel_vahvistettu") && Integer.parseInt(ykService.getPersonBirthYear(newInsurancePeriod.getPerson().getPersonNumber())) >= beginDate)
|| (groupCoverPeriod.getTerminationAge().equalsIgnoreCase("wtyel_ennustettu") && Integer.parseInt(ykService.getPersonBirthYear(newInsurancePeriod.getPerson().getPersonNumber())) >= beginDate));
答案 0 :(得分:1)
您的过滤器似乎到处都是。为什么要再次检查组保障期?
尝试重新排列代码,如下所示:
Predicate<GroupCoverPeriod> groupCoverPredicates = // all group cover predicates here filter predicates here
Predicate<InsuranceCoverInfo> iciPredicates = // all insurance cover info filter predicates here;
boolean isCalMethodCal = newInsurancePeriod.getPensionGroup().getGroupCoverPeriods().stream()
.filter(groupCoverPeriod -> groupCoverPredicates)
.flatMap(groupCoverPeriod -> groupCoverPeriod.getInsuranceCoverInfos().stream())
.anyMatch(ici -> iciPredicates);