Skip to content

Commit d2158cb

Browse files
committed
reorder func
1 parent 36683cb commit d2158cb

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

core-kotlin-modules/core-kotlin-10/src/test/kotlin/com/baeldung/cloningobject/CloningObjectUnitTest.kt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,46 +19,46 @@ data class Person(var name: String, var address: Address) : Cloneable {
1919

2020
public override fun clone() = Person(name, this.address.clone())
2121

22+
constructor(person: Person) : this(person.name, Address(person.address))
23+
2224
fun deepCopy(
2325
name: String = this.name,
2426
address: Address = this.address.deepCopy()
2527
) = Person(name, address)
26-
27-
constructor(person: Person) : this(person.name, Address(person.address))
2828
}
2929

3030
data class Company(var name: String, var industry: String, val ceo: Person, val employees: List<Person>) : Cloneable {
3131

32-
fun deepCopy(
33-
name: String = this.name,
34-
industry: String = this.industry,
35-
ceo: Person = this.ceo.deepCopy(),
36-
employees: List<Person> = this.employees.map { it.deepCopy() },
37-
) = Company(name, industry, ceo, employees)
38-
3932
public override fun clone() = Company(name, industry, ceo.clone(), employees.map { it.clone() })
4033

4134
constructor(company: Company) : this(
4235
company.name,
4336
company.industry,
4437
Person(company.ceo),
4538
company.employees.map { Person(it) })
46-
}
47-
48-
data class Organization(var name: String, val headquarters: Address, val companies: List<Company>) : Cloneable {
4939

5040
fun deepCopy(
5141
name: String = this.name,
52-
headquarters: Address = this.headquarters.deepCopy(),
53-
companies: List<Company> = this.companies.map { it.deepCopy() },
54-
) = Organization(name, headquarters, companies)
42+
industry: String = this.industry,
43+
ceo: Person = this.ceo.deepCopy(),
44+
employees: List<Person> = this.employees.map { it.deepCopy() },
45+
) = Company(name, industry, ceo, employees)
46+
}
47+
48+
data class Organization(var name: String, val headquarters: Address, val companies: List<Company>) : Cloneable {
5549

5650
public override fun clone() = Organization(name, headquarters.clone(), companies.map { it.clone() })
5751

5852
constructor(organization: Organization) : this(
5953
organization.name,
6054
Address(organization.headquarters),
6155
organization.companies.map { Company(it) })
56+
57+
fun deepCopy(
58+
name: String = this.name,
59+
headquarters: Address = this.headquarters.deepCopy(),
60+
companies: List<Company> = this.companies.map { it.deepCopy() },
61+
) = Organization(name, headquarters, companies)
6262
}
6363

6464
class CloningObjectUnitTest {

0 commit comments

Comments
 (0)