Skip to content

Commit

Permalink
Issues boostcampwm-2022#287 feat: UIText 에 equals, hashcode 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
audxo112 committed Mar 1, 2023
1 parent 05b2092 commit 29b68d5
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ sealed class UIText(
) : UIText() {
override fun makeSpannable(context: Context): Spannable =
SpannableString(context.getString(resId, *args))

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is StringResource) return false

return resId == other.resId && args.contentEquals(other.args)
}

override fun hashCode(): Int {
var result = resId.hashCode()
result = 31 * result + args.contentHashCode()
return result
}
}

class SpannableResource(
Expand All @@ -60,6 +73,19 @@ sealed class UIText(
}
return spannable
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is SpannableResource) return false

return text == other.text && spans.contentEquals(other.spans)
}

override fun hashCode(): Int {
var result = text.hashCode()
result = 31 * result + spans.contentHashCode()
return result
}
}

class UITextSet(
Expand All @@ -74,6 +100,17 @@ sealed class UIText(
}
return builder
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is UITextSet) return false

return texts.contentEquals(other.texts)
}

override fun hashCode(): Int {
return texts.contentHashCode()
}
}

class Builder {
Expand Down

0 comments on commit 29b68d5

Please sign in to comment.