У меня есть следующий метод, когда я хочу проверить свойство event.status
только в том случае, если 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
}
}
Есть ли какая-то лучшая практика?