X Tutup
Skip to content

Commit 81dda94

Browse files
committed
iluwatar#107 JavaDoc improvements for the Builder example
1 parent 1dc2d8d commit 81dda94

File tree

8 files changed

+157
-123
lines changed

8 files changed

+157
-123
lines changed
Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
1-
package com.iluwatar.builder;
2-
3-
import com.iluwatar. builder.Hero.HeroBuilder;
4-
5-
/**
6-
*
7-
* This is the Builder pattern variation as described by Joshua Bloch in
8-
* Effective Java 2nd Edition.
9-
*
10-
* We want to build Hero objects, but its construction is complex because of the
11-
* many parameters needed. To aid the user we introduce HeroBuilder class.
12-
* HeroBuilder takes the minimum parameters to build Hero object in its
13-
* constructor. After that additional configuration for the Hero object can be
14-
* done using the fluent HeroBuilder interface. When configuration is ready the
15-
* build method is called to receive the final Hero object.
16-
*
17-
*/
18-
public class App {
19-
20-
public static void main(String[] args) {
21-
22-
Hero mage = new HeroBuilder(Profession.MAGE, "Riobard")
23-
.withHairColor(HairColor.BLACK).withWeapon(Weapon.DAGGER)
24-
.build();
25-
System.out.println(mage);
26-
27-
Hero warrior = new HeroBuilder(Profession.WARRIOR, "Amberjill")
28-
.withHairColor(HairColor.BLOND)
29-
.withHairType(HairType.LONG_CURLY).withArmor(Armor.CHAIN_MAIL)
30-
.withWeapon(Weapon.SWORD).build();
31-
System.out.println(warrior);
32-
33-
Hero thief = new HeroBuilder(Profession.THIEF, "Desmond")
34-
.withHairType(HairType.BALD).withWeapon(Weapon.BOW).build();
35-
System.out.println(thief);
36-
37-
}
38-
}
1+
package com.iluwatar.builder;
2+
3+
import com.iluwatar. builder.Hero.HeroBuilder;
4+
5+
/**
6+
*
7+
* This is the Builder pattern variation as described by Joshua Bloch in
8+
* Effective Java 2nd Edition.
9+
* <p>
10+
* We want to build {@link Hero} objects, but its construction is complex because of the
11+
* many parameters needed. To aid the user we introduce {@link HeroBuilder} class.
12+
* {@link HeroBuilder} takes the minimum parameters to build {@link Hero} object in its
13+
* constructor. After that additional configuration for the {@link Hero} object can be
14+
* done using the fluent {@link HeroBuilder} interface. When configuration is ready the
15+
* build method is called to receive the final {@link Hero} object.
16+
*
17+
*/
18+
public class App {
19+
20+
/**
21+
* Program entry point
22+
* @param args command line args
23+
*/
24+
public static void main(String[] args) {
25+
26+
Hero mage = new HeroBuilder(Profession.MAGE, "Riobard")
27+
.withHairColor(HairColor.BLACK).withWeapon(Weapon.DAGGER)
28+
.build();
29+
System.out.println(mage);
30+
31+
Hero warrior = new HeroBuilder(Profession.WARRIOR, "Amberjill")
32+
.withHairColor(HairColor.BLOND)
33+
.withHairType(HairType.LONG_CURLY).withArmor(Armor.CHAIN_MAIL)
34+
.withWeapon(Weapon.SWORD).build();
35+
System.out.println(warrior);
36+
37+
Hero thief = new HeroBuilder(Profession.THIEF, "Desmond")
38+
.withHairType(HairType.BALD).withWeapon(Weapon.BOW).build();
39+
System.out.println(thief);
40+
41+
}
42+
}
Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
package com.iluwatar.builder;
2-
3-
public enum Armor {
4-
5-
CLOTHES("clothes"), LEATHER("leather"), CHAIN_MAIL("chain mail"), PLATE_MAIL("plate mail");
6-
7-
private String title;
8-
9-
Armor(String title) {
10-
this.title = title;
11-
}
12-
13-
@Override
14-
public String toString() {
15-
return title;
16-
}
17-
}
1+
package com.iluwatar.builder;
2+
3+
/**
4+
*
5+
* Armor enumeration
6+
*
7+
*/
8+
public enum Armor {
9+
10+
CLOTHES("clothes"), LEATHER("leather"), CHAIN_MAIL("chain mail"), PLATE_MAIL("plate mail");
11+
12+
private String title;
13+
14+
Armor(String title) {
15+
this.title = title;
16+
}
17+
18+
@Override
19+
public String toString() {
20+
return title;
21+
}
22+
}
Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
package com.iluwatar.builder;
2-
3-
public enum HairColor {
4-
5-
WHITE, BLOND, RED, BROWN, BLACK;
6-
7-
@Override
8-
public String toString() {
9-
return name().toLowerCase();
10-
}
11-
12-
}
1+
package com.iluwatar.builder;
2+
3+
/**
4+
*
5+
* HairColor enumeration
6+
*
7+
*/
8+
public enum HairColor {
9+
10+
WHITE, BLOND, RED, BROWN, BLACK;
11+
12+
@Override
13+
public String toString() {
14+
return name().toLowerCase();
15+
}
16+
17+
}
Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
package com.iluwatar.builder;
2-
3-
public enum HairType {
4-
5-
BALD("bald"), SHORT("short"), CURLY("curly"), LONG_STRAIGHT("long straight"), LONG_CURLY("long curly");
6-
7-
private String title;
8-
9-
HairType(String title) {
10-
this.title = title;
11-
}
12-
13-
@Override
14-
public String toString() {
15-
return title;
16-
}
17-
}
1+
package com.iluwatar.builder;
2+
3+
/**
4+
*
5+
* HairType enumeration
6+
*
7+
*/
8+
public enum HairType {
9+
10+
BALD("bald"), SHORT("short"), CURLY("curly"), LONG_STRAIGHT("long straight"), LONG_CURLY("long curly");
11+
12+
private String title;
13+
14+
HairType(String title) {
15+
this.title = title;
16+
}
17+
18+
@Override
19+
public String toString() {
20+
return title;
21+
}
22+
}

