У меня есть следующий метод, где я хочу для проверки свойства event.status
только в том случае, если статус
был передан:
def findEvent(String desc, String status = null, Collection events) {
return events.find {
it.description == desc && \\If status is not null: it.status == status
}
throw new Exception("Review Event Record Not Found: ${desc}")
}
Я думал, что это можно сделать так, но, похоже, это не работает:
def findEvent(String desc, String status = null, Collection events) {
return events.find {
it.description == desc && (status != null ?: {it.status == status})
}
throw new Exception("Review Event Record Not Found: ${desc}")
}
Можно ли как-то это сделать? Или мне нужно вернуться к чему-то вроде этого:
if (status != null) {
return events.find {
it.description == desc && it.status == status
}
} else if (status == null) {
return events.find {
it.description == desc
}
}
Есть ли какая-то передовая практика?