我正在尋找用Java lambda表達式替換下面的代碼。在下面的例子中,如果找到匹配,我需要出來循環,並且爲了斷言將boolean設置爲true條件用Java lambda表達式替換自定義列表搜索
Long teamId;
boolean matchFound = false;
List<WorkflowSubscriptions> workflowSubscriptionsList = fetchSubscriptions();
for (WorkflowSubscriptions workflowSubscriptions : workflowSubscriptionsList) {
for (WorkflowCompositeInfo workflowCompositeInfo : workflowSubscriptions.getWorkflowCompositeInfo()) {
if (workflowCompositeInfo.getId() > 0 && workflowCompositeId == workflowCompositeId.intValue()) {
teamId = Long.valueOf(workflowSubscriptions.getId());
matchFound = true;
}
}
}
if (!matchFound) {
throw new CustomParameterizedException("Workflow does not have valid subscriptions");
}
你有沒有問之前嘗試過嗎?你有什麼想法? –
我準備的下面的代碼是爲列表的一個級別。現在我在列表中列出StreamSupport.stream(可選.ofNullable(rwpSubscriptions).orElse(Collections.emptyList())) .filter(s-> s.getCompositeId()。equals(workflowCompositeId)) .findFirst () .map(s-> s.getTeamId()) .orElseThrow(() - > new CustomParameterizedException(「Workflow does not have a valid subscription」)) – Balaji
@YassinHajaj發帖供您參考 – Balaji