Skip to content

Commit

Permalink
refactor: Feedback compareTo 메소드를 Comparator 사용으로 변경한다
Browse files Browse the repository at this point in the history
  • Loading branch information
devxb committed Mar 9, 2024
1 parent a72fa11 commit 709a886
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/main/kotlin/me/nalab/api/survey/domain/feedback/Feedback.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,11 @@ class Feedback(
) : Comparable<Feedback>, TimeBaseEntity() {

override fun compareTo(other: Feedback): Int {
if (updatedAt.isAfter(other.updatedAt)) {
return -1
}
if (updatedAt.isBefore(other.updatedAt)) {
return 1
}
if (createdAt.isAfter(other.createdAt)) {
return -1
}
if (createdAt.isBefore(other.createdAt)) {
return 1
}
return 0
return DEFAULT_COMPARATOR.compare(this, other);
}

companion object {
val DEFAULT_COMPARATOR =
compareByDescending<Feedback> { it.updatedAt }.thenByDescending { it.createdAt }
}
}

0 comments on commit 709a886

Please sign in to comment.