@@ -8,46 +8,86 @@ internal val expectedSimpleTestContent = """
8
8
import kotlin.String
9
9
import kotlin.Unit
10
10
import kotlin.jvm.JvmSynthetic
11
-
11
+
12
+ /**
13
+ * Represents a person.
14
+ * @property name The full name.
15
+ * @property nickname The nickname.
16
+ * @property age The age.
17
+ */
12
18
public class Person private constructor(
13
19
public val name: String,
14
20
public val nickname: String?,
15
21
public val age: Int
16
22
) {
17
23
public override fun toString() = "Person(name=%name, nickname=%nickname, age=%age)"
18
-
24
+
19
25
public override fun equals(other: Any?): Boolean = other is Person
20
26
&& name == other.name
21
27
&& nickname == other.nickname
22
28
&& age == other.age
23
-
29
+
24
30
public override fun hashCode(): Int = Objects.hash(name, nickname, age)
25
-
31
+
32
+ /**
33
+ * Composes and builds a [Person] object.
34
+ *
35
+ * This is a concrete implementation of the builder design pattern.
36
+ *
37
+ * @property name The full name.
38
+ * @property nickname The nickname.
39
+ * @property age The age.
40
+ */
26
41
public class Builder {
27
42
@set:JvmSynthetic
28
43
public var name: String? = null
29
-
44
+
30
45
@set:JvmSynthetic
31
46
public var nickname: String? = null
32
-
47
+
33
48
@set:JvmSynthetic
34
49
public var age: Int? = null
35
-
50
+
51
+ /**
52
+ * Set the full name.
53
+ *
54
+ * @param name the full name.
55
+ * @return Builder
56
+ */
36
57
public fun setName(name: String?): Builder {
37
58
this.name = name
38
59
return this
39
60
}
40
-
61
+
62
+ /**
63
+ * Set the nickname.
64
+ *
65
+ * @param nickname the nickname.
66
+ * @return Builder
67
+ */
41
68
public fun setNickname(nickname: String?): Builder {
42
69
this.nickname = nickname
43
70
return this
44
71
}
45
-
72
+
73
+ /**
74
+ * Set the age.
75
+ *
76
+ * @param age the age.
77
+ * @return Builder
78
+ */
46
79
public fun setAge(age: Int?): Builder {
47
80
this.age = age
48
81
return this
49
82
}
50
-
83
+
84
+ /**
85
+ * Returns a [Person] reference to the object being constructed by the builder.
86
+ *
87
+ * Throws an [IllegalArgumentException] when a non-null property wasn't initialised.
88
+ *
89
+ * @return Person
90
+ */
51
91
public fun build(): Person {
52
92
if (name==null) {
53
93
throw IllegalArgumentException("Null name found when building Person.")
@@ -59,7 +99,13 @@ internal val expectedSimpleTestContent = """
59
99
}
60
100
}
61
101
}
62
-
102
+
103
+ /**
104
+ * Creates a [Person] through a DSL-style builder.
105
+ *
106
+ * @param initializer the intialisation block
107
+ * @return Person
108
+ */
63
109
@JvmSynthetic
64
110
public fun Person(initializer: Person.Builder.() -> Unit): Person =
65
111
Person.Builder().apply(initializer).build()
0 commit comments