Formatted all files to the same standard

This commit is contained in:
matthew 2014-10-08 13:42:12 +01:00
parent 53a2a8b150
commit 3da9ad5469
151 changed files with 952 additions and 870 deletions

View File

@ -8,7 +8,9 @@ package com.iluwatar;
public interface KingdomFactory {
Castle createCastle();
King createKing();
Army createArmy();
}

View File

@ -2,9 +2,8 @@ package com.iluwatar;
/**
*
* Adapter class. Adapts the interface of the device
* (GoblinGlider) into Engineer interface expected
* by the client (GnomeEngineeringManager).
* Adapter class. Adapts the interface of the device (GoblinGlider) into
* Engineer interface expected by the client (GnomeEngineeringManager).
*
*/
public class GnomeEngineer implements Engineer {

View File

@ -2,8 +2,7 @@ package com.iluwatar;
/**
*
* GnomeEngineering manager uses Engineer to
* operate devices.
* GnomeEngineering manager uses Engineer to operate devices.
*
*/
public class GnomeEngineeringManager implements Engineer {

View File

@ -10,19 +10,22 @@ package com.iluwatar;
public class App {
public static void main(String[] args) {
BlindingMagicWeapon blindingMagicWeapon = new BlindingMagicWeapon(new Excalibur());
BlindingMagicWeapon blindingMagicWeapon = new BlindingMagicWeapon(
new Excalibur());
blindingMagicWeapon.wield();
blindingMagicWeapon.blind();
blindingMagicWeapon.swing();
blindingMagicWeapon.unwield();
FlyingMagicWeapon flyingMagicWeapon = new FlyingMagicWeapon(new Mjollnir());
FlyingMagicWeapon flyingMagicWeapon = new FlyingMagicWeapon(
new Mjollnir());
flyingMagicWeapon.wield();
flyingMagicWeapon.fly();
flyingMagicWeapon.swing();
flyingMagicWeapon.unwield();
SoulEatingMagicWeapon soulEatingMagicWeapon = new SoulEatingMagicWeapon(new Stormbringer());
SoulEatingMagicWeapon soulEatingMagicWeapon = new SoulEatingMagicWeapon(
new Stormbringer());
soulEatingMagicWeapon.wield();
soulEatingMagicWeapon.swing();
soulEatingMagicWeapon.eatSoul();

View File

@ -19,7 +19,8 @@ public class Excalibur extends BlindingMagicWeaponImp {
@Override
public void blindImp() {
System.out.println("bright light streams from Excalibur blinding the enemy");
System.out
.println("bright light streams from Excalibur blinding the enemy");
}
}

View File

@ -19,7 +19,8 @@ public class Mjollnir extends FlyingMagicWeaponImp {
@Override
public void flyImp() {
System.out.println("Mjollnir hits the enemy in the air and returns back to the owner's hand");
System.out
.println("Mjollnir hits the enemy in the air and returns back to the owner's hand");
}
}

View File

@ -20,23 +20,18 @@ public class App {
public static void main(String[] args) {
Hero mage = new HeroBuilder(Profession.MAGE, "Riobard")
.withHairColor(HairColor.BLACK)
.withWeapon(Weapon.DAGGER)
.withHairColor(HairColor.BLACK).withWeapon(Weapon.DAGGER)
.build();
System.out.println(mage);
Hero warrior = new HeroBuilder(Profession.WARRIOR, "Amberjill")
.withHairColor(HairColor.BLOND)
.withHairType(HairType.LONG_CURLY)
.withArmor(Armor.CHAIN_MAIL)
.withWeapon(Weapon.SWORD)
.build();
.withHairType(HairType.LONG_CURLY).withArmor(Armor.CHAIN_MAIL)
.withWeapon(Weapon.SWORD).build();
System.out.println(warrior);
Hero thief = new HeroBuilder(Profession.THIEF, "Desmond")
.withHairType(HairType.BALD)
.withWeapon(Weapon.BOW)
.build();
.withHairType(HairType.BALD).withWeapon(Weapon.BOW).build();
System.out.println(thief);
}

View File

@ -8,10 +8,18 @@ public enum Armor {
public String toString() {
String s = "";
switch (this) {
case CLOTHES: s = "clothes"; break;
case LEATHER: s = "leather armor"; break;
case CHAIN_MAIL: s = "chain mail"; break;
case PLATE_MAIL: s = "plate mail"; break;
case CLOTHES:
s = "clothes";
break;
case LEATHER:
s = "leather armor";
break;
case CHAIN_MAIL:
s = "chain mail";
break;
case PLATE_MAIL:
s = "plate mail";
break;
}
return s;
}

View File

@ -8,11 +8,21 @@ public enum HairColor {
public String toString() {
String s = "";
switch (this) {
case WHITE: s = "white"; break;
case BLOND: s = "blond"; break;
case RED: s = "red"; break;
case BROWN: s = "brown"; break;
case BLACK: s = "black"; break;
case WHITE:
s = "white";
break;
case BLOND:
s = "blond";
break;
case RED:
s = "red";
break;
case BROWN:
s = "brown";
break;
case BLACK:
s = "black";
break;
}
return s;
}

View File

@ -8,11 +8,21 @@ public enum HairType {
public String toString() {
String s = "";
switch (this) {
case BALD: s = "bold"; break;
case SHORT: s = "short"; break;
case CURLY: s = "curly"; break;
case LONG_STRAIGHT: s = "long straight"; break;
case LONG_CURLY: s = "long curly"; break;
case BALD:
s = "bold";
break;
case SHORT:
s = "short";
break;
case CURLY:
s = "curly";
break;
case LONG_STRAIGHT:
s = "long straight";
break;
case LONG_CURLY:
s = "long curly";
break;
}
return s;
}

View File

@ -94,7 +94,8 @@ public class Hero {
public HeroBuilder(Profession profession, String name) {
if (profession == null || name == null) {
throw new NullPointerException("profession and name can not be null");
throw new NullPointerException(
"profession and name can not be null");
}
this.profession = profession;
this.name = name;

View File

@ -8,10 +8,18 @@ public enum Profession {
public String toString() {
String s = "";
switch (this) {
case WARRIOR: s = "Warrior"; break;
case THIEF: s = "Thief"; break;
case MAGE: s = "Mage"; break;
case PRIEST: s = "Priest"; break;
case WARRIOR:
s = "Warrior";
break;
case THIEF:
s = "Thief";
break;
case MAGE:
s = "Mage";
break;
case PRIEST:
s = "Priest";
break;
}
return s;
}

View File

@ -8,11 +8,21 @@ public enum Weapon {
public String toString() {
String s = "";
switch (this) {
case DAGGER: s = "dagger"; break;
case SWORD: s = "sword"; break;
case AXE: s = "axe"; break;
case WARHAMMER: s = "warhammer"; break;
case BOW: s = "bow"; break;
case DAGGER:
s = "dagger";
break;
case SWORD:
s = "sword";
break;
case AXE:
s = "axe";
break;
case WARHAMMER:
s = "warhammer";
break;
case BOW:
s = "bow";
break;
}
return s;
}

View File

@ -14,7 +14,8 @@ public class App {
OrcKing king = new OrcKing();
king.makeRequest(new Request(RequestType.DEFEND_CASTLE, "defend castle"));
king.makeRequest(new Request(RequestType.TORTURE_PRISONER, "torture prisoner"));
king.makeRequest(new Request(RequestType.TORTURE_PRISONER,
"torture prisoner"));
king.makeRequest(new Request(RequestType.COLLECT_TAX, "collect tax"));
}

View File

@ -2,8 +2,6 @@ package com.iluwatar;
public enum RequestType {
DEFEND_CASTLE,
TORTURE_PRISONER,
COLLECT_TAX
DEFEND_CASTLE, TORTURE_PRISONER, COLLECT_TAX
}

View File

@ -2,9 +2,7 @@ package com.iluwatar;
public enum Size {
SMALL,
NORMAL,
LARGE;
SMALL, NORMAL, LARGE;
@Override
public String toString() {
@ -27,5 +25,4 @@ public enum Size {
return s;
}
}

View File

@ -26,6 +26,7 @@ public abstract class Target {
public abstract String toString();
public void printStatus() {
System.out.println(String.format("%s, size=%s visibility=%s", this, getSize(), getVisibility()));
System.out.println(String.format("%s, size=%s visibility=%s", this,
getSize(), getVisibility()));
}
}

View File

@ -2,8 +2,7 @@ package com.iluwatar;
public enum Visibility {
VISIBLE,
INVISIBLE;
VISIBLE, INVISIBLE;
@Override
public String toString() {

View File

@ -10,15 +10,20 @@ public class Messenger {
List<Word> words = new ArrayList<Word>();
words.add(new Word(Arrays.asList(new Letter('W'), new Letter('h'), new Letter('e'), new Letter('r'), new Letter('e'))));
words.add(new Word(Arrays.asList(new Letter('t'), new Letter('h'), new Letter('e'), new Letter('r'), new Letter('e'))));
words.add(new Word(Arrays.asList(new Letter('W'), new Letter('h'),
new Letter('e'), new Letter('r'), new Letter('e'))));
words.add(new Word(Arrays.asList(new Letter('t'), new Letter('h'),
new Letter('e'), new Letter('r'), new Letter('e'))));
words.add(new Word(Arrays.asList(new Letter('i'), new Letter('s'))));
words.add(new Word(Arrays.asList(new Letter('a'))));
words.add(new Word(Arrays.asList(new Letter('w'), new Letter('h'), new Letter('i'), new Letter('p'))));
words.add(new Word(Arrays.asList(new Letter('t'), new Letter('h'), new Letter('e'), new Letter('r'), new Letter('e'))));
words.add(new Word(Arrays.asList(new Letter('w'), new Letter('h'),
new Letter('i'), new Letter('p'))));
words.add(new Word(Arrays.asList(new Letter('t'), new Letter('h'),
new Letter('e'), new Letter('r'), new Letter('e'))));
words.add(new Word(Arrays.asList(new Letter('i'), new Letter('s'))));
words.add(new Word(Arrays.asList(new Letter('a'))));
words.add(new Word(Arrays.asList(new Letter('w'), new Letter('a'), new Letter('y'))));
words.add(new Word(Arrays.asList(new Letter('w'), new Letter('a'),
new Letter('y'))));
return new Sentence(words);
@ -28,12 +33,18 @@ public class Messenger {
List<Word> words = new ArrayList<Word>();
words.add(new Word(Arrays.asList(new Letter('M'), new Letter('u'), new Letter('c'), new Letter('h'))));
words.add(new Word(Arrays.asList(new Letter('w'), new Letter('i'), new Letter('n'), new Letter('d'))));
words.add(new Word(Arrays.asList(new Letter('p'), new Letter('o'), new Letter('u'), new Letter('r'), new Letter('s'))));
words.add(new Word(Arrays.asList(new Letter('f'), new Letter('r'), new Letter('o'), new Letter('m'))));
words.add(new Word(Arrays.asList(new Letter('y'), new Letter('o'), new Letter('u'), new Letter('r'))));
words.add(new Word(Arrays.asList(new Letter('m'), new Letter('o'), new Letter('u'), new Letter('t'), new Letter('h'))));
words.add(new Word(Arrays.asList(new Letter('M'), new Letter('u'),
new Letter('c'), new Letter('h'))));
words.add(new Word(Arrays.asList(new Letter('w'), new Letter('i'),
new Letter('n'), new Letter('d'))));
words.add(new Word(Arrays.asList(new Letter('p'), new Letter('o'),
new Letter('u'), new Letter('r'), new Letter('s'))));
words.add(new Word(Arrays.asList(new Letter('f'), new Letter('r'),
new Letter('o'), new Letter('m'))));
words.add(new Word(Arrays.asList(new Letter('y'), new Letter('o'),
new Letter('u'), new Letter('r'))));
words.add(new Word(Arrays.asList(new Letter('m'), new Letter('o'),
new Letter('u'), new Letter('t'), new Letter('h'))));
return new Sentence(words);

View File

@ -20,5 +20,4 @@ public class Sentence extends LetterComposite {
System.out.print(".");
}
}

View File

@ -3,6 +3,7 @@ package com.iluwatar;
public interface Hostile {
void attack();
void fleeBattle();
}

View File

@ -19,7 +19,8 @@ public class App {
executorService.execute(new Runnable() {
@Override
public void run() {
while (inventory.addItem(new Item()));
while (inventory.addItem(new Item()))
;
}
});
}

View File

@ -5,7 +5,6 @@ import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class Inventory {
private int inventorySize;

View File

@ -8,12 +8,17 @@ public enum WeaponType {
public String toString() {
String s = "";
switch (this) {
case SHORT_SWORD: s = "short sword"; break;
case SPEAR: s = "spear"; break;
case AXE: s = "axe"; break;
case SHORT_SWORD:
s = "short sword";
break;
case SPEAR:
s = "spear";
break;
case AXE:
s = "axe";
break;
}
return s;
}
}

View File

@ -4,7 +4,8 @@ public class HealingPotion implements Potion {
@Override
public void drink() {
System.out.println("You feel healed. (Potion=" + System.identityHashCode(this) + ")");
System.out.println("You feel healed. (Potion="
+ System.identityHashCode(this) + ")");
}
}

View File

@ -4,7 +4,8 @@ public class HolyWaterPotion implements Potion {
@Override
public void drink() {
System.out.println("You feel blessed. (Potion=" + System.identityHashCode(this) + ")");
System.out.println("You feel blessed. (Potion="
+ System.identityHashCode(this) + ")");
}
}

View File

@ -4,7 +4,8 @@ public class InvisibilityPotion implements Potion {
@Override
public void drink() {
System.out.println("You become invisible. (Potion=" + System.identityHashCode(this) + ")");
System.out.println("You become invisible. (Potion="
+ System.identityHashCode(this) + ")");
}
}

View File

@ -4,7 +4,8 @@ public class PoisonPotion implements Potion {
@Override
public void drink() {
System.out.println("Urgh! This is poisonous. (Potion=" + System.identityHashCode(this) + ")");
System.out.println("Urgh! This is poisonous. (Potion="
+ System.identityHashCode(this) + ")");
}
}

View File

@ -2,10 +2,6 @@ package com.iluwatar;
public enum PotionType {
HEALING,
INVISIBILITY,
STRENGTH,
HOLY_WATER,
POISON;
HEALING, INVISIBILITY, STRENGTH, HOLY_WATER, POISON;
}

View File

@ -4,7 +4,8 @@ public class StrengthPotion implements Potion {
@Override
public void drink() {
System.out.println("You feel strong. (Potion=" + System.identityHashCode(this) + ")");
System.out.println("You feel strong. (Potion="
+ System.identityHashCode(this) + ")");
}
}

View File

@ -25,22 +25,28 @@ public class App {
if (isOperator(s)) {
Expression rightExpression = stack.pop();
Expression leftExpression = stack.pop();
System.out.println(String.format("popped from stack left: %d right: %d",
leftExpression.interpret(), rightExpression.interpret()));
System.out
.println(String.format(
"popped from stack left: %d right: %d",
leftExpression.interpret(),
rightExpression.interpret()));
Expression operator = getOperatorInstance(s, leftExpression,
rightExpression);
System.out.println(String.format("operator: %s", operator));
int result = operator.interpret();
NumberExpression resultExpression = new NumberExpression(result);
stack.push(resultExpression);
System.out.println(String.format("push result to stack: %d", resultExpression.interpret()));
System.out.println(String.format("push result to stack: %d",
resultExpression.interpret()));
} else {
Expression i = new NumberExpression(s);
stack.push(i);
System.out.println(String.format("push to stack: %d", i.interpret()));
System.out.println(String.format("push to stack: %d",
i.interpret()));
}
}
System.out.println(String.format("result: %d", stack.pop().interpret()));
System.out
.println(String.format("result: %d", stack.pop().interpret()));
}
public static boolean isOperator(String s) {

View File

@ -5,7 +5,8 @@ public class MultiplyExpression extends Expression {
private Expression leftExpression;
private Expression rightExpression;
public MultiplyExpression(Expression leftExpression, Expression rightExpression) {
public MultiplyExpression(Expression leftExpression,
Expression rightExpression) {
this.leftExpression = leftExpression;
this.rightExpression = rightExpression;
}

View File

@ -2,9 +2,6 @@ package com.iluwatar;
public enum ItemType {
ANY,
WEAPON,
RING,
POTION
ANY, WEAPON, RING, POTION
}

View File

@ -39,7 +39,8 @@ public class TreasureChestItemIterator implements ItemIterator {
tempIdx = -1;
break;
}
if (type.equals(ItemType.ANY) || items.get(tempIdx).getType().equals(type)) {
if (type.equals(ItemType.ANY)
|| items.get(tempIdx).getType().equals(type)) {
break;
}
}

View File

@ -63,6 +63,7 @@ public class Star {
@Override
public String toString() {
return String.format("%s age: %d years mass: %d tons", type.toString(), ageYears, massTons);
return String.format("%s age: %d years mass: %d tons", type.toString(),
ageYears, massTons);
}
}

View File

@ -14,18 +14,23 @@ public class StarMementoInternal implements StarMemento {
public StarType getType() {
return type;
}
public void setType(StarType type) {
this.type = type;
}
public int getAgeYears() {
return ageYears;
}
public void setAgeYears(int ageYears) {
this.ageYears = ageYears;
}
public int getMassTons() {
return massTons;
}
public void setMassTons(int massTons) {
this.massTons = massTons;
}

View File

@ -2,11 +2,7 @@ package com.iluwatar;
public enum StarType {
SUN,
RED_GIANT,
WHITE_DWARF,
SUPERNOVA,
DEAD;
SUN, RED_GIANT, WHITE_DWARF, SUPERNOVA, DEAD;
@Override
public String toString() {

View File

@ -5,8 +5,8 @@ import java.io.File;
import java.io.FileReader;
/**
* Every instance of this class represents the Model component
* in the Model-View-Presenter architectural pattern.
* Every instance of this class represents the Model component in the
* Model-View-Presenter architectural pattern.
*
* It is responsible for reading and loading the contents of a given file.
*/
@ -27,7 +27,8 @@ public class FileLoader {
*/
public String loadData() {
try {
BufferedReader br = new BufferedReader(new FileReader(new File(this.fileName)));
BufferedReader br = new BufferedReader(new FileReader(new File(
this.fileName)));
String text = "";
String line = "";
@ -51,7 +52,8 @@ public class FileLoader {
/**
* Sets the path of the file to be loaded, to the given value.
*
* @param fileName The path of the file to be loaded.
* @param fileName
* The path of the file to be loaded.
*/
public void setFileName(String fileName) {
this.fileName = fileName;

View File

@ -14,10 +14,11 @@ import javax.swing.JTextArea;
import javax.swing.JTextField;
/**
* This class is the GUI implementation of the View component
* In the Model-View-Presenter pattern.
* This class is the GUI implementation of the View component In the
* Model-View-Presenter pattern.
*/
public class FileSelectorJFrame extends JFrame implements FileSelectorView, ActionListener {
public class FileSelectorJFrame extends JFrame implements FileSelectorView,
ActionListener {
/**
* Default serial version ID.
@ -45,8 +46,7 @@ public class FileSelectorJFrame extends JFrame implements FileSelectorView, Acti
private JLabel contents;
/**
* The text field for giving the name of the file
* that we want to open.
* The text field for giving the name of the file that we want to open.
*/
private JTextField input;

View File

@ -1,10 +1,11 @@
package com.iluwatar;
/**
* Every instance of this class represents the Presenter component
* in the Model-View-Presenter architectural pattern.
* Every instance of this class represents the Presenter component in the
* Model-View-Presenter architectural pattern.
*
* It is responsible for reacting to the user's actions and update the View component.
* It is responsible for reacting to the user's actions and update the View
* component.
*/
public class FileSelectorPresenter {
@ -21,7 +22,8 @@ public class FileSelectorPresenter {
/**
* Constructor
*
* @param view The view component that the presenter will interact with.
* @param view
* The view component that the presenter will interact with.
*/
public FileSelectorPresenter(FileSelectorView view) {
this.view = view;
@ -30,7 +32,8 @@ public class FileSelectorPresenter {
/**
* Sets the FileLoader object, to the value given as parameter.
*
* @param loader The new FileLoader object(the Model component).
* @param loader
* The new FileLoader object(the Model component).
*/
public void setLoader(FileLoader loader) {
this.loader = loader;

View File

@ -1,14 +1,14 @@
package com.iluwatar;
/**
* Every instance of this class represents the Stub component in
* the Model-View-Presenter architectural pattern.
* Every instance of this class represents the Stub component in the
* Model-View-Presenter architectural pattern.
*
* The stub implements the View interface and it is useful when
* we want the test the reaction to user events, such as mouse clicks.
* The stub implements the View interface and it is useful when we want the test
* the reaction to user events, such as mouse clicks.
*
* Since we can not test the GUI directly, the MVP pattern provides
* this functionality through the View's dummy implementation, the Stub.
* Since we can not test the GUI directly, the MVP pattern provides this
* functionality through the View's dummy implementation, the Stub.
*/
public class FileSelectorStub implements FileSelectorView {

View File

@ -1,9 +1,8 @@
package com.iluwatar;
/**
* This interface represents the View component in the
* Model-View-Presenter pattern. It can be implemented
* by either the GUI components, or by the Stub.
* This interface represents the View component in the Model-View-Presenter
* pattern. It can be implemented by either the GUI components, or by the Stub.
*/
public interface FileSelectorView {
@ -25,7 +24,8 @@ public interface FileSelectorView {
/**
* Sets the presenter component, to the one given as parameter.
*
* @param presenter The new presenter component.
* @param presenter
* The new presenter component.
*/
public void setPresenter(FileSelectorPresenter presenter);
@ -37,7 +37,8 @@ public interface FileSelectorView {
/**
* Sets the file's name, to the value given as parameter.
*
* @param name The new name of the file.
* @param name
* The new name of the file.
*/
public void setFileName(String name);
@ -49,14 +50,16 @@ public interface FileSelectorView {
/**
* Displays a message to the users.
*
* @param message The message to be displayed.
* @param message
* The message to be displayed.
*/
public void showMessage(String message);
/**
* Displays the data to the view.
*
* @param data The data to be written.
* @param data
* The data to be written.
*/
public void displayData(String data);
}

View File

@ -6,8 +6,8 @@ import org.junit.Before;
import org.junit.Test;
/**
* This test case is responsible for testing our application
* by taking advantage of the Model-View-Controller architectural pattern.
* This test case is responsible for testing our application by taking advantage
* of the Model-View-Controller architectural pattern.
*/
public class FileSelectorPresenterTest {
@ -26,7 +26,6 @@ public class FileSelectorPresenterTest {
*/
private FileLoader loader;
/**
* Initializes the components of the test case.
*/
@ -64,8 +63,8 @@ public class FileSelectorPresenterTest {
}
/**
* Tests if we receive a confirmation when we attempt to open a file
* that it's name is null or an empty string.
* Tests if we receive a confirmation when we attempt to open a file that
* it's name is null or an empty string.
*/
@Test
public void fileConfirmationWhenNameIsNull() {
@ -80,8 +79,8 @@ public class FileSelectorPresenterTest {
}
/**
* Tests if we receive a confirmation when we attempt to open a file
* that it doesn't exist.
* Tests if we receive a confirmation when we attempt to open a file that it
* doesn't exist.
*/
@Test
public void fileConfirmationWhenFileDoesNotExist() {

View File

@ -6,7 +6,8 @@ public class Hobbits implements WeatherObserver {
public void update(WeatherType currentWeather) {
switch (currentWeather) {
case COLD:
System.out.println("The hobbits are shivering in the cold weather.");
System.out
.println("The hobbits are shivering in the cold weather.");
break;
case RAINY:
System.out.println("The hobbits look for cover from the rain.");
@ -15,7 +16,8 @@ public class Hobbits implements WeatherObserver {
System.out.println("The happy hobbits bade in the warm sun.");
break;
case WINDY:
System.out.println("The hobbits hold their hats tightly in the windy weather.");
System.out
.println("The hobbits hold their hats tightly in the windy weather.");
break;
default:
break;

View File

@ -5,8 +5,8 @@ import java.util.List;
/**
*
* Weather can be observed by implementing WeatherObserver
* interface and registering as listener.
* Weather can be observed by implementing WeatherObserver interface and
* registering as listener.
*
*/
public class Weather {

View File

@ -2,10 +2,7 @@ package com.iluwatar;
public enum WeatherType {
SUNNY,
RAINY,
WINDY,
COLD;
SUNNY, RAINY, WINDY, COLD;
public String toString() {
return this.name().toLowerCase();

View File

@ -15,7 +15,8 @@ public class App {
Warlord warlord;
Beast beast;
factory = new HeroFactoryImpl(new ElfMage(), new ElfWarlord(), new ElfBeast());
factory = new HeroFactoryImpl(new ElfMage(), new ElfWarlord(),
new ElfBeast());
mage = factory.createMage();
warlord = factory.createWarlord();
beast = factory.createBeast();
@ -23,7 +24,8 @@ public class App {
System.out.println(warlord);
System.out.println(beast);
factory = new HeroFactoryImpl(new OrcMage(), new OrcWarlord(), new OrcBeast());
factory = new HeroFactoryImpl(new OrcMage(), new OrcWarlord(),
new OrcBeast());
mage = factory.createMage();
warlord = factory.createWarlord();
beast = factory.createBeast();

View File

@ -9,7 +9,8 @@ public class IvoryTower {
private static IvoryTower instance = new IvoryTower();
private IvoryTower() {}
private IvoryTower() {
}
public static IvoryTower getInstance() {
return instance;

View File

@ -4,7 +4,8 @@ public class ProjectileStrategy implements DragonSlayingStrategy {
@Override
public void execute() {
System.out.println("You shoot the dragon with the magical crossbow and it falls dead on the ground!");
System.out
.println("You shoot the dragon with the magical crossbow and it falls dead on the ground!");
}
}

View File

@ -4,7 +4,8 @@ public class SpellStrategy implements DragonSlayingStrategy {
@Override
public void execute() {
System.out.println("You cast the spell of disintegration and the dragon vaporizes in a pile of dust!");
System.out
.println("You cast the spell of disintegration and the dragon vaporizes in a pile of dust!");
}
}

View File

@ -9,12 +9,14 @@ public class SubtleMethod extends StealingMethod {
@Override
protected void confuseTarget(String target) {
System.out.println("Approach the " + target + " with tears running and hug him!");
System.out.println("Approach the " + target
+ " with tears running and hug him!");
}
@Override
protected void stealTheItem(String target) {
System.out.println("While in close contact grab the " + target + "'s wallet.");
System.out.println("While in close contact grab the " + target
+ "'s wallet.");
}
}

View File

@ -11,9 +11,9 @@ public class App {
public static void main(String[] args) {
Commander commander = new Commander(
new Sergeant(new Soldier(), new Soldier(), new Soldier()),
new Sergeant(new Soldier(), new Soldier(), new Soldier()));
Commander commander = new Commander(new Sergeant(new Soldier(),
new Soldier(), new Soldier()), new Sergeant(new Soldier(),
new Soldier(), new Soldier()));
commander.accept(new SoldierVisitor());
commander.accept(new SergeantVisitor());
commander.accept(new CommanderVisitor());

View File

@ -8,7 +8,9 @@ package com.iluwatar;
public interface UnitVisitor {
void visitSoldier(Soldier soldier);
void visitSergeant(Sergeant sergeant);
void visitCommander(Commander commander);
}