builder/src/main/java/com/iluwatar/builder/Hero.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
*
5-
* The class with many parameters.
5+
* Hero, the class with many parameters.
66
*
77
*/
88
public class Hero {
Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
package com.iluwatar.builder;
2-
3-
public enum Profession {
4-
5-
WARRIOR, THIEF, MAGE, PRIEST;
6-
7-
@Override
8-
public String toString() {
9-
return name().toLowerCase();
10-
}
11-
12-
}
1+
package com.iluwatar.builder;
2+
3+
/**
4+
*
5+
* Profession enumeration
6+
*
7+
*/
8+
public enum Profession {
9+
10+
WARRIOR, THIEF, MAGE, PRIEST;
11+
12+
@Override
13+
public String toString() {
14+
return name().toLowerCase();
15+
}
16+
17+
}
Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
package com.iluwatar.builder;
2-
3-
public enum Weapon {
4-
5-
DAGGER, SWORD, AXE, WARHAMMER, BOW;
6-
7-
@Override
8-
public String toString() {
9-
return name().toLowerCase();
10-
}
11-
12-
}
1+
package com.iluwatar.builder;
2+
3+
/**
4+
*
5+
* Weapon enumeration
6+
*
7+
*/
8+
public enum Weapon {
9+
10+
DAGGER, SWORD, AXE, WARHAMMER, BOW;
11+
12+
@Override
13+
public String toString() {
14+
return name().toLowerCase();
15+
}
16+
17+
}
Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
package com.iluwatar.builder;
2-
3-
import org.junit.Test;
4-
5-
import com.iluwatar. builder.App;
6-
7-
public class AppTest {
8-
9-
@Test
10-
public void test() {
11-
String[] args = {};
12-
App.main(args);
13-
}
14-
}
1+
package com.iluwatar.builder;
2+
3+
import org.junit.Test;
4+
5+
import com.iluwatar. builder.App;
6+
7+
/**
8+
*
9+
* Application test
10+
*
11+
*/
12+
public class AppTest {
13+
14+
@Test
15+
public void test() {
16+
String[] args = {};
17+
App.main(args);
18+
}
19+
}

0 commit comments

Comments
 (0)
X Tutup