Source:
<code>public List<QuestionableActivityListingDTO> checkMeasuresRemoved( CertifiedProductSearchDetails origListing, CertifiedProductSearchDetails newListing) { List<QuestionableActivityListingDTO> measuresRemovedActivities = new ArrayList<QuestionableActivityListingDTO>(); if (origListing.getMeasures() != null && origListing.getMeasures().size() > 0 && newListing.getMeasures() != null && newListing.getMeasures().size() > 0) { for (ListingMeasure origMeasure : origListing.getMeasures()) { Optional<ListingMeasure> matchingNewMeasure = newListing.getMeasures().stream() .filter(newMeasure -> origMeasure.getId().equals(newMeasure.getId())) <START> .findFirst(); <END> if (!matchingNewMeasure.isPresent()) { QuestionableActivityListingDTO activity = new QuestionableActivityListingDTO(); activity.setBefore(origMeasure.getMeasurementType().getName() + " measure " + origMeasure.getMeasure().getName() + " for " + origMeasure.getMeasure().getAbbreviation()); activity.setAfter(null); measuresRemovedActivities.add(activity); } } } else if (origListing.getMeasures() != null && (newListing.getMeasures() == null || newListing.getMeasures().size() == 0)) { for (ListingMeasure origMeasure : origListing.getMeasures()) { QuestionableActivityListingDTO activity = new QuestionableActivityListingDTO(); activity.setBefore(origMeasure.getMeasurementType().getName() + " measure " + origMeasure.getMeasure().getName() + " for " + origMeasure.getMeasure().getAbbreviation()); activity.setAfter(null); measuresRemovedActivities.add(activity); } } return measuresRemovedActivities; }</code><technical_language>FYI... findAny is more efficient findFirst streams necessarily processing in order. <LINK_0></technical_language>

Target:
public List<QuestionableActivityListingDTO> checkMeasuresRemoved( CertifiedProductSearchDetails origListing, CertifiedProductSearchDetails newListing) { List<QuestionableActivityListingDTO> measuresRemovedActivities = new ArrayList<QuestionableActivityListingDTO>(); if (origListing.getMeasures() != null && origListing.getMeasures().size() > 0 && newListing.getMeasures() != null && newListing.getMeasures().size() > 0) { for (ListingMeasure origMeasure : origListing.getMeasures()) { Optional<ListingMeasure> matchingNewMeasure = newListing.getMeasures().stream() .filter(newMeasure -> origMeasure.getId().equals(newMeasure.getId())) .findAny(); if (!matchingNewMeasure.isPresent()) { QuestionableActivityListingDTO activity = new QuestionableActivityListingDTO(); activity.setBefore(origMeasure.getMeasureType().getName() + " measure " + origMeasure.getMeasure().getName() + " for " + origMeasure.getMeasure().getAbbreviation()); activity.setAfter(null); measuresRemovedActivities.add(activity); } } } else if (origListing.getMeasures() != null && (newListing.getMeasures() == null || newListing.getMeasures().size() == 0)) { for (ListingMeasure origMeasure : origListing.getMeasures()) { QuestionableActivityListingDTO activity = new QuestionableActivityListingDTO(); activity.setBefore(origMeasure.getMeasureType().getName() + " measure " + origMeasure.getMeasure().getName() + " for " + origMeasure.getMeasure().getAbbreviation()); activity.setAfter(null); measuresRemovedActivities.add(activity); } } return measuresRemovedActivities; }