Merge pull request #281 from ankurkaushal/master

Reformat according to google style guide
This commit is contained in:
Ilkka Seppälä
2015-11-02 21:39:17 +02:00
438 changed files with 8257 additions and 8382 deletions

View File

@@ -2,28 +2,29 @@ package com.iluwatar.strategy;
/**
*
* The Strategy pattern (also known as the policy pattern) is a software design pattern that
* enables an algorithm's behavior to be selected at runtime.
* The Strategy pattern (also known as the policy pattern) is a software design pattern that enables
* an algorithm's behavior to be selected at runtime.
* <p>
* In this example ({@link DragonSlayingStrategy}) encapsulates an algorithm. The containing
* object ({@link DragonSlayer}) can alter its behavior by changing its strategy.
* In this example ({@link DragonSlayingStrategy}) encapsulates an algorithm. The containing object
* ({@link DragonSlayer}) can alter its behavior by changing its strategy.
*
*/
public class App {
/**
* Program entry point
* @param args command line args
*/
public static void main(String[] args) {
System.out.println("Green dragon spotted ahead!");
DragonSlayer dragonSlayer = new DragonSlayer(new MeleeStrategy());
dragonSlayer.goToBattle();
System.out.println("Red dragon emerges.");
dragonSlayer.changeStrategy(new ProjectileStrategy());
dragonSlayer.goToBattle();
System.out.println("Black dragon lands before you.");
dragonSlayer.changeStrategy(new SpellStrategy());
dragonSlayer.goToBattle();
}
/**
* Program entry point
*
* @param args command line args
*/
public static void main(String[] args) {
System.out.println("Green dragon spotted ahead!");
DragonSlayer dragonSlayer = new DragonSlayer(new MeleeStrategy());
dragonSlayer.goToBattle();
System.out.println("Red dragon emerges.");
dragonSlayer.changeStrategy(new ProjectileStrategy());
dragonSlayer.goToBattle();
System.out.println("Black dragon lands before you.");
dragonSlayer.changeStrategy(new SpellStrategy());
dragonSlayer.goToBattle();
}
}

View File

@@ -7,17 +7,17 @@ package com.iluwatar.strategy;
*/
public class DragonSlayer {
private DragonSlayingStrategy strategy;
private DragonSlayingStrategy strategy;
public DragonSlayer(DragonSlayingStrategy strategy) {
this.strategy = strategy;
}
public DragonSlayer(DragonSlayingStrategy strategy) {
this.strategy = strategy;
}
public void changeStrategy(DragonSlayingStrategy strategy) {
this.strategy = strategy;
}
public void changeStrategy(DragonSlayingStrategy strategy) {
this.strategy = strategy;
}
public void goToBattle() {
strategy.execute();
}
public void goToBattle() {
strategy.execute();
}
}

View File

@@ -7,6 +7,6 @@ package com.iluwatar.strategy;
*/
public interface DragonSlayingStrategy {
void execute();
void execute();
}

View File

@@ -7,9 +7,8 @@ package com.iluwatar.strategy;
*/
public class MeleeStrategy implements DragonSlayingStrategy {
@Override
public void execute() {
System.out.println("With your Excalibur you severe the dragon's head!");
}
@Override
public void execute() {
System.out.println("With your Excalibur you severe the dragon's head!");
}
}

View File

@@ -7,10 +7,9 @@ package com.iluwatar.strategy;
*/
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!");
}
@Override
public void execute() {
System.out
.println("You shoot the dragon with the magical crossbow and it falls dead on the ground!");
}
}

View File

@@ -7,10 +7,10 @@ package com.iluwatar.strategy;
*/
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!");
}
@Override
public void execute() {
System.out
.println("You cast the spell of disintegration and the dragon vaporizes in a pile of dust!");
}
}

View File

@@ -11,9 +11,9 @@ import com.iluwatar.strategy.App;
*/
public class AppTest {
@Test
public void test() {
String[] args = {};
App.main(args);
}
@Test
public void test() {
String[] args = {};
App.main(args);
}
}