#107 JavaDoc improvements for the Builder example

This commit is contained in:
Ilkka Seppala 2015-08-18 21:37:07 +03:00
parent 1dc2d8d0c7
commit 81dda94abd
8 changed files with 157 additions and 123 deletions

View File

@ -1,38 +1,42 @@
package com.iluwatar.builder; package com.iluwatar.builder;
import com.iluwatar. builder.Hero.HeroBuilder; import com.iluwatar. builder.Hero.HeroBuilder;
/** /**
* *
* This is the Builder pattern variation as described by Joshua Bloch in * This is the Builder pattern variation as described by Joshua Bloch in
* Effective Java 2nd Edition. * Effective Java 2nd Edition.
* * <p>
* We want to build Hero objects, but its construction is complex because of the * We want to build {@link Hero} objects, but its construction is complex because of the
* many parameters needed. To aid the user we introduce HeroBuilder class. * many parameters needed. To aid the user we introduce {@link HeroBuilder} class.
* HeroBuilder takes the minimum parameters to build Hero object in its * {@link HeroBuilder} takes the minimum parameters to build {@link Hero} object in its
* constructor. After that additional configuration for the Hero object can be * constructor. After that additional configuration for the {@link Hero} object can be
* done using the fluent HeroBuilder interface. When configuration is ready the * done using the fluent {@link HeroBuilder} interface. When configuration is ready the
* build method is called to receive the final Hero object. * build method is called to receive the final {@link Hero} object.
* *
*/ */
public class App { public class App {
public static void main(String[] args) { /**
* Program entry point
Hero mage = new HeroBuilder(Profession.MAGE, "Riobard") * @param args command line args
.withHairColor(HairColor.BLACK).withWeapon(Weapon.DAGGER) */
.build(); public static void main(String[] args) {
System.out.println(mage);
Hero mage = new HeroBuilder(Profession.MAGE, "Riobard")
Hero warrior = new HeroBuilder(Profession.WARRIOR, "Amberjill") .withHairColor(HairColor.BLACK).withWeapon(Weapon.DAGGER)
.withHairColor(HairColor.BLOND) .build();
.withHairType(HairType.LONG_CURLY).withArmor(Armor.CHAIN_MAIL) System.out.println(mage);
.withWeapon(Weapon.SWORD).build();
System.out.println(warrior); Hero warrior = new HeroBuilder(Profession.WARRIOR, "Amberjill")
.withHairColor(HairColor.BLOND)
Hero thief = new HeroBuilder(Profession.THIEF, "Desmond") .withHairType(HairType.LONG_CURLY).withArmor(Armor.CHAIN_MAIL)
.withHairType(HairType.BALD).withWeapon(Weapon.BOW).build(); .withWeapon(Weapon.SWORD).build();
System.out.println(thief); System.out.println(warrior);
} Hero thief = new HeroBuilder(Profession.THIEF, "Desmond")
} .withHairType(HairType.BALD).withWeapon(Weapon.BOW).build();
System.out.println(thief);
}
}

View File

@ -1,17 +1,22 @@
package com.iluwatar.builder; package com.iluwatar.builder;
public enum Armor { /**
*
CLOTHES("clothes"), LEATHER("leather"), CHAIN_MAIL("chain mail"), PLATE_MAIL("plate mail"); * Armor enumeration
*
private String title; */
public enum Armor {
Armor(String title) {
this.title = title; CLOTHES("clothes"), LEATHER("leather"), CHAIN_MAIL("chain mail"), PLATE_MAIL("plate mail");
}
private String title;
@Override
public String toString() { Armor(String title) {
return title; this.title = title;
} }
}
@Override
public String toString() {
return title;
}
}

View File

@ -1,12 +1,17 @@
package com.iluwatar.builder; package com.iluwatar.builder;
public enum HairColor { /**
*
WHITE, BLOND, RED, BROWN, BLACK; * HairColor enumeration
*
@Override */
public String toString() { public enum HairColor {
return name().toLowerCase();
} WHITE, BLOND, RED, BROWN, BLACK;
} @Override
public String toString() {
return name().toLowerCase();
}
}

View File

@ -1,17 +1,22 @@
package com.iluwatar.builder; package com.iluwatar.builder;
public enum HairType { /**
*
BALD("bald"), SHORT("short"), CURLY("curly"), LONG_STRAIGHT("long straight"), LONG_CURLY("long curly"); * HairType enumeration
*
private String title; */
public enum HairType {
HairType(String title) {
this.title = title; BALD("bald"), SHORT("short"), CURLY("curly"), LONG_STRAIGHT("long straight"), LONG_CURLY("long curly");
}
private String title;
@Override
public String toString() { HairType(String title) {
return title; this.title = title;
} }
}
@Override
public String toString() {
return title;
}
}

View File

@ -2,7 +2,7 @@ package com.iluwatar.builder;
/** /**
* *
* The class with many parameters. * Hero, the class with many parameters.
* *
*/ */
public class Hero { public class Hero {

View File

@ -1,12 +1,17 @@
package com.iluwatar.builder; package com.iluwatar.builder;
public enum Profession { /**
*
WARRIOR, THIEF, MAGE, PRIEST; * Profession enumeration
*
@Override */
public String toString() { public enum Profession {
return name().toLowerCase();
} WARRIOR, THIEF, MAGE, PRIEST;
} @Override
public String toString() {
return name().toLowerCase();
}
}

View File

@ -1,12 +1,17 @@
package com.iluwatar.builder; package com.iluwatar.builder;
public enum Weapon { /**
*
DAGGER, SWORD, AXE, WARHAMMER, BOW; * Weapon enumeration
*
@Override */
public String toString() { public enum Weapon {
return name().toLowerCase();
} DAGGER, SWORD, AXE, WARHAMMER, BOW;
} @Override
public String toString() {
return name().toLowerCase();
}
}

View File

@ -1,14 +1,19 @@
package com.iluwatar.builder; package com.iluwatar.builder;
import org.junit.Test; import org.junit.Test;
import com.iluwatar. builder.App; import com.iluwatar. builder.App;
public class AppTest { /**
*
@Test * Application test
public void test() { *
String[] args = {}; */
App.main(args); public class AppTest {
}
} @Test
public void test() {
String[] args = {};
App.main(args);
}
}