final List<String> hasElectionWithGIPlanCode = getEnrollmentDocumentResponse…
- User
final List hasElectionWithGIPlanCode = getEnrollmentDocumentResponse .getDocument() .getEnrollmentData() .getElections() .stream() .map(election -> GI_PLAN_CODES.contains(election.getPlanCode()) ? election.getPlanCode() : null) .toList();
// If current election has a GI plan, Make the corresponding GI election nonEditable, // and remove other GI plans from BenefitPlans. getEnrollmentDocumentResponse .getDocument() .getEligibleBenefitPlansData() .getBenefitPlans() .removeIf(benefitPlan -> { if (GI_PLAN_CODES.contains(benefitPlan.getPlanCode())) { if (hasElectionWithGIPlanCode.contains(benefitPlan.getPlanCode())) { benefitPlan.setNonEditable(true); return false; } return true; } return false; });
Can you simplify this also i dont want to return null in map
- Assistant
Sure! The desired behavior seems to be that you want to process a list of elections to determine which ones are associated with a "GI Plan Code" and then modify the list of benefit plans based on whether or not a corresponding election exists.
We can simplify this process by eliminating the nulls and using a
Setto efficiently test for existence. Here's a version with these considerations:java