#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

@ -25,6 +25,8 @@ package com.iluwatar.observer;
import com.iluwatar.observer.generic.GHobbits;
import com.iluwatar.observer.generic.GOrcs;
import com.iluwatar.observer.generic.GWeather;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
@ -41,6 +43,8 @@ import com.iluwatar.observer.generic.GWeather;
*/
public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
* Program entry point
*
@ -58,7 +62,7 @@ public class App {
weather.timePasses();
// Generic observer inspired by Java Generics and Collection by Naftalin & Wadler
System.out.println("\n--Running generic version--");
LOGGER.info("--Running generic version--");
GWeather gWeather = new GWeather();
gWeather.addObserver(new GOrcs());
gWeather.addObserver(new GHobbits());

View File

@ -22,6 +22,9 @@
*/
package com.iluwatar.observer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* Hobbits
@ -29,20 +32,22 @@ package com.iluwatar.observer;
*/
public class Hobbits implements WeatherObserver {
private static final Logger LOGGER = LoggerFactory.getLogger(Hobbits.class);
@Override
public void update(WeatherType currentWeather) {
switch (currentWeather) {
case COLD:
System.out.println("The hobbits are shivering in the cold weather.");
LOGGER.info("The hobbits are shivering in the cold weather.");
break;
case RAINY:
System.out.println("The hobbits look for cover from the rain.");
LOGGER.info("The hobbits look for cover from the rain.");
break;
case SUNNY:
System.out.println("The happy hobbits bade in the warm sun.");
LOGGER.info("The happy hobbits bade in the warm sun.");
break;
case WINDY:
System.out.println("The hobbits hold their hats tightly in the windy weather.");
LOGGER.info("The hobbits hold their hats tightly in the windy weather.");
break;
default:
break;

View File

@ -22,6 +22,9 @@
*/
package com.iluwatar.observer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* Orcs
@ -29,20 +32,22 @@ package com.iluwatar.observer;
*/
public class Orcs implements WeatherObserver {
private static final Logger LOGGER = LoggerFactory.getLogger(Orcs.class);
@Override
public void update(WeatherType currentWeather) {
switch (currentWeather) {
case COLD:
System.out.println("The orcs are freezing cold.");
LOGGER.info("The orcs are freezing cold.");
break;
case RAINY:
System.out.println("The orcs are dripping wet.");
LOGGER.info("The orcs are dripping wet.");
break;
case SUNNY:
System.out.println("The sun hurts the orcs' eyes.");
LOGGER.info("The sun hurts the orcs' eyes.");
break;
case WINDY:
System.out.println("The orc smell almost vanishes in the wind.");
LOGGER.info("The orc smell almost vanishes in the wind.");
break;
default:
break;

View File

@ -22,6 +22,9 @@
*/
package com.iluwatar.observer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
@ -33,6 +36,8 @@ import java.util.List;
*/
public class Weather {
private static final Logger LOGGER = LoggerFactory.getLogger(Weather.class);
private WeatherType currentWeather;
private List<WeatherObserver> observers;
@ -55,7 +60,7 @@ public class Weather {
public void timePasses() {
WeatherType[] enumValues = WeatherType.values();
currentWeather = enumValues[(currentWeather.ordinal() + 1) % enumValues.length];
System.out.println("The weather changed to " + currentWeather + ".");
LOGGER.info("The weather changed to {}.", currentWeather);
notifyObservers();
}

View File

@ -23,6 +23,8 @@
package com.iluwatar.observer.generic;
import com.iluwatar.observer.WeatherType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
@ -30,20 +32,23 @@ import com.iluwatar.observer.WeatherType;
*
*/
public class GHobbits implements Race {
private static final Logger LOGGER = LoggerFactory.getLogger(GHobbits.class);
@Override
public void update(GWeather weather, WeatherType weatherType) {
switch (weatherType) {
case COLD:
System.out.println("The hobbits are shivering in the cold weather.");
LOGGER.info("The hobbits are shivering in the cold weather.");
break;
case RAINY:
System.out.println("The hobbits look for cover from the rain.");
LOGGER.info("The hobbits look for cover from the rain.");
break;
case SUNNY:
System.out.println("The happy hobbits bade in the warm sun.");
LOGGER.info("The happy hobbits bade in the warm sun.");
break;
case WINDY:
System.out.println("The hobbits hold their hats tightly in the windy weather.");
LOGGER.info("The hobbits hold their hats tightly in the windy weather.");
break;
default:
break;

View File

@ -23,6 +23,8 @@
package com.iluwatar.observer.generic;
import com.iluwatar.observer.WeatherType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
@ -31,20 +33,22 @@ import com.iluwatar.observer.WeatherType;
*/
public class GOrcs implements Race {
private static final Logger LOGGER = LoggerFactory.getLogger(GOrcs.class);
@Override
public void update(GWeather weather, WeatherType weatherType) {
switch (weatherType) {
case COLD:
System.out.println("The orcs are freezing cold.");
LOGGER.info("The orcs are freezing cold.");
break;
case RAINY:
System.out.println("The orcs are dripping wet.");
LOGGER.info("The orcs are dripping wet.");
break;
case SUNNY:
System.out.println("The sun hurts the orcs' eyes.");
LOGGER.info("The sun hurts the orcs' eyes.");
break;
case WINDY:
System.out.println("The orc smell almost vanishes in the wind.");
LOGGER.info("The orc smell almost vanishes in the wind.");
break;
default:
break;

View File

@ -23,6 +23,8 @@
package com.iluwatar.observer.generic;
import com.iluwatar.observer.WeatherType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
@ -31,6 +33,8 @@ import com.iluwatar.observer.WeatherType;
*/
public class GWeather extends Observable<GWeather, Race, WeatherType> {
private static final Logger LOGGER = LoggerFactory.getLogger(GWeather.class);
private WeatherType currentWeather;
public GWeather() {
@ -43,7 +47,7 @@ public class GWeather extends Observable<GWeather, Race, WeatherType> {
public void timePasses() {
WeatherType[] enumValues = WeatherType.values();
currentWeather = enumValues[(currentWeather.ordinal() + 1) % enumValues.length];
System.out.println("The weather changed to " + currentWeather + ".");
LOGGER.info("The weather changed to {}.", currentWeather);
notifyObservers(currentWeather);
}
}