#502 Replaced usages of System.out with logger.

This commit is contained in:
daniel-bryla
2016-10-23 19:59:03 +02:00
parent 4ca205c03c
commit 0438811489
154 changed files with 1155 additions and 792 deletions

View File

@ -22,6 +22,9 @@
*/
package com.iluwatar.strategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* The Strategy pattern (also known as the policy pattern) is a software design pattern that enables
@ -37,6 +40,8 @@ package com.iluwatar.strategy;
*/
public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
* Program entry point
*
@ -44,27 +49,27 @@ public class App {
*/
public static void main(String[] args) {
// GoF Strategy pattern
System.out.println("Green dragon spotted ahead!");
LOGGER.info("Green dragon spotted ahead!");
DragonSlayer dragonSlayer = new DragonSlayer(new MeleeStrategy());
dragonSlayer.goToBattle();
System.out.println("Red dragon emerges.");
LOGGER.info("Red dragon emerges.");
dragonSlayer.changeStrategy(new ProjectileStrategy());
dragonSlayer.goToBattle();
System.out.println("Black dragon lands before you.");
LOGGER.info("Black dragon lands before you.");
dragonSlayer.changeStrategy(new SpellStrategy());
dragonSlayer.goToBattle();
// Java 8 Strategy pattern
System.out.println("Green dragon spotted ahead!");
LOGGER.info("Green dragon spotted ahead!");
dragonSlayer = new DragonSlayer(
() -> System.out.println("With your Excalibur you severe the dragon's head!"));
() -> LOGGER.info("With your Excalibur you severe the dragon's head!"));
dragonSlayer.goToBattle();
System.out.println("Red dragon emerges.");
dragonSlayer.changeStrategy(() -> System.out.println(
LOGGER.info("Red dragon emerges.");
dragonSlayer.changeStrategy(() -> LOGGER.info(
"You shoot the dragon with the magical crossbow and it falls dead on the ground!"));
dragonSlayer.goToBattle();
System.out.println("Black dragon lands before you.");
dragonSlayer.changeStrategy(() -> System.out.println(
LOGGER.info("Black dragon lands before you.");
dragonSlayer.changeStrategy(() -> LOGGER.info(
"You cast the spell of disintegration and the dragon vaporizes in a pile of dust!"));
dragonSlayer.goToBattle();
}

View File

@ -22,6 +22,9 @@
*/
package com.iluwatar.strategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* Melee strategy.
@ -29,8 +32,10 @@ package com.iluwatar.strategy;
*/
public class MeleeStrategy implements DragonSlayingStrategy {
private static final Logger LOGGER = LoggerFactory.getLogger(MeleeStrategy.class);
@Override
public void execute() {
System.out.println("With your Excalibur you sever the dragon's head!");
LOGGER.info("With your Excalibur you sever the dragon's head!");
}
}

View File

@ -22,6 +22,9 @@
*/
package com.iluwatar.strategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* Projectile strategy.
@ -29,9 +32,10 @@ package com.iluwatar.strategy;
*/
public class ProjectileStrategy implements DragonSlayingStrategy {
private static final Logger LOGGER = LoggerFactory.getLogger(ProjectileStrategy.class);
@Override
public void execute() {
System.out
.println("You shoot the dragon with the magical crossbow and it falls dead on the ground!");
LOGGER.info("You shoot the dragon with the magical crossbow and it falls dead on the ground!");
}
}

View File

@ -22,6 +22,9 @@
*/
package com.iluwatar.strategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* Spell strategy.
@ -29,10 +32,11 @@ package com.iluwatar.strategy;
*/
public class SpellStrategy implements DragonSlayingStrategy {
private static final Logger LOGGER = LoggerFactory.getLogger(SpellStrategy.class);
@Override
public void execute() {
System.out
.println("You cast the spell of disintegration and the dragon vaporizes in a pile of dust!");
LOGGER.info("You cast the spell of disintegration and the dragon vaporizes in a pile of dust!");
}
}