Skip to content

Commit 509de97

Browse files
committed
renamed HeroBuilder to Builder
1 parent f6649a4 commit 509de97

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

builder/etc/builder.ucls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<operations public="true" package="true" protected="true" private="true" static="true"/>
2929
</display>
3030
</enumeration>
31-
<class id="4" language="java" name="com.iluwatar.builder.Hero.HeroBuilder" project="builder"
31+
<class id="4" language="java" name="com.iluwatar.builder.Hero.Builder" project="builder"
3232
file="/builder/src/main/java/com/iluwatar/builder/Hero.java" binary="false" corner="BOTTOM_RIGHT">
3333
<position height="196" width="234" x="20" y="183"/>
3434
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
package com.iluwatar.builder;
2424

25-
import com.iluwatar.builder.Hero.HeroBuilder;
25+
import com.iluwatar.builder.Hero.Builder;
2626

2727
/**
2828
*
@@ -41,10 +41,10 @@
4141
* Java 2nd Edition.
4242
* <p>
4343
* We want to build {@link Hero} objects, but its construction is complex because of the many
44-
* parameters needed. To aid the user we introduce {@link HeroBuilder} class. {@link HeroBuilder}
44+
* parameters needed. To aid the user we introduce {@link Builder} class. {@link Hero.Builder}
4545
* takes the minimum parameters to build {@link Hero} object in its constructor. After that
4646
* additional configuration for the {@link Hero} object can be done using the fluent
47-
* {@link HeroBuilder} interface. When configuration is ready the build method is called to receive
47+
* {@link Builder} interface. When configuration is ready the build method is called to receive
4848
* the final {@link Hero} object.
4949
*
5050
*/
@@ -58,18 +58,18 @@ public class App {
5858
public static void main(String[] args) {
5959

6060
Hero mage =
61-
new HeroBuilder(Profession.MAGE, "Riobard").withHairColor(HairColor.BLACK)
61+
new Hero.Builder(Profession.MAGE, "Riobard").withHairColor(HairColor.BLACK)
6262
.withWeapon(Weapon.DAGGER).build();
6363
System.out.println(mage);
6464

6565
Hero warrior =
66-
new HeroBuilder(Profession.WARRIOR, "Amberjill").withHairColor(HairColor.BLOND)
66+
new Hero.Builder(Profession.WARRIOR, "Amberjill").withHairColor(HairColor.BLOND)
6767
.withHairType(HairType.LONG_CURLY).withArmor(Armor.CHAIN_MAIL).withWeapon(Weapon.SWORD)
6868
.build();
6969
System.out.println(warrior);
7070

7171
Hero thief =
72-
new HeroBuilder(Profession.THIEF, "Desmond").withHairType(HairType.BALD)
72+
new Hero.Builder(Profession.THIEF, "Desmond").withHairType(HairType.BALD)
7373
.withWeapon(Weapon.BOW).build();
7474
System.out.println(thief);
7575

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public final class Hero {
3636
private final Armor armor;
3737
private final Weapon weapon;
3838

39-
private Hero(HeroBuilder builder) {
39+
private Hero(Builder builder) {
4040
this.profession = builder.profession;
4141
this.name = builder.name;
4242
this.hairColor = builder.hairColor;
@@ -102,7 +102,7 @@ public String toString() {
102102
* The builder class.
103103
*
104104
*/
105-
public static class HeroBuilder {
105+
public static class Builder {
106106

107107
private final Profession profession;
108108
private final String name;
@@ -114,30 +114,30 @@ public static class HeroBuilder {
114114
/**
115115
* Constructor
116116
*/
117-
public HeroBuilder(Profession profession, String name) {
117+
public Builder(Profession profession, String name) {
118118
if (profession == null || name == null) {
119119
throw new IllegalArgumentException("profession and name can not be null");
120120
}
121121
this.profession = profession;
122122
this.name = name;
123123
}
124124

125-
public HeroBuilder withHairType(HairType hairType) {
125+
public Builder withHairType(HairType hairType) {
126126
this.hairType = hairType;
127127
return this;
128128
}
129129

130-
public HeroBuilder withHairColor(HairColor hairColor) {
130+
public Builder withHairColor(HairColor hairColor) {
131131
this.hairColor = hairColor;
132132
return this;
133133
}
134134

135-
public HeroBuilder withArmor(Armor armor) {
135+
public Builder withArmor(Armor armor) {
136136
this.armor = armor;
137137
return this;
138138
}
139139

140-
public HeroBuilder withWeapon(Weapon weapon) {
140+
public Builder withWeapon(Weapon weapon) {
141141
this.weapon = weapon;
142142
return this;
143143
}

builder/src/test/java/com/iluwatar/builder/HeroTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ public class HeroTest {
3939
*/
4040
@Test(expected = IllegalArgumentException.class)
4141
public void testMissingProfession() throws Exception {
42-
new Hero.HeroBuilder(null, "Sir without a job");
42+
new Hero.Builder(null, "Sir without a job");
4343
}
4444

4545
/**
4646
* Test if we get the expected exception when trying to create a hero without a name
4747
*/
4848
@Test(expected = IllegalArgumentException.class)
4949
public void testMissingName() throws Exception {
50-
new Hero.HeroBuilder(Profession.THIEF, null);
50+
new Hero.Builder(Profession.THIEF, null);
5151
}
5252

5353
/**
@@ -57,7 +57,7 @@ public void testMissingName() throws Exception {
5757
public void testBuildHero() throws Exception {
5858
final String heroName = "Sir Lancelot";
5959

60-
final Hero hero = new Hero.HeroBuilder(Profession.WARRIOR, heroName)
60+
final Hero hero = new Hero.Builder(Profession.WARRIOR, heroName)
6161
.withArmor(Armor.CHAIN_MAIL)
6262
.withWeapon(Weapon.SWORD)
6363
.withHairType(HairType.LONG_CURLY)

0 commit comments

Comments
 (0)