Skip to content

Commit

Permalink
Merge pull request #90 from eshc123/refactor/refac-data-class-get-method
Browse files Browse the repository at this point in the history
[REFACTOR] Player Property by lazy
  • Loading branch information
KanuKim97 authored Jun 8, 2024
2 parents a15e3ec + 6f4f986 commit 98e6650
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,39 @@ import java.time.LocalDate
import java.time.Period

data class Player(
val id :Int,
val name : String = "",
val backNumber : Int = 0,
val birthDate : String = "",
val height : Int = 0,
val weight : Int = 0,
val imageUrl : String = "",
val contractStartDate : String = "",
val contractEndDate : String = "",
val position : String = "",
val positionInitial : String = "",
val positionCategory : String = "",
val nationality : String = "",
val id: Int,
val name: String = "",
val backNumber: Int = 0,
val birthDate: String = "",
val height: Int = 0,
val weight: Int = 0,
val imageUrl: String = "",
val contractStartDate: String = "",
val contractEndDate: String = "",
val position: String = "",
val positionInitial: String = "",
val positionCategory: String = "",
val nationality: String = "",
val nationalityImageUrl: String = ""
) {
private val names : List<String>
private val names: List<String>
get() = name.split(" ")

val firstName : String
private val firstName: String
get() = names.firstOrNull() ?: ""

val lastNames : String
private val lastNames: String
get() = names.let {
if(it.size > 1) names.subList(1, names.lastIndex + 1).joinToString(" ")
if (it.size > 1) names.subList(1, names.lastIndex + 1).joinToString(" ")
else ""
}

val displayName : String
get() = firstName + (if(lastNames.isEmpty()) "" else "\n${lastNames}")
val displayName: String by lazy(LazyThreadSafetyMode.NONE) {
firstName + (if (lastNames.isEmpty()) "" else "\n${lastNames}")
}

fun getAge() : Int {
return Period.between(
val age: Int by lazy(LazyThreadSafetyMode.NONE) {
Period.between(
getYearAndMonthAndDateLocalDate(birthDate),
LocalDate.now()
).years
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ fun PlayerDetailScreen(
) {
PlayerDetailInfo(
title = "Age",
content = "${player.getAge()}"
content = "${player.age}"
)
PlayerDetailInfo(
title = "Games",
Expand Down

0 comments on commit 98e6650

Please sign in to comment.