Skip to content

Commit

Permalink
PI-2391: Added sort of court appearances and recal/withdrawn
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcphee77 committed Aug 2, 2024
1 parent 0610127 commit 69eda3a
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,17 @@ class ConvictionService(
}

fun Event.toLatestOrSentencingCourtAppearanceOf(): CourtAppearanceBasic? {
return courtAppearances.filter { it.isSentenceing() }
.sortedByDescending(CourtAppearance::appearanceDate)
.maxByOrNull { it.appearanceDate }
?.let { return it.toCourtAppearanceBasic() }
?: courtAppearances.sortedByDescending(CourtAppearance::appearanceDate).maxByOrNull { it.appearanceDate }
?.let { return it.toCourtAppearanceBasic() }
return courtAppearances
.stream()
.filter { it.isSentenceing() }
.max(Comparator.comparing(CourtAppearance::appearanceDate))
.map { it.toCourtAppearanceBasic() }.orElseGet {
courtAppearances
.stream()
.max(Comparator.comparing(CourtAppearance::appearanceDate))
.map { it.toCourtAppearanceBasic() }
.orElse(null)
}
}

fun CourtAppearance.toCourtAppearanceBasic(): CourtAppearanceBasic =
Expand Down

0 comments on commit 69eda3a

Please sign in to comment.