Вы можете просто применить простой поток для каждого, как показано ниже:
group.getGroupCallCenters().stream().forEach((existingGroupCall) ->
{
if(!existingGroupCall.getCallCenter()
.getId().equals(accountCallCenterResource.getCallCenterId()))
{
if
(!accountCallCenterResource.getValidity().getEffectiveStarting()
.isAfter(existingGroupCall.getExpirationDate())
&& !existingGroupCall.getEffectiveDate()
.isAfter(accountCallCenterResource.getValidity().getExpiresAfter()))
{
throw new ApiException(ApiErrorCode.DEFAULT_400, "Group call center already exist for that period");
}
}
else {
throw new DuplicateException(ApiErrorCode.DUPLICATE,
existingGroupCall.getId());
}
});
Вы не упомянули, что такое accountCallCenterResource
объект в вашем коде. Вы должны убедиться, что accountCallCenterResource
является окончательным или эффективным, чтобы использовать его внутри метода stream.
Для более детального понимания вы можете обратиться к этому