渡された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
}
}
ある種のベストプラクティスはありますか?