#502 Replaced usages of System.out with logger.
This commit is contained in:
parent
4ca205c03c
commit
0438811489
@ -27,6 +27,8 @@ import com.iluwatar.abstractdocument.domain.HasModel;
|
|||||||
import com.iluwatar.abstractdocument.domain.HasParts;
|
import com.iluwatar.abstractdocument.domain.HasParts;
|
||||||
import com.iluwatar.abstractdocument.domain.HasPrice;
|
import com.iluwatar.abstractdocument.domain.HasPrice;
|
||||||
import com.iluwatar.abstractdocument.domain.HasType;
|
import com.iluwatar.abstractdocument.domain.HasType;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -44,11 +46,13 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the App
|
* Executes the App
|
||||||
*/
|
*/
|
||||||
public App() {
|
public App() {
|
||||||
System.out.println("Constructing parts and car");
|
LOGGER.info("Constructing parts and car");
|
||||||
|
|
||||||
Map<String, Object> carProperties = new HashMap<>();
|
Map<String, Object> carProperties = new HashMap<>();
|
||||||
carProperties.put(HasModel.PROPERTY, "300SL");
|
carProperties.put(HasModel.PROPERTY, "300SL");
|
||||||
@ -68,12 +72,11 @@ public class App {
|
|||||||
|
|
||||||
Car car = new Car(carProperties);
|
Car car = new Car(carProperties);
|
||||||
|
|
||||||
System.out.println("Here is our car:");
|
LOGGER.info("Here is our car:");
|
||||||
System.out.println("-> model: " + car.getModel().get());
|
LOGGER.info("-> model: {}", car.getModel().get());
|
||||||
System.out.println("-> price: " + car.getPrice().get());
|
LOGGER.info("-> price: {}", car.getPrice().get());
|
||||||
System.out.println("-> parts: ");
|
LOGGER.info("-> parts: ");
|
||||||
car.getParts().forEach(p -> System.out
|
car.getParts().forEach(p -> LOGGER.info("\t{}/{}/{}", p.getType().get(), p.getModel().get(), p.getPrice().get()));
|
||||||
.println("\t" + p.getType().get() + "/" + p.getModel().get() + "/" + p.getPrice().get()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.abstractfactory;
|
package com.iluwatar.abstractfactory;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* The Abstract Factory pattern provides a way to encapsulate a group of individual factories that have a common theme
|
* The Abstract Factory pattern provides a way to encapsulate a group of individual factories that have a common theme
|
||||||
@ -39,6 +42,8 @@ package com.iluwatar.abstractfactory;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
private King king;
|
private King king;
|
||||||
private Castle castle;
|
private Castle castle;
|
||||||
private Army army;
|
private Army army;
|
||||||
@ -98,17 +103,17 @@ public class App {
|
|||||||
|
|
||||||
App app = new App();
|
App app = new App();
|
||||||
|
|
||||||
System.out.println("Elf Kingdom");
|
LOGGER.info("Elf Kingdom");
|
||||||
app.createKingdom(new ElfKingdomFactory());
|
app.createKingdom(new ElfKingdomFactory());
|
||||||
System.out.println(app.getArmy().getDescription());
|
LOGGER.info(app.getArmy().getDescription());
|
||||||
System.out.println(app.getCastle().getDescription());
|
LOGGER.info(app.getCastle().getDescription());
|
||||||
System.out.println(app.getKing().getDescription());
|
LOGGER.info(app.getKing().getDescription());
|
||||||
|
|
||||||
System.out.println("\nOrc Kingdom");
|
LOGGER.info("Orc Kingdom");
|
||||||
app.createKingdom(new OrcKingdomFactory());
|
app.createKingdom(new OrcKingdomFactory());
|
||||||
System.out.println(app.getArmy().getDescription());
|
LOGGER.info(app.getArmy().getDescription());
|
||||||
System.out.println(app.getCastle().getDescription());
|
LOGGER.info(app.getCastle().getDescription());
|
||||||
System.out.println(app.getKing().getDescription());
|
LOGGER.info(app.getKing().getDescription());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.adapter;
|
package com.iluwatar.adapter;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Adapter class. Adapts the interface of the device ({@link FishingBoat}) into {@link BattleShip}
|
* Adapter class. Adapts the interface of the device ({@link FishingBoat}) into {@link BattleShip}
|
||||||
@ -33,6 +36,8 @@ package com.iluwatar.adapter;
|
|||||||
*/
|
*/
|
||||||
public class BattleFishingBoat implements BattleShip {
|
public class BattleFishingBoat implements BattleShip {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(BattleFishingBoat.class);
|
||||||
|
|
||||||
private FishingBoat boat;
|
private FishingBoat boat;
|
||||||
|
|
||||||
public BattleFishingBoat() {
|
public BattleFishingBoat() {
|
||||||
@ -41,7 +46,7 @@ public class BattleFishingBoat implements BattleShip {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fire() {
|
public void fire() {
|
||||||
System.out.println("fire!");
|
LOGGER.info("fire!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.adapter;
|
package com.iluwatar.adapter;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Device class (adaptee in the pattern). We want to reuse this class
|
* Device class (adaptee in the pattern). We want to reuse this class
|
||||||
@ -29,12 +32,14 @@ package com.iluwatar.adapter;
|
|||||||
*/
|
*/
|
||||||
public class FishingBoat {
|
public class FishingBoat {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(FishingBoat.class);
|
||||||
|
|
||||||
public void sail() {
|
public void sail() {
|
||||||
System.out.println("The Boat is moving to that place");
|
LOGGER.info("The Boat is moving to that place");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fish() {
|
public void fish() {
|
||||||
System.out.println("fishing ...");
|
LOGGER.info("fishing ...");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,8 @@ import org.apache.http.client.methods.HttpGet;
|
|||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -37,6 +39,8 @@ import java.io.IOException;
|
|||||||
@Component
|
@Component
|
||||||
public class ProductInformationClientImpl implements ProductInformationClient {
|
public class ProductInformationClientImpl implements ProductInformationClient {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(ProductInformationClientImpl.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProductTitle() {
|
public String getProductTitle() {
|
||||||
String response = null;
|
String response = null;
|
||||||
@ -46,7 +50,7 @@ public class ProductInformationClientImpl implements ProductInformationClient {
|
|||||||
response = EntityUtils.toString(httpResponse.getEntity());
|
response = EntityUtils.toString(httpResponse.getEntity());
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
LOGGER.error("Exception caught.", e);
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,8 @@ import org.apache.http.client.methods.HttpGet;
|
|||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -37,6 +39,8 @@ import java.io.IOException;
|
|||||||
@Component
|
@Component
|
||||||
public class ProductInventoryClientImpl implements ProductInventoryClient {
|
public class ProductInventoryClientImpl implements ProductInventoryClient {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(ProductInventoryClientImpl.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getProductInventories() {
|
public int getProductInventories() {
|
||||||
String response = "0";
|
String response = "0";
|
||||||
@ -46,7 +50,7 @@ public class ProductInventoryClientImpl implements ProductInventoryClient {
|
|||||||
response = EntityUtils.toString(httpResponse.getEntity());
|
response = EntityUtils.toString(httpResponse.getEntity());
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
LOGGER.error("Exception caught.", e);
|
||||||
}
|
}
|
||||||
return Integer.parseInt(response);
|
return Integer.parseInt(response);
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.async.method.invocation;
|
package com.iluwatar.async.method.invocation;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,6 +57,8 @@ import java.util.concurrent.Callable;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point
|
||||||
*/
|
*/
|
||||||
@ -120,6 +125,6 @@ public class App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void log(String msg) {
|
private static void log(String msg) {
|
||||||
System.out.println(String.format("[%1$-10s] - %2$s", Thread.currentThread().getName(), msg));
|
LOGGER.info(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.bridge;
|
package com.iluwatar.bridge;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Excalibur
|
* Excalibur
|
||||||
@ -29,23 +32,25 @@ package com.iluwatar.bridge;
|
|||||||
*/
|
*/
|
||||||
public class Excalibur extends BlindingMagicWeaponImpl {
|
public class Excalibur extends BlindingMagicWeaponImpl {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Excalibur.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void wieldImp() {
|
public void wieldImp() {
|
||||||
System.out.println("wielding Excalibur");
|
LOGGER.info("wielding Excalibur");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void swingImp() {
|
public void swingImp() {
|
||||||
System.out.println("swinging Excalibur");
|
LOGGER.info("swinging Excalibur");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unwieldImp() {
|
public void unwieldImp() {
|
||||||
System.out.println("unwielding Excalibur");
|
LOGGER.info("unwielding Excalibur");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void blindImp() {
|
public void blindImp() {
|
||||||
System.out.println("bright light streams from Excalibur blinding the enemy");
|
LOGGER.info("bright light streams from Excalibur blinding the enemy");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.bridge;
|
package com.iluwatar.bridge;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Mjollnir
|
* Mjollnir
|
||||||
@ -29,23 +32,25 @@ package com.iluwatar.bridge;
|
|||||||
*/
|
*/
|
||||||
public class Mjollnir extends FlyingMagicWeaponImpl {
|
public class Mjollnir extends FlyingMagicWeaponImpl {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Mjollnir.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void wieldImp() {
|
public void wieldImp() {
|
||||||
System.out.println("wielding Mjollnir");
|
LOGGER.info("wielding Mjollnir");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void swingImp() {
|
public void swingImp() {
|
||||||
System.out.println("swinging Mjollnir");
|
LOGGER.info("swinging Mjollnir");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unwieldImp() {
|
public void unwieldImp() {
|
||||||
System.out.println("unwielding Mjollnir");
|
LOGGER.info("unwielding Mjollnir");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void flyImp() {
|
public void flyImp() {
|
||||||
System.out.println("Mjollnir hits the enemy in the air and returns back to the owner's hand");
|
LOGGER.info("Mjollnir hits the enemy in the air and returns back to the owner's hand");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.bridge;
|
package com.iluwatar.bridge;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Stormbringer
|
* Stormbringer
|
||||||
@ -29,23 +32,25 @@ package com.iluwatar.bridge;
|
|||||||
*/
|
*/
|
||||||
public class Stormbringer extends SoulEatingMagicWeaponImpl {
|
public class Stormbringer extends SoulEatingMagicWeaponImpl {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Stormbringer.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void wieldImp() {
|
public void wieldImp() {
|
||||||
System.out.println("wielding Stormbringer");
|
LOGGER.info("wielding Stormbringer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void swingImp() {
|
public void swingImp() {
|
||||||
System.out.println("swinging Stormbringer");
|
LOGGER.info("swinging Stormbringer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unwieldImp() {
|
public void unwieldImp() {
|
||||||
System.out.println("unwielding Stormbringer");
|
LOGGER.info("unwielding Stormbringer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void eatSoulImp() {
|
public void eatSoulImp() {
|
||||||
System.out.println("Stormbringer devours the enemy's soul");
|
LOGGER.info("Stormbringer devours the enemy's soul");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
package com.iluwatar.builder;
|
package com.iluwatar.builder;
|
||||||
|
|
||||||
import com.iluwatar.builder.Hero.Builder;
|
import com.iluwatar.builder.Hero.Builder;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -50,6 +52,8 @@ import com.iluwatar.builder.Hero.Builder;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point
|
||||||
*
|
*
|
||||||
@ -60,18 +64,18 @@ public class App {
|
|||||||
Hero mage =
|
Hero mage =
|
||||||
new Hero.Builder(Profession.MAGE, "Riobard").withHairColor(HairColor.BLACK)
|
new Hero.Builder(Profession.MAGE, "Riobard").withHairColor(HairColor.BLACK)
|
||||||
.withWeapon(Weapon.DAGGER).build();
|
.withWeapon(Weapon.DAGGER).build();
|
||||||
System.out.println(mage);
|
LOGGER.info(mage.toString());
|
||||||
|
|
||||||
Hero warrior =
|
Hero warrior =
|
||||||
new Hero.Builder(Profession.WARRIOR, "Amberjill").withHairColor(HairColor.BLOND)
|
new Hero.Builder(Profession.WARRIOR, "Amberjill").withHairColor(HairColor.BLOND)
|
||||||
.withHairType(HairType.LONG_CURLY).withArmor(Armor.CHAIN_MAIL).withWeapon(Weapon.SWORD)
|
.withHairType(HairType.LONG_CURLY).withArmor(Armor.CHAIN_MAIL).withWeapon(Weapon.SWORD)
|
||||||
.build();
|
.build();
|
||||||
System.out.println(warrior);
|
LOGGER.info(warrior.toString());
|
||||||
|
|
||||||
Hero thief =
|
Hero thief =
|
||||||
new Hero.Builder(Profession.THIEF, "Desmond").withHairType(HairType.BALD)
|
new Hero.Builder(Profession.THIEF, "Desmond").withHairType(HairType.BALD)
|
||||||
.withWeapon(Weapon.BOW).build();
|
.withWeapon(Weapon.BOW).build();
|
||||||
System.out.println(thief);
|
LOGGER.info(thief.toString());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.business.delegate;
|
package com.iluwatar.business.delegate;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Service EJB implementation
|
* Service EJB implementation
|
||||||
@ -29,8 +32,10 @@ package com.iluwatar.business.delegate;
|
|||||||
*/
|
*/
|
||||||
public class EjbService implements BusinessService {
|
public class EjbService implements BusinessService {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(EjbService.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doProcessing() {
|
public void doProcessing() {
|
||||||
System.out.println("EjbService is now processing");
|
LOGGER.info("EjbService is now processing");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.business.delegate;
|
package com.iluwatar.business.delegate;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Service JMS implementation
|
* Service JMS implementation
|
||||||
@ -29,8 +32,10 @@ package com.iluwatar.business.delegate;
|
|||||||
*/
|
*/
|
||||||
public class JmsService implements BusinessService {
|
public class JmsService implements BusinessService {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(JmsService.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doProcessing() {
|
public void doProcessing() {
|
||||||
System.out.println("JmsService is now processing");
|
LOGGER.info("JmsService is now processing");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.caching;
|
package com.iluwatar.caching;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* The Caching pattern describes how to avoid expensive re-acquisition of resources by not releasing
|
* The Caching pattern describes how to avoid expensive re-acquisition of resources by not releasing
|
||||||
@ -59,6 +62,9 @@ package com.iluwatar.caching;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point
|
||||||
*
|
*
|
||||||
@ -80,13 +86,13 @@ public class App {
|
|||||||
* Read-through and write-through
|
* Read-through and write-through
|
||||||
*/
|
*/
|
||||||
public void useReadAndWriteThroughStrategy() {
|
public void useReadAndWriteThroughStrategy() {
|
||||||
System.out.println("# CachingPolicy.THROUGH");
|
LOGGER.info("# CachingPolicy.THROUGH");
|
||||||
AppManager.initCachingPolicy(CachingPolicy.THROUGH);
|
AppManager.initCachingPolicy(CachingPolicy.THROUGH);
|
||||||
|
|
||||||
UserAccount userAccount1 = new UserAccount("001", "John", "He is a boy.");
|
UserAccount userAccount1 = new UserAccount("001", "John", "He is a boy.");
|
||||||
|
|
||||||
AppManager.save(userAccount1);
|
AppManager.save(userAccount1);
|
||||||
System.out.println(AppManager.printCacheContent());
|
LOGGER.info(AppManager.printCacheContent());
|
||||||
AppManager.find("001");
|
AppManager.find("001");
|
||||||
AppManager.find("001");
|
AppManager.find("001");
|
||||||
}
|
}
|
||||||
@ -95,21 +101,21 @@ public class App {
|
|||||||
* Read-through and write-around
|
* Read-through and write-around
|
||||||
*/
|
*/
|
||||||
public void useReadThroughAndWriteAroundStrategy() {
|
public void useReadThroughAndWriteAroundStrategy() {
|
||||||
System.out.println("# CachingPolicy.AROUND");
|
LOGGER.info("# CachingPolicy.AROUND");
|
||||||
AppManager.initCachingPolicy(CachingPolicy.AROUND);
|
AppManager.initCachingPolicy(CachingPolicy.AROUND);
|
||||||
|
|
||||||
UserAccount userAccount2 = new UserAccount("002", "Jane", "She is a girl.");
|
UserAccount userAccount2 = new UserAccount("002", "Jane", "She is a girl.");
|
||||||
|
|
||||||
AppManager.save(userAccount2);
|
AppManager.save(userAccount2);
|
||||||
System.out.println(AppManager.printCacheContent());
|
LOGGER.info(AppManager.printCacheContent());
|
||||||
AppManager.find("002");
|
AppManager.find("002");
|
||||||
System.out.println(AppManager.printCacheContent());
|
LOGGER.info(AppManager.printCacheContent());
|
||||||
userAccount2 = AppManager.find("002");
|
userAccount2 = AppManager.find("002");
|
||||||
userAccount2.setUserName("Jane G.");
|
userAccount2.setUserName("Jane G.");
|
||||||
AppManager.save(userAccount2);
|
AppManager.save(userAccount2);
|
||||||
System.out.println(AppManager.printCacheContent());
|
LOGGER.info(AppManager.printCacheContent());
|
||||||
AppManager.find("002");
|
AppManager.find("002");
|
||||||
System.out.println(AppManager.printCacheContent());
|
LOGGER.info(AppManager.printCacheContent());
|
||||||
AppManager.find("002");
|
AppManager.find("002");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +123,7 @@ public class App {
|
|||||||
* Read-through and write-behind
|
* Read-through and write-behind
|
||||||
*/
|
*/
|
||||||
public void useReadThroughAndWriteBehindStrategy() {
|
public void useReadThroughAndWriteBehindStrategy() {
|
||||||
System.out.println("# CachingPolicy.BEHIND");
|
LOGGER.info("# CachingPolicy.BEHIND");
|
||||||
AppManager.initCachingPolicy(CachingPolicy.BEHIND);
|
AppManager.initCachingPolicy(CachingPolicy.BEHIND);
|
||||||
|
|
||||||
UserAccount userAccount3 = new UserAccount("003", "Adam", "He likes food.");
|
UserAccount userAccount3 = new UserAccount("003", "Adam", "He likes food.");
|
||||||
@ -127,13 +133,13 @@ public class App {
|
|||||||
AppManager.save(userAccount3);
|
AppManager.save(userAccount3);
|
||||||
AppManager.save(userAccount4);
|
AppManager.save(userAccount4);
|
||||||
AppManager.save(userAccount5);
|
AppManager.save(userAccount5);
|
||||||
System.out.println(AppManager.printCacheContent());
|
LOGGER.info(AppManager.printCacheContent());
|
||||||
AppManager.find("003");
|
AppManager.find("003");
|
||||||
System.out.println(AppManager.printCacheContent());
|
LOGGER.info(AppManager.printCacheContent());
|
||||||
UserAccount userAccount6 = new UserAccount("006", "Yasha", "She is an only child.");
|
UserAccount userAccount6 = new UserAccount("006", "Yasha", "She is an only child.");
|
||||||
AppManager.save(userAccount6);
|
AppManager.save(userAccount6);
|
||||||
System.out.println(AppManager.printCacheContent());
|
LOGGER.info(AppManager.printCacheContent());
|
||||||
AppManager.find("004");
|
AppManager.find("004");
|
||||||
System.out.println(AppManager.printCacheContent());
|
LOGGER.info(AppManager.printCacheContent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.caching;
|
package com.iluwatar.caching;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,6 +34,8 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class CacheStore {
|
public class CacheStore {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(CacheStore.class);
|
||||||
|
|
||||||
static LruCache cache;
|
static LruCache cache;
|
||||||
|
|
||||||
private CacheStore() {
|
private CacheStore() {
|
||||||
@ -52,10 +57,10 @@ public class CacheStore {
|
|||||||
*/
|
*/
|
||||||
public static UserAccount readThrough(String userId) {
|
public static UserAccount readThrough(String userId) {
|
||||||
if (cache.contains(userId)) {
|
if (cache.contains(userId)) {
|
||||||
System.out.println("# Cache Hit!");
|
LOGGER.info("# Cache Hit!");
|
||||||
return cache.get(userId);
|
return cache.get(userId);
|
||||||
}
|
}
|
||||||
System.out.println("# Cache Miss!");
|
LOGGER.info("# Cache Miss!");
|
||||||
UserAccount userAccount = DbManager.readFromDb(userId);
|
UserAccount userAccount = DbManager.readFromDb(userId);
|
||||||
cache.set(userId, userAccount);
|
cache.set(userId, userAccount);
|
||||||
return userAccount;
|
return userAccount;
|
||||||
@ -91,13 +96,13 @@ public class CacheStore {
|
|||||||
*/
|
*/
|
||||||
public static UserAccount readThroughWithWriteBackPolicy(String userId) {
|
public static UserAccount readThroughWithWriteBackPolicy(String userId) {
|
||||||
if (cache.contains(userId)) {
|
if (cache.contains(userId)) {
|
||||||
System.out.println("# Cache Hit!");
|
LOGGER.info("# Cache Hit!");
|
||||||
return cache.get(userId);
|
return cache.get(userId);
|
||||||
}
|
}
|
||||||
System.out.println("# Cache Miss!");
|
LOGGER.info("# Cache Miss!");
|
||||||
UserAccount userAccount = DbManager.readFromDb(userId);
|
UserAccount userAccount = DbManager.readFromDb(userId);
|
||||||
if (cache.isFull()) {
|
if (cache.isFull()) {
|
||||||
System.out.println("# Cache is FULL! Writing LRU data to DB...");
|
LOGGER.info("# Cache is FULL! Writing LRU data to DB...");
|
||||||
UserAccount toBeWrittenToDb = cache.getLruData();
|
UserAccount toBeWrittenToDb = cache.getLruData();
|
||||||
DbManager.upsertDb(toBeWrittenToDb);
|
DbManager.upsertDb(toBeWrittenToDb);
|
||||||
}
|
}
|
||||||
@ -110,7 +115,7 @@ public class CacheStore {
|
|||||||
*/
|
*/
|
||||||
public static void writeBehind(UserAccount userAccount) {
|
public static void writeBehind(UserAccount userAccount) {
|
||||||
if (cache.isFull() && !cache.contains(userAccount.getUserId())) {
|
if (cache.isFull() && !cache.contains(userAccount.getUserId())) {
|
||||||
System.out.println("# Cache is FULL! Writing LRU data to DB...");
|
LOGGER.info("# Cache is FULL! Writing LRU data to DB...");
|
||||||
UserAccount toBeWrittenToDb = cache.getLruData();
|
UserAccount toBeWrittenToDb = cache.getLruData();
|
||||||
DbManager.upsertDb(toBeWrittenToDb);
|
DbManager.upsertDb(toBeWrittenToDb);
|
||||||
}
|
}
|
||||||
@ -130,7 +135,7 @@ public class CacheStore {
|
|||||||
* Writes remaining content in the cache into the DB.
|
* Writes remaining content in the cache into the DB.
|
||||||
*/
|
*/
|
||||||
public static void flushCache() {
|
public static void flushCache() {
|
||||||
System.out.println("# flushCache...");
|
LOGGER.info("# flushCache...");
|
||||||
if (null == cache) {
|
if (null == cache) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.caching;
|
package com.iluwatar.caching;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -38,6 +41,8 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class LruCache {
|
public class LruCache {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(LruCache.class);
|
||||||
|
|
||||||
class Node {
|
class Node {
|
||||||
String userId;
|
String userId;
|
||||||
UserAccount userAccount;
|
UserAccount userAccount;
|
||||||
@ -117,7 +122,7 @@ public class LruCache {
|
|||||||
} else {
|
} else {
|
||||||
Node newNode = new Node(userId, userAccount);
|
Node newNode = new Node(userId, userAccount);
|
||||||
if (cache.size() >= capacity) {
|
if (cache.size() >= capacity) {
|
||||||
System.out.println("# Cache is FULL! Removing " + end.userId + " from cache...");
|
LOGGER.info("# Cache is FULL! Removing {} from cache...", end.userId);
|
||||||
cache.remove(end.userId); // remove LRU data from cache.
|
cache.remove(end.userId); // remove LRU data from cache.
|
||||||
remove(end);
|
remove(end);
|
||||||
setHead(newNode);
|
setHead(newNode);
|
||||||
@ -136,7 +141,7 @@ public class LruCache {
|
|||||||
* Invalidate cache for user
|
* Invalidate cache for user
|
||||||
*/
|
*/
|
||||||
public void invalidate(String userId) {
|
public void invalidate(String userId) {
|
||||||
System.out.println("# " + userId + " has been updated! Removing older version from cache...");
|
LOGGER.info("# {} has been updated! Removing older version from cache...", userId);
|
||||||
Node toBeRemoved = cache.get(userId);
|
Node toBeRemoved = cache.get(userId);
|
||||||
remove(toBeRemoved);
|
remove(toBeRemoved);
|
||||||
cache.remove(userId);
|
cache.remove(userId);
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.callback;
|
package com.iluwatar.callback;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Callback pattern is more native for functional languages where functions are treated as
|
* Callback pattern is more native for functional languages where functions are treated as
|
||||||
@ -31,6 +34,8 @@ package com.iluwatar.callback;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point
|
||||||
*/
|
*/
|
||||||
@ -39,7 +44,7 @@ public class App {
|
|||||||
Callback callback = new Callback() {
|
Callback callback = new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void call() {
|
public void call() {
|
||||||
System.out.println("I'm done now.");
|
LOGGER.info("I'm done now.");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
task.executeWith(callback);
|
task.executeWith(callback);
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.callback;
|
package com.iluwatar.callback;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* This example generates the exact same output as {@link App} however the callback has been
|
* This example generates the exact same output as {@link App} however the callback has been
|
||||||
@ -30,12 +33,14 @@ package com.iluwatar.callback;
|
|||||||
*/
|
*/
|
||||||
public class LambdasApp {
|
public class LambdasApp {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(LambdasApp.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Task task = new SimpleTask();
|
Task task = new SimpleTask();
|
||||||
Callback c = () -> System.out.println("I'm done now.");
|
Callback c = () -> LOGGER.info("I'm done now.");
|
||||||
task.executeWith(c);
|
task.executeWith(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.callback;
|
package com.iluwatar.callback;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Implementation of task that need to be executed
|
* Implementation of task that need to be executed
|
||||||
@ -29,8 +32,10 @@ package com.iluwatar.callback;
|
|||||||
*/
|
*/
|
||||||
public class SimpleTask extends Task {
|
public class SimpleTask extends Task {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(SimpleTask.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
System.out.println("Perform some important activity and after call the callback method.");
|
LOGGER.info("Perform some important activity and after call the callback method.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.chain;
|
package com.iluwatar.chain;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* RequestHandler
|
* RequestHandler
|
||||||
@ -29,6 +32,8 @@ package com.iluwatar.chain;
|
|||||||
*/
|
*/
|
||||||
public abstract class RequestHandler {
|
public abstract class RequestHandler {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(RequestHandler.class);
|
||||||
|
|
||||||
private RequestHandler next;
|
private RequestHandler next;
|
||||||
|
|
||||||
public RequestHandler(RequestHandler next) {
|
public RequestHandler(RequestHandler next) {
|
||||||
@ -45,7 +50,7 @@ public abstract class RequestHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void printHandling(Request req) {
|
protected void printHandling(Request req) {
|
||||||
System.out.println(this + " handling request \"" + req + "\"");
|
LOGGER.info("{} handling request \"{}\"", this, req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.command;
|
package com.iluwatar.command;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Base class for spell targets.
|
* Base class for spell targets.
|
||||||
@ -29,6 +32,8 @@ package com.iluwatar.command;
|
|||||||
*/
|
*/
|
||||||
public abstract class Target {
|
public abstract class Target {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Target.class);
|
||||||
|
|
||||||
private Size size;
|
private Size size;
|
||||||
|
|
||||||
private Visibility visibility;
|
private Visibility visibility;
|
||||||
@ -56,8 +61,6 @@ public abstract class Target {
|
|||||||
* Print status
|
* Print status
|
||||||
*/
|
*/
|
||||||
public void printStatus() {
|
public void printStatus() {
|
||||||
System.out.println(String.format("%s, [size=%s] [visibility=%s]", this, getSize(),
|
LOGGER.info("{}, [size={}] [visibility={}]", this, getSize(), getVisibility());
|
||||||
getVisibility()));
|
|
||||||
System.out.println();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.command;
|
package com.iluwatar.command;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
@ -32,6 +35,8 @@ import java.util.LinkedList;
|
|||||||
*/
|
*/
|
||||||
public class Wizard {
|
public class Wizard {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Wizard.class);
|
||||||
|
|
||||||
private Deque<Command> undoStack = new LinkedList<>();
|
private Deque<Command> undoStack = new LinkedList<>();
|
||||||
private Deque<Command> redoStack = new LinkedList<>();
|
private Deque<Command> redoStack = new LinkedList<>();
|
||||||
|
|
||||||
@ -41,7 +46,7 @@ public class Wizard {
|
|||||||
* Cast spell
|
* Cast spell
|
||||||
*/
|
*/
|
||||||
public void castSpell(Command command, Target target) {
|
public void castSpell(Command command, Target target) {
|
||||||
System.out.println(this + " casts " + command + " at " + target);
|
LOGGER.info("{} casts {} at {}", this, command, target);
|
||||||
command.execute(target);
|
command.execute(target);
|
||||||
undoStack.offerLast(command);
|
undoStack.offerLast(command);
|
||||||
}
|
}
|
||||||
@ -53,7 +58,7 @@ public class Wizard {
|
|||||||
if (!undoStack.isEmpty()) {
|
if (!undoStack.isEmpty()) {
|
||||||
Command previousSpell = undoStack.pollLast();
|
Command previousSpell = undoStack.pollLast();
|
||||||
redoStack.offerLast(previousSpell);
|
redoStack.offerLast(previousSpell);
|
||||||
System.out.println(this + " undoes " + previousSpell);
|
LOGGER.info("{} undoes {}", this, previousSpell);
|
||||||
previousSpell.undo();
|
previousSpell.undo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,7 +70,7 @@ public class Wizard {
|
|||||||
if (!redoStack.isEmpty()) {
|
if (!redoStack.isEmpty()) {
|
||||||
Command previousSpell = redoStack.pollLast();
|
Command previousSpell = redoStack.pollLast();
|
||||||
undoStack.offerLast(previousSpell);
|
undoStack.offerLast(previousSpell);
|
||||||
System.out.println(this + " redoes " + previousSpell);
|
LOGGER.info("{} redoes {}", this, previousSpell);
|
||||||
previousSpell.redo();
|
previousSpell.redo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.composite;
|
package com.iluwatar.composite;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Composite pattern is a partitioning design pattern. The Composite pattern describes that a
|
* The Composite pattern is a partitioning design pattern. The Composite pattern describes that a
|
||||||
* group of objects is to be treated in the same way as a single instance of an object. The intent
|
* group of objects is to be treated in the same way as a single instance of an object. The intent
|
||||||
@ -35,20 +38,22 @@ package com.iluwatar.composite;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point
|
||||||
*
|
*
|
||||||
* @param args command line args
|
* @param args command line args
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("Message from the orcs: ");
|
LOGGER.info("Message from the orcs: ");
|
||||||
|
|
||||||
LetterComposite orcMessage = new Messenger().messageFromOrcs();
|
LetterComposite orcMessage = new Messenger().messageFromOrcs();
|
||||||
orcMessage.print();
|
orcMessage.print();
|
||||||
|
|
||||||
System.out.println("\n");
|
LOGGER.info("\n");
|
||||||
|
|
||||||
System.out.println("Message from the elves: ");
|
LOGGER.info("Message from the elves: ");
|
||||||
|
|
||||||
LetterComposite elfMessage = new Messenger().messageFromElves();
|
LetterComposite elfMessage = new Messenger().messageFromElves();
|
||||||
elfMessage.print();
|
elfMessage.print();
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.composite;
|
package com.iluwatar.composite;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Letter
|
* Letter
|
||||||
@ -29,6 +32,8 @@ package com.iluwatar.composite;
|
|||||||
*/
|
*/
|
||||||
public class Letter extends LetterComposite {
|
public class Letter extends LetterComposite {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Letter.class);
|
||||||
|
|
||||||
private char c;
|
private char c;
|
||||||
|
|
||||||
public Letter(char c) {
|
public Letter(char c) {
|
||||||
@ -37,7 +42,7 @@ public class Letter extends LetterComposite {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void printThisBefore() {
|
protected void printThisBefore() {
|
||||||
System.out.print(c);
|
LOGGER.info(String.valueOf(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.composite;
|
package com.iluwatar.composite;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,6 +34,8 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class Sentence extends LetterComposite {
|
public class Sentence extends LetterComposite {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Sentence.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
@ -47,6 +52,6 @@ public class Sentence extends LetterComposite {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void printThisAfter() {
|
protected void printThisAfter() {
|
||||||
System.out.print(".");
|
LOGGER.info(".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.composite;
|
package com.iluwatar.composite;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,6 +34,8 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class Word extends LetterComposite {
|
public class Word extends LetterComposite {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Word.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
@ -42,7 +47,7 @@ public class Word extends LetterComposite {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void printThisBefore() {
|
protected void printThisBefore() {
|
||||||
System.out.print(" ");
|
LOGGER.info(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.decorator;
|
package com.iluwatar.decorator;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* The Decorator pattern is a more flexible alternative to subclassing. The Decorator class
|
* The Decorator pattern is a more flexible alternative to subclassing. The Decorator class
|
||||||
@ -36,6 +39,8 @@ package com.iluwatar.decorator;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point
|
||||||
*
|
*
|
||||||
@ -44,17 +49,17 @@ public class App {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
// simple troll
|
// simple troll
|
||||||
System.out.println("A simple looking troll approaches.");
|
LOGGER.info("A simple looking troll approaches.");
|
||||||
Hostile troll = new Troll();
|
Hostile troll = new Troll();
|
||||||
troll.attack();
|
troll.attack();
|
||||||
troll.fleeBattle();
|
troll.fleeBattle();
|
||||||
System.out.printf("Simple troll power %d.\n", troll.getAttackPower());
|
LOGGER.info("Simple troll power {}.\n", troll.getAttackPower());
|
||||||
|
|
||||||
// change the behavior of the simple troll by adding a decorator
|
// change the behavior of the simple troll by adding a decorator
|
||||||
System.out.println("\nA smart looking troll surprises you.");
|
LOGGER.info("A smart looking troll surprises you.");
|
||||||
Hostile smart = new SmartHostile(troll);
|
Hostile smart = new SmartHostile(troll);
|
||||||
smart.attack();
|
smart.attack();
|
||||||
smart.fleeBattle();
|
smart.fleeBattle();
|
||||||
System.out.printf("Smart troll power %d.\n", smart.getAttackPower());
|
LOGGER.info("Smart troll power {}.\n", smart.getAttackPower());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.decorator;
|
package com.iluwatar.decorator;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SmartHostile is a decorator for {@link Hostile} objects. The calls to the {@link Hostile} interface
|
* SmartHostile is a decorator for {@link Hostile} objects. The calls to the {@link Hostile} interface
|
||||||
* are intercepted and decorated. Finally the calls are delegated to the decorated {@link Hostile}
|
* are intercepted and decorated. Finally the calls are delegated to the decorated {@link Hostile}
|
||||||
@ -30,6 +33,8 @@ package com.iluwatar.decorator;
|
|||||||
*/
|
*/
|
||||||
public class SmartHostile implements Hostile {
|
public class SmartHostile implements Hostile {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(SmartHostile.class);
|
||||||
|
|
||||||
private Hostile decorated;
|
private Hostile decorated;
|
||||||
|
|
||||||
public SmartHostile(Hostile decorated) {
|
public SmartHostile(Hostile decorated) {
|
||||||
@ -38,7 +43,7 @@ public class SmartHostile implements Hostile {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void attack() {
|
public void attack() {
|
||||||
System.out.println("It throws a rock at you!");
|
LOGGER.info("It throws a rock at you!");
|
||||||
decorated.attack();
|
decorated.attack();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +55,7 @@ public class SmartHostile implements Hostile {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fleeBattle() {
|
public void fleeBattle() {
|
||||||
System.out.println("It calls for help!");
|
LOGGER.info("It calls for help!");
|
||||||
decorated.fleeBattle();
|
decorated.fleeBattle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.decorator;
|
package com.iluwatar.decorator;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Troll implements {@link Hostile} interface directly.
|
* Troll implements {@link Hostile} interface directly.
|
||||||
@ -29,9 +32,11 @@ package com.iluwatar.decorator;
|
|||||||
*/
|
*/
|
||||||
public class Troll implements Hostile {
|
public class Troll implements Hostile {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Troll.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void attack() {
|
public void attack() {
|
||||||
System.out.println("The troll swings at you with a club!");
|
LOGGER.info("The troll swings at you with a club!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -41,6 +46,6 @@ public class Troll implements Hostile {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fleeBattle() {
|
public void fleeBattle() {
|
||||||
System.out.println("The troll shrieks in horror and runs away!");
|
LOGGER.info("The troll shrieks in horror and runs away!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
package com.iluwatar.delegation.simple.printers;
|
package com.iluwatar.delegation.simple.printers;
|
||||||
|
|
||||||
import com.iluwatar.delegation.simple.Printer;
|
import com.iluwatar.delegation.simple.Printer;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specialised Implementation of {@link Printer} for a Canon Printer, in
|
* Specialised Implementation of {@link Printer} for a Canon Printer, in
|
||||||
@ -32,12 +34,14 @@ import com.iluwatar.delegation.simple.Printer;
|
|||||||
*/
|
*/
|
||||||
public class CanonPrinter implements Printer {
|
public class CanonPrinter implements Printer {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(CanonPrinter.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void print(String message) {
|
public void print(String message) {
|
||||||
System.out.print("Canon Printer : " + message);
|
LOGGER.info("Canon Printer : {}", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
package com.iluwatar.delegation.simple.printers;
|
package com.iluwatar.delegation.simple.printers;
|
||||||
|
|
||||||
import com.iluwatar.delegation.simple.Printer;
|
import com.iluwatar.delegation.simple.Printer;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specialised Implementation of {@link Printer} for a Epson Printer, in
|
* Specialised Implementation of {@link Printer} for a Epson Printer, in
|
||||||
@ -32,12 +34,14 @@ import com.iluwatar.delegation.simple.Printer;
|
|||||||
*/
|
*/
|
||||||
public class EpsonPrinter implements Printer {
|
public class EpsonPrinter implements Printer {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(EpsonPrinter.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void print(String message) {
|
public void print(String message) {
|
||||||
System.out.print("Epson Printer : " + message);
|
LOGGER.info("Epson Printer : {}", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
package com.iluwatar.delegation.simple.printers;
|
package com.iluwatar.delegation.simple.printers;
|
||||||
|
|
||||||
import com.iluwatar.delegation.simple.Printer;
|
import com.iluwatar.delegation.simple.Printer;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specialised Implementation of {@link Printer} for a HP Printer, in
|
* Specialised Implementation of {@link Printer} for a HP Printer, in
|
||||||
@ -32,12 +34,14 @@ import com.iluwatar.delegation.simple.Printer;
|
|||||||
*/
|
*/
|
||||||
public class HpPrinter implements Printer {
|
public class HpPrinter implements Printer {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(HpPrinter.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void print(String message) {
|
public void print(String message) {
|
||||||
System.out.print("HP Printer : " + message);
|
LOGGER.info("HP Printer : {}", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.dependency.injection;
|
package com.iluwatar.dependency.injection;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Tobacco abstraction
|
* Tobacco abstraction
|
||||||
@ -29,8 +32,10 @@ package com.iluwatar.dependency.injection;
|
|||||||
*/
|
*/
|
||||||
public abstract class Tobacco {
|
public abstract class Tobacco {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Tobacco.class);
|
||||||
|
|
||||||
public void smoke(Wizard wizard) {
|
public void smoke(Wizard wizard) {
|
||||||
System.out.println(String.format("%s smoking %s", wizard.getClass().getSimpleName(), this
|
LOGGER.info("{} smoking {}", wizard.getClass().getSimpleName(),
|
||||||
.getClass().getSimpleName()));
|
this.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.doublechecked.locking;
|
package com.iluwatar.doublechecked.locking;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -40,6 +43,8 @@ import java.util.concurrent.TimeUnit;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point
|
||||||
*
|
*
|
||||||
@ -58,7 +63,7 @@ public class App {
|
|||||||
try {
|
try {
|
||||||
executorService.awaitTermination(5, TimeUnit.SECONDS);
|
executorService.awaitTermination(5, TimeUnit.SECONDS);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
System.out.println("Error waiting for ExecutorService shutdown");
|
LOGGER.error("Error waiting for ExecutorService shutdown");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.doublechecked.locking;
|
package com.iluwatar.doublechecked.locking;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -35,6 +38,8 @@ import java.util.concurrent.locks.ReentrantLock;
|
|||||||
*/
|
*/
|
||||||
public class Inventory {
|
public class Inventory {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Inventory.class);
|
||||||
|
|
||||||
private final int inventorySize;
|
private final int inventorySize;
|
||||||
private final List<Item> items;
|
private final List<Item> items;
|
||||||
private final Lock lock;
|
private final Lock lock;
|
||||||
@ -57,8 +62,7 @@ public class Inventory {
|
|||||||
try {
|
try {
|
||||||
if (items.size() < inventorySize) {
|
if (items.size() < inventorySize) {
|
||||||
items.add(item);
|
items.add(item);
|
||||||
System.out.println(Thread.currentThread() + ": items.size()=" + items.size()
|
LOGGER.info("{}: items.size()={}, inventorySize={}", Thread.currentThread(), items.size(), inventorySize);
|
||||||
+ ", inventorySize=" + inventorySize);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.doubledispatch;
|
package com.iluwatar.doubledispatch;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -45,6 +48,8 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point
|
||||||
*
|
*
|
||||||
@ -58,8 +63,8 @@ public class App {
|
|||||||
objects.add(new SpaceStationMir(1, 1, 2, 2));
|
objects.add(new SpaceStationMir(1, 1, 2, 2));
|
||||||
objects.add(new Meteoroid(10, 10, 15, 15));
|
objects.add(new Meteoroid(10, 10, 15, 15));
|
||||||
objects.add(new SpaceStationIss(12, 12, 14, 14));
|
objects.add(new SpaceStationIss(12, 12, 14, 14));
|
||||||
objects.stream().forEach(o -> System.out.println(o));
|
objects.stream().forEach(o -> LOGGER.info(o.toString()));
|
||||||
System.out.println("");
|
LOGGER.info("");
|
||||||
|
|
||||||
// collision check
|
// collision check
|
||||||
objects.stream().forEach(o1 -> objects.stream().forEach(o2 -> {
|
objects.stream().forEach(o1 -> objects.stream().forEach(o2 -> {
|
||||||
@ -67,10 +72,10 @@ public class App {
|
|||||||
o1.collision(o2);
|
o1.collision(o2);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
System.out.println("");
|
LOGGER.info("");
|
||||||
|
|
||||||
// output eventual object statuses
|
// output eventual object statuses
|
||||||
objects.stream().forEach(o -> System.out.println(o));
|
objects.stream().forEach(o -> LOGGER.info(o.toString()));
|
||||||
System.out.println("");
|
LOGGER.info("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.doubledispatch;
|
package com.iluwatar.doubledispatch;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Meteoroid game object
|
* Meteoroid game object
|
||||||
@ -29,6 +32,8 @@ package com.iluwatar.doubledispatch;
|
|||||||
*/
|
*/
|
||||||
public class Meteoroid extends GameObject {
|
public class Meteoroid extends GameObject {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Meteoroid.class);
|
||||||
|
|
||||||
public Meteoroid(int left, int top, int right, int bottom) {
|
public Meteoroid(int left, int top, int right, int bottom) {
|
||||||
super(left, top, right, bottom);
|
super(left, top, right, bottom);
|
||||||
}
|
}
|
||||||
@ -40,25 +45,21 @@ public class Meteoroid extends GameObject {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void collisionResolve(FlamingAsteroid asteroid) {
|
public void collisionResolve(FlamingAsteroid asteroid) {
|
||||||
System.out.println(String.format("%s hits %s.", asteroid.getClass().getSimpleName(), this
|
LOGGER.info("{} hits {}.", asteroid.getClass().getSimpleName(), this.getClass().getSimpleName());
|
||||||
.getClass().getSimpleName()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void collisionResolve(Meteoroid meteoroid) {
|
public void collisionResolve(Meteoroid meteoroid) {
|
||||||
System.out.println(String.format("%s hits %s.", meteoroid.getClass().getSimpleName(), this
|
LOGGER.info("{} hits {}.", meteoroid.getClass().getSimpleName(), this.getClass().getSimpleName());
|
||||||
.getClass().getSimpleName()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void collisionResolve(SpaceStationMir mir) {
|
public void collisionResolve(SpaceStationMir mir) {
|
||||||
System.out.println(String.format("%s hits %s.", mir.getClass().getSimpleName(), this.getClass()
|
LOGGER.info("{} hits {}.", mir.getClass().getSimpleName(), this.getClass().getSimpleName());
|
||||||
.getSimpleName()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void collisionResolve(SpaceStationIss iss) {
|
public void collisionResolve(SpaceStationIss iss) {
|
||||||
System.out.println(String.format("%s hits %s.", iss.getClass().getSimpleName(), this.getClass()
|
LOGGER.info("{} hits {}.", iss.getClass().getSimpleName(), this.getClass().getSimpleName());
|
||||||
.getSimpleName()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.doubledispatch;
|
package com.iluwatar.doubledispatch;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Space station Mir game object
|
* Space station Mir game object
|
||||||
@ -29,6 +32,8 @@ package com.iluwatar.doubledispatch;
|
|||||||
*/
|
*/
|
||||||
public class SpaceStationMir extends GameObject {
|
public class SpaceStationMir extends GameObject {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(SpaceStationMir.class);
|
||||||
|
|
||||||
public SpaceStationMir(int left, int top, int right, int bottom) {
|
public SpaceStationMir(int left, int top, int right, int bottom) {
|
||||||
super(left, top, right, bottom);
|
super(left, top, right, bottom);
|
||||||
}
|
}
|
||||||
@ -40,31 +45,30 @@ public class SpaceStationMir extends GameObject {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void collisionResolve(FlamingAsteroid asteroid) {
|
public void collisionResolve(FlamingAsteroid asteroid) {
|
||||||
System.out.println(String.format("%s hits %s. %s is damaged! %s is set on fire!", asteroid
|
LOGGER.info("{} hits {}. {} is damaged! {} is set on fire!", asteroid.getClass().getSimpleName(),
|
||||||
.getClass().getSimpleName(), this.getClass().getSimpleName(), this.getClass()
|
this.getClass().getSimpleName(), this.getClass().getSimpleName(), this.getClass().getSimpleName());
|
||||||
.getSimpleName(), this.getClass().getSimpleName()));
|
|
||||||
setDamaged(true);
|
setDamaged(true);
|
||||||
setOnFire(true);
|
setOnFire(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void collisionResolve(Meteoroid meteoroid) {
|
public void collisionResolve(Meteoroid meteoroid) {
|
||||||
System.out.println(String.format("%s hits %s. %s is damaged!", meteoroid.getClass()
|
LOGGER.info("{} hits {}. {} is damaged!", meteoroid.getClass().getSimpleName(),
|
||||||
.getSimpleName(), this.getClass().getSimpleName(), this.getClass().getSimpleName()));
|
this.getClass().getSimpleName(), this.getClass().getSimpleName());
|
||||||
setDamaged(true);
|
setDamaged(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void collisionResolve(SpaceStationMir mir) {
|
public void collisionResolve(SpaceStationMir mir) {
|
||||||
System.out.println(String.format("%s hits %s. %s is damaged!", mir.getClass().getSimpleName(),
|
LOGGER.info("{} hits {}. {} is damaged!", mir.getClass().getSimpleName(),
|
||||||
this.getClass().getSimpleName(), this.getClass().getSimpleName()));
|
this.getClass().getSimpleName(), this.getClass().getSimpleName());
|
||||||
setDamaged(true);
|
setDamaged(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void collisionResolve(SpaceStationIss iss) {
|
public void collisionResolve(SpaceStationIss iss) {
|
||||||
System.out.println(String.format("%s hits %s. %s is damaged!", iss.getClass().getSimpleName(),
|
LOGGER.info("{} hits {}. {} is damaged!", iss.getClass().getSimpleName(),
|
||||||
this.getClass().getSimpleName(), this.getClass().getSimpleName()));
|
this.getClass().getSimpleName(), this.getClass().getSimpleName());
|
||||||
setDamaged(true);
|
setDamaged(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.event.aggregator;
|
package com.iluwatar.event.aggregator;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* KingJoffrey observes events from {@link KingsHand}.
|
* KingJoffrey observes events from {@link KingsHand}.
|
||||||
@ -29,8 +32,10 @@ package com.iluwatar.event.aggregator;
|
|||||||
*/
|
*/
|
||||||
public class KingJoffrey implements EventObserver {
|
public class KingJoffrey implements EventObserver {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(KingJoffrey.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEvent(Event e) {
|
public void onEvent(Event e) {
|
||||||
System.out.println("Received event from the King's Hand: " + e.toString());
|
LOGGER.info("Received event from the King's Hand: {}", e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,17 +24,19 @@ package com.iluwatar.eda.handler;
|
|||||||
|
|
||||||
import com.iluwatar.eda.event.UserCreatedEvent;
|
import com.iluwatar.eda.event.UserCreatedEvent;
|
||||||
import com.iluwatar.eda.framework.Handler;
|
import com.iluwatar.eda.framework.Handler;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the {@link UserCreatedEvent} message.
|
* Handles the {@link UserCreatedEvent} message.
|
||||||
*/
|
*/
|
||||||
public class UserCreatedEventHandler implements Handler<UserCreatedEvent> {
|
public class UserCreatedEventHandler implements Handler<UserCreatedEvent> {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(UserCreatedEventHandler.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEvent(UserCreatedEvent event) {
|
public void onEvent(UserCreatedEvent event) {
|
||||||
|
LOGGER.info("User '{}' has been Created!", event.getUser().getUsername());
|
||||||
System.out.println(String.format(
|
|
||||||
"User '%s' has been Created!", event.getUser().getUsername()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,16 +24,18 @@ package com.iluwatar.eda.handler;
|
|||||||
|
|
||||||
import com.iluwatar.eda.event.UserUpdatedEvent;
|
import com.iluwatar.eda.event.UserUpdatedEvent;
|
||||||
import com.iluwatar.eda.framework.Handler;
|
import com.iluwatar.eda.framework.Handler;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the {@link UserUpdatedEvent} message.
|
* Handles the {@link UserUpdatedEvent} message.
|
||||||
*/
|
*/
|
||||||
public class UserUpdatedEventHandler implements Handler<UserUpdatedEvent> {
|
public class UserUpdatedEventHandler implements Handler<UserUpdatedEvent> {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(UserUpdatedEventHandler.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEvent(UserUpdatedEvent event) {
|
public void onEvent(UserUpdatedEvent event) {
|
||||||
|
LOGGER.info("User '{}' has been Updated!", event.getUser().getUsername());
|
||||||
System.out.println(String.format(
|
|
||||||
"User '%s' has been Updated!", event.getUser().getUsername()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.facade;
|
package com.iluwatar.facade;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* DwarvenCartOperator is one of the goldmine subsystems.
|
* DwarvenCartOperator is one of the goldmine subsystems.
|
||||||
@ -29,9 +32,11 @@ package com.iluwatar.facade;
|
|||||||
*/
|
*/
|
||||||
public class DwarvenCartOperator extends DwarvenMineWorker {
|
public class DwarvenCartOperator extends DwarvenMineWorker {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(DwarvenCartOperator.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void work() {
|
public void work() {
|
||||||
System.out.println(name() + " moves gold chunks out of the mine.");
|
LOGGER.info("{} moves gold chunks out of the mine.", name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.facade;
|
package com.iluwatar.facade;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* DwarvenGoldDigger is one of the goldmine subsystems.
|
* DwarvenGoldDigger is one of the goldmine subsystems.
|
||||||
@ -29,9 +32,11 @@ package com.iluwatar.facade;
|
|||||||
*/
|
*/
|
||||||
public class DwarvenGoldDigger extends DwarvenMineWorker {
|
public class DwarvenGoldDigger extends DwarvenMineWorker {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(DwarvenGoldDigger.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void work() {
|
public void work() {
|
||||||
System.out.println(name() + " digs for gold.");
|
LOGGER.info("{} digs for gold.", name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.facade;
|
package com.iluwatar.facade;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* DwarvenMineWorker is one of the goldmine subsystems.
|
* DwarvenMineWorker is one of the goldmine subsystems.
|
||||||
@ -29,20 +32,22 @@ package com.iluwatar.facade;
|
|||||||
*/
|
*/
|
||||||
public abstract class DwarvenMineWorker {
|
public abstract class DwarvenMineWorker {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(DwarvenMineWorker.class);
|
||||||
|
|
||||||
public void goToSleep() {
|
public void goToSleep() {
|
||||||
System.out.println(name() + " goes to sleep.");
|
LOGGER.info("{} goes to sleep.", name());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void wakeUp() {
|
public void wakeUp() {
|
||||||
System.out.println(name() + " wakes up.");
|
LOGGER.info("{} wakes up.", name());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void goHome() {
|
public void goHome() {
|
||||||
System.out.println(name() + " goes home.");
|
LOGGER.info("{} goes home.", name());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void goToMine() {
|
public void goToMine() {
|
||||||
System.out.println(name() + " goes to the mine.");
|
LOGGER.info("{} goes to the mine.", name());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void action(Action action) {
|
private void action(Action action) {
|
||||||
@ -63,7 +68,7 @@ public abstract class DwarvenMineWorker {
|
|||||||
work();
|
work();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
System.out.println("Undefined action");
|
LOGGER.info("Undefined action");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.facade;
|
package com.iluwatar.facade;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* DwarvenTunnelDigger is one of the goldmine subsystems.
|
* DwarvenTunnelDigger is one of the goldmine subsystems.
|
||||||
@ -29,9 +32,11 @@ package com.iluwatar.facade;
|
|||||||
*/
|
*/
|
||||||
public class DwarvenTunnelDigger extends DwarvenMineWorker {
|
public class DwarvenTunnelDigger extends DwarvenMineWorker {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(DwarvenTunnelDigger.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void work() {
|
public void work() {
|
||||||
System.out.println(name() + " creates another promising tunnel.");
|
LOGGER.info("{} creates another promising tunnel.", name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.factorykit;
|
package com.iluwatar.factorykit;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory-kit is a creational pattern which defines a factory of immutable content
|
* Factory-kit is a creational pattern which defines a factory of immutable content
|
||||||
* with separated builder and factory interfaces to deal with the problem of
|
* with separated builder and factory interfaces to deal with the problem of
|
||||||
@ -36,6 +39,9 @@ package com.iluwatar.factorykit;
|
|||||||
* be mapped explicitly with desired class type in the factory instance.
|
* be mapped explicitly with desired class type in the factory instance.
|
||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point.
|
* Program entry point.
|
||||||
*
|
*
|
||||||
@ -49,6 +55,6 @@ public class App {
|
|||||||
builder.add(WeaponType.BOW, Bow::new);
|
builder.add(WeaponType.BOW, Bow::new);
|
||||||
});
|
});
|
||||||
Weapon axe = factory.create(WeaponType.AXE);
|
Weapon axe = factory.create(WeaponType.AXE);
|
||||||
System.out.println(axe);
|
LOGGER.info(axe.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.factory.method;
|
package com.iluwatar.factory.method;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* The Factory Method is a creational design pattern which uses factory methods to deal with the
|
* The Factory Method is a creational design pattern which uses factory methods to deal with the
|
||||||
@ -38,6 +41,8 @@ package com.iluwatar.factory.method;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
private final Blacksmith blacksmith;
|
private final Blacksmith blacksmith;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,8 +75,8 @@ public class App {
|
|||||||
private void manufactureWeapons() {
|
private void manufactureWeapons() {
|
||||||
Weapon weapon;
|
Weapon weapon;
|
||||||
weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
|
weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
|
||||||
System.out.println(weapon);
|
LOGGER.info(weapon.toString());
|
||||||
weapon = blacksmith.manufactureWeapon(WeaponType.AXE);
|
weapon = blacksmith.manufactureWeapon(WeaponType.AXE);
|
||||||
System.out.println(weapon);
|
LOGGER.info(weapon.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,8 @@ import com.iluwatar.featuretoggle.pattern.Service;
|
|||||||
import com.iluwatar.featuretoggle.pattern.propertiesversion.PropertiesFeatureToggleVersion;
|
import com.iluwatar.featuretoggle.pattern.propertiesversion.PropertiesFeatureToggleVersion;
|
||||||
import com.iluwatar.featuretoggle.user.User;
|
import com.iluwatar.featuretoggle.user.User;
|
||||||
import com.iluwatar.featuretoggle.user.UserGroup;
|
import com.iluwatar.featuretoggle.user.UserGroup;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
@ -45,6 +47,8 @@ import java.util.Properties;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Block 1 shows the {@link PropertiesFeatureToggleVersion} being run with {@link Properties} setting the feature
|
* Block 1 shows the {@link PropertiesFeatureToggleVersion} being run with {@link Properties} setting the feature
|
||||||
* toggle to enabled.
|
* toggle to enabled.
|
||||||
@ -70,7 +74,7 @@ public class App {
|
|||||||
properties.put("enhancedWelcome", true);
|
properties.put("enhancedWelcome", true);
|
||||||
Service service = new PropertiesFeatureToggleVersion(properties);
|
Service service = new PropertiesFeatureToggleVersion(properties);
|
||||||
final String welcomeMessage = service.getWelcomeMessage(new User("Jamie No Code"));
|
final String welcomeMessage = service.getWelcomeMessage(new User("Jamie No Code"));
|
||||||
System.out.println(welcomeMessage);
|
LOGGER.info(welcomeMessage);
|
||||||
|
|
||||||
// ---------------------------------------------
|
// ---------------------------------------------
|
||||||
|
|
||||||
@ -78,7 +82,7 @@ public class App {
|
|||||||
turnedOff.put("enhancedWelcome", false);
|
turnedOff.put("enhancedWelcome", false);
|
||||||
Service turnedOffService = new PropertiesFeatureToggleVersion(turnedOff);
|
Service turnedOffService = new PropertiesFeatureToggleVersion(turnedOff);
|
||||||
final String welcomeMessageturnedOff = turnedOffService.getWelcomeMessage(new User("Jamie No Code"));
|
final String welcomeMessageturnedOff = turnedOffService.getWelcomeMessage(new User("Jamie No Code"));
|
||||||
System.out.println(welcomeMessageturnedOff);
|
LOGGER.info(welcomeMessageturnedOff);
|
||||||
|
|
||||||
// --------------------------------------------
|
// --------------------------------------------
|
||||||
|
|
||||||
@ -90,7 +94,7 @@ public class App {
|
|||||||
|
|
||||||
final String welcomeMessagePaidUser = service.getWelcomeMessage(paidUser);
|
final String welcomeMessagePaidUser = service.getWelcomeMessage(paidUser);
|
||||||
final String welcomeMessageFreeUser = service.getWelcomeMessage(freeUser);
|
final String welcomeMessageFreeUser = service.getWelcomeMessage(freeUser);
|
||||||
System.out.println(welcomeMessageFreeUser);
|
LOGGER.info(welcomeMessageFreeUser);
|
||||||
System.out.println(welcomeMessagePaidUser);
|
LOGGER.info(welcomeMessagePaidUser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,8 @@ import java.util.function.Predicate;
|
|||||||
import com.iluwatar.fluentinterface.fluentiterable.FluentIterable;
|
import com.iluwatar.fluentinterface.fluentiterable.FluentIterable;
|
||||||
import com.iluwatar.fluentinterface.fluentiterable.lazy.LazyFluentIterable;
|
import com.iluwatar.fluentinterface.fluentiterable.lazy.LazyFluentIterable;
|
||||||
import com.iluwatar.fluentinterface.fluentiterable.simple.SimpleFluentIterable;
|
import com.iluwatar.fluentinterface.fluentiterable.simple.SimpleFluentIterable;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Fluent Interface pattern is useful when you want to provide an easy readable, flowing API.
|
* The Fluent Interface pattern is useful when you want to provide an easy readable, flowing API.
|
||||||
@ -50,6 +52,8 @@ import com.iluwatar.fluentinterface.fluentiterable.simple.SimpleFluentIterable;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point
|
||||||
*/
|
*/
|
||||||
@ -74,9 +78,7 @@ public class App {
|
|||||||
.fromCopyOf(integerList)
|
.fromCopyOf(integerList)
|
||||||
.filter(number -> number % 2 == 0)
|
.filter(number -> number % 2 == 0)
|
||||||
.first()
|
.first()
|
||||||
.ifPresent(
|
.ifPresent(evenNumber -> LOGGER.info("The first even number is: {}", evenNumber));
|
||||||
evenNumber -> System.out.println(String.format("The first even number is: %d",
|
|
||||||
evenNumber)));
|
|
||||||
|
|
||||||
|
|
||||||
List<String> transformedList =
|
List<String> transformedList =
|
||||||
@ -97,9 +99,7 @@ public class App {
|
|||||||
.filter(negatives())
|
.filter(negatives())
|
||||||
.first(2)
|
.first(2)
|
||||||
.last()
|
.last()
|
||||||
.ifPresent(
|
.ifPresent(lastOfFirstTwo -> LOGGER.info("The last of the first two negatives is: {}", lastOfFirstTwo));
|
||||||
lastOfFirstTwo -> System.out.println(String.format(
|
|
||||||
"The last of the first two negatives is: %d", lastOfFirstTwo)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Function<Integer, String> transformToString() {
|
private static Function<Integer, String> transformToString() {
|
||||||
@ -126,6 +126,6 @@ public class App {
|
|||||||
joiner.add(iterator.next().toString());
|
joiner.add(iterator.next().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(joiner);
|
LOGGER.info(joiner.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,8 @@ package com.iluwatar.flux.view;
|
|||||||
import com.iluwatar.flux.action.Content;
|
import com.iluwatar.flux.action.Content;
|
||||||
import com.iluwatar.flux.store.ContentStore;
|
import com.iluwatar.flux.store.ContentStore;
|
||||||
import com.iluwatar.flux.store.Store;
|
import com.iluwatar.flux.store.Store;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -33,6 +35,8 @@ import com.iluwatar.flux.store.Store;
|
|||||||
*/
|
*/
|
||||||
public class ContentView implements View {
|
public class ContentView implements View {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(ContentView.class);
|
||||||
|
|
||||||
private Content content = Content.PRODUCTS;
|
private Content content = Content.PRODUCTS;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -44,6 +48,6 @@ public class ContentView implements View {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render() {
|
||||||
System.out.println(content.toString());
|
LOGGER.info(content.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,8 @@ import com.iluwatar.flux.action.MenuItem;
|
|||||||
import com.iluwatar.flux.dispatcher.Dispatcher;
|
import com.iluwatar.flux.dispatcher.Dispatcher;
|
||||||
import com.iluwatar.flux.store.MenuStore;
|
import com.iluwatar.flux.store.MenuStore;
|
||||||
import com.iluwatar.flux.store.Store;
|
import com.iluwatar.flux.store.Store;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -34,6 +36,8 @@ import com.iluwatar.flux.store.Store;
|
|||||||
*/
|
*/
|
||||||
public class MenuView implements View {
|
public class MenuView implements View {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(MenuView.class);
|
||||||
|
|
||||||
private MenuItem selected = MenuItem.HOME;
|
private MenuItem selected = MenuItem.HOME;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -47,9 +51,9 @@ public class MenuView implements View {
|
|||||||
public void render() {
|
public void render() {
|
||||||
for (MenuItem item : MenuItem.values()) {
|
for (MenuItem item : MenuItem.values()) {
|
||||||
if (selected.equals(item)) {
|
if (selected.equals(item)) {
|
||||||
System.out.println(String.format("* %s", item.toString()));
|
LOGGER.info("* {}", item);
|
||||||
} else {
|
} else {
|
||||||
System.out.println(item.toString());
|
LOGGER.info(item.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.flyweight;
|
package com.iluwatar.flyweight;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -33,6 +36,8 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class AlchemistShop {
|
public class AlchemistShop {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(AlchemistShop.class);
|
||||||
|
|
||||||
private List<Potion> topShelf;
|
private List<Potion> topShelf;
|
||||||
private List<Potion> bottomShelf;
|
private List<Potion> bottomShelf;
|
||||||
|
|
||||||
@ -88,13 +93,13 @@ public class AlchemistShop {
|
|||||||
*/
|
*/
|
||||||
public void enumerate() {
|
public void enumerate() {
|
||||||
|
|
||||||
System.out.println("Enumerating top shelf potions\n");
|
LOGGER.info("Enumerating top shelf potions\n");
|
||||||
|
|
||||||
for (Potion p : topShelf) {
|
for (Potion p : topShelf) {
|
||||||
p.drink();
|
p.drink();
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("\nEnumerating bottom shelf potions\n");
|
LOGGER.info("Enumerating bottom shelf potions\n");
|
||||||
|
|
||||||
for (Potion p : bottomShelf) {
|
for (Potion p : bottomShelf) {
|
||||||
p.drink();
|
p.drink();
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.flyweight;
|
package com.iluwatar.flyweight;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* HealingPotion
|
* HealingPotion
|
||||||
@ -29,8 +32,10 @@ package com.iluwatar.flyweight;
|
|||||||
*/
|
*/
|
||||||
public class HealingPotion implements Potion {
|
public class HealingPotion implements Potion {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(HealingPotion.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drink() {
|
public void drink() {
|
||||||
System.out.println("You feel healed. (Potion=" + System.identityHashCode(this) + ")");
|
LOGGER.info("You feel healed. (Potion={})", System.identityHashCode(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.flyweight;
|
package com.iluwatar.flyweight;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* HolyWaterPotion
|
* HolyWaterPotion
|
||||||
@ -29,8 +32,10 @@ package com.iluwatar.flyweight;
|
|||||||
*/
|
*/
|
||||||
public class HolyWaterPotion implements Potion {
|
public class HolyWaterPotion implements Potion {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(HolyWaterPotion.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drink() {
|
public void drink() {
|
||||||
System.out.println("You feel blessed. (Potion=" + System.identityHashCode(this) + ")");
|
LOGGER.info("You feel blessed. (Potion={})", System.identityHashCode(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.flyweight;
|
package com.iluwatar.flyweight;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* InvisibilityPotion
|
* InvisibilityPotion
|
||||||
@ -29,8 +32,10 @@ package com.iluwatar.flyweight;
|
|||||||
*/
|
*/
|
||||||
public class InvisibilityPotion implements Potion {
|
public class InvisibilityPotion implements Potion {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(InvisibilityPotion.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drink() {
|
public void drink() {
|
||||||
System.out.println("You become invisible. (Potion=" + System.identityHashCode(this) + ")");
|
LOGGER.info("You become invisible. (Potion={})", System.identityHashCode(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.flyweight;
|
package com.iluwatar.flyweight;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* PoisonPotion
|
* PoisonPotion
|
||||||
@ -29,8 +32,10 @@ package com.iluwatar.flyweight;
|
|||||||
*/
|
*/
|
||||||
public class PoisonPotion implements Potion {
|
public class PoisonPotion implements Potion {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(PoisonPotion.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drink() {
|
public void drink() {
|
||||||
System.out.println("Urgh! This is poisonous. (Potion=" + System.identityHashCode(this) + ")");
|
LOGGER.info("Urgh! This is poisonous. (Potion={})", System.identityHashCode(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.flyweight;
|
package com.iluwatar.flyweight;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* StrengthPotion
|
* StrengthPotion
|
||||||
@ -29,8 +32,10 @@ package com.iluwatar.flyweight;
|
|||||||
*/
|
*/
|
||||||
public class StrengthPotion implements Potion {
|
public class StrengthPotion implements Potion {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(StrengthPotion.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drink() {
|
public void drink() {
|
||||||
System.out.println("You feel strong. (Potion=" + System.identityHashCode(this) + ")");
|
LOGGER.info("You feel strong. (Potion={})", System.identityHashCode(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,15 +22,20 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.front.controller;
|
package com.iluwatar.front.controller;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* View for archers.
|
* View for archers.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ArcherView implements View {
|
public class ArcherView implements View {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(ArcherView.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void display() {
|
public void display() {
|
||||||
System.out.println("Displaying archers");
|
LOGGER.info("Displaying archers");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.front.controller;
|
package com.iluwatar.front.controller;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* View for catapults.
|
* View for catapults.
|
||||||
@ -29,8 +32,10 @@ package com.iluwatar.front.controller;
|
|||||||
*/
|
*/
|
||||||
public class CatapultView implements View {
|
public class CatapultView implements View {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(CatapultView.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void display() {
|
public void display() {
|
||||||
System.out.println("Displaying catapults");
|
LOGGER.info("Displaying catapults");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.front.controller;
|
package com.iluwatar.front.controller;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* View for errors.
|
* View for errors.
|
||||||
@ -29,8 +32,10 @@ package com.iluwatar.front.controller;
|
|||||||
*/
|
*/
|
||||||
public class ErrorView implements View {
|
public class ErrorView implements View {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(ErrorView.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void display() {
|
public void display() {
|
||||||
System.out.println("Error 500");
|
LOGGER.error("Error 500");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.halfsynchalfasync;
|
package com.iluwatar.halfsynchalfasync;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,6 +69,8 @@ import java.util.concurrent.LinkedBlockingQueue;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point
|
||||||
*
|
*
|
||||||
@ -128,7 +133,7 @@ public class App {
|
|||||||
@Override
|
@Override
|
||||||
public void onPostCall(Long result) {
|
public void onPostCall(Long result) {
|
||||||
// Handle the result of computation
|
// Handle the result of computation
|
||||||
System.out.println(result);
|
LOGGER.info(result.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -141,7 +146,7 @@ public class App {
|
|||||||
try {
|
try {
|
||||||
Thread.sleep(i);
|
Thread.sleep(i);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
System.out.println(e);
|
LOGGER.error("Exception caught.", e);
|
||||||
}
|
}
|
||||||
return i * (i + 1) / 2;
|
return i * (i + 1) / 2;
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,8 @@ import com.iluwatar.hexagonal.domain.LotteryService;
|
|||||||
import com.iluwatar.hexagonal.module.LotteryModule;
|
import com.iluwatar.hexagonal.module.LotteryModule;
|
||||||
import com.iluwatar.hexagonal.mongo.MongoConnectionPropertiesLoader;
|
import com.iluwatar.hexagonal.mongo.MongoConnectionPropertiesLoader;
|
||||||
import com.iluwatar.hexagonal.sampledata.SampleData;
|
import com.iluwatar.hexagonal.sampledata.SampleData;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
@ -38,6 +40,8 @@ import java.util.Scanner;
|
|||||||
*/
|
*/
|
||||||
public class ConsoleAdministration {
|
public class ConsoleAdministration {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(ConsoleAdministration.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point
|
||||||
*/
|
*/
|
||||||
@ -53,29 +57,29 @@ public class ConsoleAdministration {
|
|||||||
printMainMenu();
|
printMainMenu();
|
||||||
String cmd = readString(scanner);
|
String cmd = readString(scanner);
|
||||||
if (cmd.equals("1")) {
|
if (cmd.equals("1")) {
|
||||||
administartion.getAllSubmittedTickets().forEach((k,v)->System.out.println("Key: " + k + " Value: " + v));
|
administartion.getAllSubmittedTickets().forEach((k,v)->LOGGER.info("Key: {}, Value: {}", k, v));
|
||||||
} else if (cmd.equals("2")) {
|
} else if (cmd.equals("2")) {
|
||||||
LotteryNumbers numbers = administartion.performLottery();
|
LotteryNumbers numbers = administartion.performLottery();
|
||||||
System.out.println("The winning numbers: " + numbers.getNumbersAsString());
|
LOGGER.info("The winning numbers: {}", numbers.getNumbersAsString());
|
||||||
System.out.println("Time to reset the database for next round, eh?");
|
LOGGER.info("Time to reset the database for next round, eh?");
|
||||||
} else if (cmd.equals("3")) {
|
} else if (cmd.equals("3")) {
|
||||||
administartion.resetLottery();
|
administartion.resetLottery();
|
||||||
System.out.println("The lottery ticket database was cleared.");
|
LOGGER.info("The lottery ticket database was cleared.");
|
||||||
} else if (cmd.equals("4")) {
|
} else if (cmd.equals("4")) {
|
||||||
exit = true;
|
exit = true;
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Unknown command: " + cmd);
|
LOGGER.info("Unknown command: {}", cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void printMainMenu() {
|
private static void printMainMenu() {
|
||||||
System.out.println("");
|
LOGGER.info("");
|
||||||
System.out.println("### Lottery Administration Console ###");
|
LOGGER.info("### Lottery Administration Console ###");
|
||||||
System.out.println("(1) Show all submitted tickets");
|
LOGGER.info("(1) Show all submitted tickets");
|
||||||
System.out.println("(2) Perform lottery draw");
|
LOGGER.info("(2) Perform lottery draw");
|
||||||
System.out.println("(3) Reset lottery ticket database");
|
LOGGER.info("(3) Reset lottery ticket database");
|
||||||
System.out.println("(4) Exit");
|
LOGGER.info("(4) Exit");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String readString(Scanner scanner) {
|
private static String readString(Scanner scanner) {
|
||||||
|
@ -23,42 +23,42 @@
|
|||||||
package com.iluwatar.hexagonal.eventlog;
|
package com.iluwatar.hexagonal.eventlog;
|
||||||
|
|
||||||
import com.iluwatar.hexagonal.domain.PlayerDetails;
|
import com.iluwatar.hexagonal.domain.PlayerDetails;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Standard output event log
|
* Standard output event log
|
||||||
*/
|
*/
|
||||||
public class StdOutEventLog implements LotteryEventLog {
|
public class StdOutEventLog implements LotteryEventLog {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(StdOutEventLog.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ticketSubmitted(PlayerDetails details) {
|
public void ticketSubmitted(PlayerDetails details) {
|
||||||
System.out.println(String.format("Lottery ticket for %s was submitted. Bank account %s was charged for 3 credits.",
|
LOGGER.info("Lottery ticket for {} was submitted. Bank account {} was charged for 3 credits.",
|
||||||
details.getEmail(), details.getBankAccount()));
|
details.getEmail(), details.getBankAccount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ticketDidNotWin(PlayerDetails details) {
|
public void ticketDidNotWin(PlayerDetails details) {
|
||||||
System.out.println(String.format("Lottery ticket for %s was checked and unfortunately did not win this time.",
|
LOGGER.info("Lottery ticket for {} was checked and unfortunately did not win this time.", details.getEmail());
|
||||||
details.getEmail()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ticketWon(PlayerDetails details, int prizeAmount) {
|
public void ticketWon(PlayerDetails details, int prizeAmount) {
|
||||||
System.out
|
LOGGER.info("Lottery ticket for {} has won! The bank account {} was deposited with {} credits.",
|
||||||
.println(String.format("Lottery ticket for %s has won! The bank account %s was deposited with %d credits.",
|
details.getEmail(), details.getBankAccount(), prizeAmount);
|
||||||
details.getEmail(), details.getBankAccount(), prizeAmount));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void prizeError(PlayerDetails details, int prizeAmount) {
|
public void prizeError(PlayerDetails details, int prizeAmount) {
|
||||||
System.out
|
LOGGER.error("Lottery ticket for {} has won! Unfortunately the bank credit transfer of {} failed.",
|
||||||
.println(String.format("Lottery ticket for %s has won! Unfortunately the bank credit transfer of %d failed.",
|
details.getEmail(), prizeAmount);
|
||||||
details.getEmail(), prizeAmount));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ticketSubmitError(PlayerDetails details) {
|
public void ticketSubmitError(PlayerDetails details) {
|
||||||
System.out.println(
|
LOGGER.error("Lottery ticket for {} could not be submitted because the credit transfer of 3 credits failed.",
|
||||||
String.format("Lottery ticket for %s could not be submitted because the credit transfer of 3 credits failed.",
|
details.getEmail());
|
||||||
details.getEmail()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ package com.iluwatar.hexagonal.service;
|
|||||||
|
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
|
import com.iluwatar.hexagonal.administration.ConsoleAdministration;
|
||||||
import com.iluwatar.hexagonal.banking.WireTransfers;
|
import com.iluwatar.hexagonal.banking.WireTransfers;
|
||||||
import com.iluwatar.hexagonal.domain.LotteryNumbers;
|
import com.iluwatar.hexagonal.domain.LotteryNumbers;
|
||||||
import com.iluwatar.hexagonal.domain.LotteryService;
|
import com.iluwatar.hexagonal.domain.LotteryService;
|
||||||
@ -33,6 +34,8 @@ import com.iluwatar.hexagonal.domain.LotteryTicketId;
|
|||||||
import com.iluwatar.hexagonal.domain.PlayerDetails;
|
import com.iluwatar.hexagonal.domain.PlayerDetails;
|
||||||
import com.iluwatar.hexagonal.module.LotteryModule;
|
import com.iluwatar.hexagonal.module.LotteryModule;
|
||||||
import com.iluwatar.hexagonal.mongo.MongoConnectionPropertiesLoader;
|
import com.iluwatar.hexagonal.mongo.MongoConnectionPropertiesLoader;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -44,6 +47,7 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
public class ConsoleLottery {
|
public class ConsoleLottery {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(ConsoleLottery.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point
|
||||||
@ -59,25 +63,25 @@ public class ConsoleLottery {
|
|||||||
printMainMenu();
|
printMainMenu();
|
||||||
String cmd = readString(scanner);
|
String cmd = readString(scanner);
|
||||||
if (cmd.equals("1")) {
|
if (cmd.equals("1")) {
|
||||||
System.out.println("What is the account number?");
|
LOGGER.info("What is the account number?");
|
||||||
String account = readString(scanner);
|
String account = readString(scanner);
|
||||||
System.out.println(String.format("The account %s has %d credits.", account, bank.getFunds(account)));
|
LOGGER.info("The account {} has {} credits.", account, bank.getFunds(account));
|
||||||
} else if (cmd.equals("2")) {
|
} else if (cmd.equals("2")) {
|
||||||
System.out.println("What is the account number?");
|
LOGGER.info("What is the account number?");
|
||||||
String account = readString(scanner);
|
String account = readString(scanner);
|
||||||
System.out.println("How many credits do you want to deposit?");
|
LOGGER.info("How many credits do you want to deposit?");
|
||||||
String amount = readString(scanner);
|
String amount = readString(scanner);
|
||||||
bank.setFunds(account, Integer.parseInt(amount));
|
bank.setFunds(account, Integer.parseInt(amount));
|
||||||
System.out.println(String.format("The account %s now has %d credits.", account, bank.getFunds(account)));
|
LOGGER.info("The account {} now has {} credits.", account, bank.getFunds(account));
|
||||||
} else if (cmd.equals("3")) {
|
} else if (cmd.equals("3")) {
|
||||||
System.out.println("What is your email address?");
|
LOGGER.info("What is your email address?");
|
||||||
String email = readString(scanner);
|
String email = readString(scanner);
|
||||||
System.out.println("What is your bank account number?");
|
LOGGER.info("What is your bank account number?");
|
||||||
String account = readString(scanner);
|
String account = readString(scanner);
|
||||||
System.out.println("What is your phone number?");
|
LOGGER.info("What is your phone number?");
|
||||||
String phone = readString(scanner);
|
String phone = readString(scanner);
|
||||||
PlayerDetails details = new PlayerDetails(email, account, phone);
|
PlayerDetails details = new PlayerDetails(email, account, phone);
|
||||||
System.out.println("Give 4 comma separated lottery numbers?");
|
LOGGER.info("Give 4 comma separated lottery numbers?");
|
||||||
String numbers = readString(scanner);
|
String numbers = readString(scanner);
|
||||||
try {
|
try {
|
||||||
String[] parts = numbers.split(",");
|
String[] parts = numbers.split(",");
|
||||||
@ -89,17 +93,17 @@ public class ConsoleLottery {
|
|||||||
LotteryTicket lotteryTicket = new LotteryTicket(new LotteryTicketId(), details, lotteryNumbers);
|
LotteryTicket lotteryTicket = new LotteryTicket(new LotteryTicketId(), details, lotteryNumbers);
|
||||||
Optional<LotteryTicketId> id = service.submitTicket(lotteryTicket);
|
Optional<LotteryTicketId> id = service.submitTicket(lotteryTicket);
|
||||||
if (id.isPresent()) {
|
if (id.isPresent()) {
|
||||||
System.out.println("Submitted lottery ticket with id: " + id.get());
|
LOGGER.info("Submitted lottery ticket with id: {}", id.get());
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Failed submitting lottery ticket - please try again.");
|
LOGGER.info("Failed submitting lottery ticket - please try again.");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("Failed submitting lottery ticket - please try again.");
|
LOGGER.info("Failed submitting lottery ticket - please try again.");
|
||||||
}
|
}
|
||||||
} else if (cmd.equals("4")) {
|
} else if (cmd.equals("4")) {
|
||||||
System.out.println("What is the ID of the lottery ticket?");
|
LOGGER.info("What is the ID of the lottery ticket?");
|
||||||
String id = readString(scanner);
|
String id = readString(scanner);
|
||||||
System.out.println("Give the 4 comma separated winning numbers?");
|
LOGGER.info("Give the 4 comma separated winning numbers?");
|
||||||
String numbers = readString(scanner);
|
String numbers = readString(scanner);
|
||||||
try {
|
try {
|
||||||
String[] parts = numbers.split(",");
|
String[] parts = numbers.split(",");
|
||||||
@ -110,31 +114,31 @@ public class ConsoleLottery {
|
|||||||
LotteryTicketCheckResult result = service.checkTicketForPrize(
|
LotteryTicketCheckResult result = service.checkTicketForPrize(
|
||||||
new LotteryTicketId(Integer.parseInt(id)), LotteryNumbers.create(winningNumbers));
|
new LotteryTicketId(Integer.parseInt(id)), LotteryNumbers.create(winningNumbers));
|
||||||
if (result.getResult().equals(LotteryTicketCheckResult.CheckResult.WIN_PRIZE)) {
|
if (result.getResult().equals(LotteryTicketCheckResult.CheckResult.WIN_PRIZE)) {
|
||||||
System.out.println("Congratulations! The lottery ticket has won!");
|
LOGGER.info("Congratulations! The lottery ticket has won!");
|
||||||
} else if (result.getResult().equals(LotteryTicketCheckResult.CheckResult.NO_PRIZE)) {
|
} else if (result.getResult().equals(LotteryTicketCheckResult.CheckResult.NO_PRIZE)) {
|
||||||
System.out.println("Unfortunately the lottery ticket did not win.");
|
LOGGER.info("Unfortunately the lottery ticket did not win.");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Such lottery ticket has not been submitted.");
|
LOGGER.info("Such lottery ticket has not been submitted.");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("Failed checking the lottery ticket - please try again.");
|
LOGGER.info("Failed checking the lottery ticket - please try again.");
|
||||||
}
|
}
|
||||||
} else if (cmd.equals("5")) {
|
} else if (cmd.equals("5")) {
|
||||||
exit = true;
|
exit = true;
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Unknown command");
|
LOGGER.info("Unknown command");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void printMainMenu() {
|
private static void printMainMenu() {
|
||||||
System.out.println("");
|
LOGGER.info("");
|
||||||
System.out.println("### Lottery Service Console ###");
|
LOGGER.info("### Lottery Service Console ###");
|
||||||
System.out.println("(1) Query lottery account funds");
|
LOGGER.info("(1) Query lottery account funds");
|
||||||
System.out.println("(2) Add funds to lottery account");
|
LOGGER.info("(2) Add funds to lottery account");
|
||||||
System.out.println("(3) Submit ticket");
|
LOGGER.info("(3) Submit ticket");
|
||||||
System.out.println("(4) Check ticket");
|
LOGGER.info("(4) Check ticket");
|
||||||
System.out.println("(5) Exit");
|
LOGGER.info("(5) Exit");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String readString(Scanner scanner) {
|
private static String readString(Scanner scanner) {
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.interpreter;
|
package com.iluwatar.interpreter;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,6 +40,8 @@ import java.util.Stack;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Program entry point.
|
* Program entry point.
|
||||||
@ -56,21 +61,21 @@ public class App {
|
|||||||
if (isOperator(s)) {
|
if (isOperator(s)) {
|
||||||
Expression rightExpression = stack.pop();
|
Expression rightExpression = stack.pop();
|
||||||
Expression leftExpression = stack.pop();
|
Expression leftExpression = stack.pop();
|
||||||
System.out.println(String.format("popped from stack left: %d right: %d",
|
LOGGER.info("popped from stack left: {} right: {}",
|
||||||
leftExpression.interpret(), rightExpression.interpret()));
|
leftExpression.interpret(), rightExpression.interpret());
|
||||||
Expression operator = getOperatorInstance(s, leftExpression, rightExpression);
|
Expression operator = getOperatorInstance(s, leftExpression, rightExpression);
|
||||||
System.out.println(String.format("operator: %s", operator));
|
LOGGER.info("operator: {}", operator);
|
||||||
int result = operator.interpret();
|
int result = operator.interpret();
|
||||||
NumberExpression resultExpression = new NumberExpression(result);
|
NumberExpression resultExpression = new NumberExpression(result);
|
||||||
stack.push(resultExpression);
|
stack.push(resultExpression);
|
||||||
System.out.println(String.format("push result to stack: %d", resultExpression.interpret()));
|
LOGGER.info("push result to stack: {}", resultExpression.interpret());
|
||||||
} else {
|
} else {
|
||||||
Expression i = new NumberExpression(s);
|
Expression i = new NumberExpression(s);
|
||||||
stack.push(i);
|
stack.push(i);
|
||||||
System.out.println(String.format("push to stack: %d", i.interpret()));
|
LOGGER.info("push to stack: {}", i.interpret());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println(String.format("result: %d", stack.pop().interpret()));
|
LOGGER.info("result: {}", stack.pop().interpret());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isOperator(String s) {
|
public static boolean isOperator(String s) {
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.iterator;
|
package com.iluwatar.iterator;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* The Iterator pattern is a design pattern in which an iterator is used to traverse a container and
|
* The Iterator pattern is a design pattern in which an iterator is used to traverse a container and
|
||||||
@ -34,6 +37,8 @@ package com.iluwatar.iterator;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point
|
||||||
*
|
*
|
||||||
@ -44,28 +49,28 @@ public class App {
|
|||||||
|
|
||||||
ItemIterator ringIterator = chest.iterator(ItemType.RING);
|
ItemIterator ringIterator = chest.iterator(ItemType.RING);
|
||||||
while (ringIterator.hasNext()) {
|
while (ringIterator.hasNext()) {
|
||||||
System.out.println(ringIterator.next());
|
LOGGER.info(ringIterator.next().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("----------");
|
LOGGER.info("----------");
|
||||||
|
|
||||||
ItemIterator potionIterator = chest.iterator(ItemType.POTION);
|
ItemIterator potionIterator = chest.iterator(ItemType.POTION);
|
||||||
while (potionIterator.hasNext()) {
|
while (potionIterator.hasNext()) {
|
||||||
System.out.println(potionIterator.next());
|
LOGGER.info(potionIterator.next().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("----------");
|
LOGGER.info("----------");
|
||||||
|
|
||||||
ItemIterator weaponIterator = chest.iterator(ItemType.WEAPON);
|
ItemIterator weaponIterator = chest.iterator(ItemType.WEAPON);
|
||||||
while (weaponIterator.hasNext()) {
|
while (weaponIterator.hasNext()) {
|
||||||
System.out.println(weaponIterator.next());
|
LOGGER.info(weaponIterator.next().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("----------");
|
LOGGER.info("----------");
|
||||||
|
|
||||||
ItemIterator it = chest.iterator(ItemType.ANY);
|
ItemIterator it = chest.iterator(ItemType.ANY);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
System.out.println(it.next());
|
LOGGER.info(it.next().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.layers;
|
package com.iluwatar.layers;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* View implementation for displaying cakes
|
* View implementation for displaying cakes
|
||||||
@ -29,6 +32,8 @@ package com.iluwatar.layers;
|
|||||||
*/
|
*/
|
||||||
public class CakeViewImpl implements View {
|
public class CakeViewImpl implements View {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(CakeViewImpl.class);
|
||||||
|
|
||||||
private CakeBakingService cakeBakingService;
|
private CakeBakingService cakeBakingService;
|
||||||
|
|
||||||
public CakeViewImpl(CakeBakingService cakeBakingService) {
|
public CakeViewImpl(CakeBakingService cakeBakingService) {
|
||||||
@ -36,6 +41,6 @@ public class CakeViewImpl implements View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void render() {
|
public void render() {
|
||||||
cakeBakingService.getAllCakes().stream().forEach(cake -> System.out.println(cake));
|
cakeBakingService.getAllCakes().stream().forEach(cake -> LOGGER.info(cake.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,8 @@ package com.iluwatar.layers;
|
|||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.lazy.loading;
|
package com.iluwatar.lazy.loading;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Lazy loading idiom defers object creation until needed.
|
* Lazy loading idiom defers object creation until needed.
|
||||||
@ -33,6 +36,9 @@ package com.iluwatar.lazy.loading;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point
|
||||||
*
|
*
|
||||||
@ -43,16 +49,16 @@ public class App {
|
|||||||
// Simple lazy loader - not thread safe
|
// Simple lazy loader - not thread safe
|
||||||
HolderNaive holderNaive = new HolderNaive();
|
HolderNaive holderNaive = new HolderNaive();
|
||||||
Heavy heavy = holderNaive.getHeavy();
|
Heavy heavy = holderNaive.getHeavy();
|
||||||
System.out.println("heavy=" + heavy);
|
LOGGER.info("heavy={}", heavy);
|
||||||
|
|
||||||
// Thread safe lazy loader, but with heavy synchronization on each access
|
// Thread safe lazy loader, but with heavy synchronization on each access
|
||||||
HolderThreadSafe holderThreadSafe = new HolderThreadSafe();
|
HolderThreadSafe holderThreadSafe = new HolderThreadSafe();
|
||||||
Heavy another = holderThreadSafe.getHeavy();
|
Heavy another = holderThreadSafe.getHeavy();
|
||||||
System.out.println("another=" + another);
|
LOGGER.info("another={}", another);
|
||||||
|
|
||||||
// The most efficient lazy loader utilizing Java 8 features
|
// The most efficient lazy loader utilizing Java 8 features
|
||||||
Java8Holder java8Holder = new Java8Holder();
|
Java8Holder java8Holder = new Java8Holder();
|
||||||
Heavy next = java8Holder.getHeavy();
|
Heavy next = java8Holder.getHeavy();
|
||||||
System.out.println("next=" + next);
|
LOGGER.info("next={}", next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.lazy.loading;
|
package com.iluwatar.lazy.loading;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Heavy objects are expensive to create.
|
* Heavy objects are expensive to create.
|
||||||
@ -29,16 +32,18 @@ package com.iluwatar.lazy.loading;
|
|||||||
*/
|
*/
|
||||||
public class Heavy {
|
public class Heavy {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Heavy.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public Heavy() {
|
public Heavy() {
|
||||||
System.out.println("Creating Heavy ...");
|
LOGGER.info("Creating Heavy ...");
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
LOGGER.error("Exception caught.", e);
|
||||||
}
|
}
|
||||||
System.out.println("... Heavy created");
|
LOGGER.info("... Heavy created");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.lazy.loading;
|
package com.iluwatar.lazy.loading;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Simple implementation of the lazy loading idiom. However, this is not thread safe.
|
* Simple implementation of the lazy loading idiom. However, this is not thread safe.
|
||||||
@ -29,13 +32,15 @@ package com.iluwatar.lazy.loading;
|
|||||||
*/
|
*/
|
||||||
public class HolderNaive {
|
public class HolderNaive {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(HolderNaive.class);
|
||||||
|
|
||||||
private Heavy heavy;
|
private Heavy heavy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public HolderNaive() {
|
public HolderNaive() {
|
||||||
System.out.println("HolderNaive created");
|
LOGGER.info("HolderNaive created");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.lazy.loading;
|
package com.iluwatar.lazy.loading;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Same as HolderNaive but with added synchronization. This implementation is thread safe, but each
|
* Same as HolderNaive but with added synchronization. This implementation is thread safe, but each
|
||||||
@ -30,13 +33,15 @@ package com.iluwatar.lazy.loading;
|
|||||||
*/
|
*/
|
||||||
public class HolderThreadSafe {
|
public class HolderThreadSafe {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(HolderThreadSafe.class);
|
||||||
|
|
||||||
private Heavy heavy;
|
private Heavy heavy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public HolderThreadSafe() {
|
public HolderThreadSafe() {
|
||||||
System.out.println("HolderThreadSafe created");
|
LOGGER.info("HolderThreadSafe created");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.lazy.loading;
|
package com.iluwatar.lazy.loading;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,10 +35,12 @@ import java.util.function.Supplier;
|
|||||||
*/
|
*/
|
||||||
public class Java8Holder {
|
public class Java8Holder {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Java8Holder.class);
|
||||||
|
|
||||||
private Supplier<Heavy> heavy = () -> createAndCacheHeavy();
|
private Supplier<Heavy> heavy = () -> createAndCacheHeavy();
|
||||||
|
|
||||||
public Java8Holder() {
|
public Java8Holder() {
|
||||||
System.out.println("Java8Holder created");
|
LOGGER.info("Java8Holder created");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Heavy getHeavy() {
|
public Heavy getHeavy() {
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.mediator;
|
package com.iluwatar.mediator;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Abstract base class for party members.
|
* Abstract base class for party members.
|
||||||
@ -29,23 +32,25 @@ package com.iluwatar.mediator;
|
|||||||
*/
|
*/
|
||||||
public abstract class PartyMemberBase implements PartyMember {
|
public abstract class PartyMemberBase implements PartyMember {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(PartyMemberBase.class);
|
||||||
|
|
||||||
protected Party party;
|
protected Party party;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void joinedParty(Party party) {
|
public void joinedParty(Party party) {
|
||||||
System.out.println(this + " joins the party");
|
LOGGER.info("{} joins the party", this);
|
||||||
this.party = party;
|
this.party = party;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void partyAction(Action action) {
|
public void partyAction(Action action) {
|
||||||
System.out.println(this + " " + action.getDescription());
|
LOGGER.info("{} {}", this, action.getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void act(Action action) {
|
public void act(Action action) {
|
||||||
if (party != null) {
|
if (party != null) {
|
||||||
System.out.println(this + " " + action.toString());
|
LOGGER.info("{} {}", this, action);
|
||||||
party.act(this, action);
|
party.act(this, action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.memento;
|
package com.iluwatar.memento;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,6 +48,8 @@ import java.util.Stack;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point
|
||||||
*/
|
*/
|
||||||
@ -52,22 +57,22 @@ public class App {
|
|||||||
Stack<StarMemento> states = new Stack<>();
|
Stack<StarMemento> states = new Stack<>();
|
||||||
|
|
||||||
Star star = new Star(StarType.SUN, 10000000, 500000);
|
Star star = new Star(StarType.SUN, 10000000, 500000);
|
||||||
System.out.println(star);
|
LOGGER.info(star.toString());
|
||||||
states.add(star.getMemento());
|
states.add(star.getMemento());
|
||||||
star.timePasses();
|
star.timePasses();
|
||||||
System.out.println(star);
|
LOGGER.info(star.toString());
|
||||||
states.add(star.getMemento());
|
states.add(star.getMemento());
|
||||||
star.timePasses();
|
star.timePasses();
|
||||||
System.out.println(star);
|
LOGGER.info(star.toString());
|
||||||
states.add(star.getMemento());
|
states.add(star.getMemento());
|
||||||
star.timePasses();
|
star.timePasses();
|
||||||
System.out.println(star);
|
LOGGER.info(star.toString());
|
||||||
states.add(star.getMemento());
|
states.add(star.getMemento());
|
||||||
star.timePasses();
|
star.timePasses();
|
||||||
System.out.println(star);
|
LOGGER.info(star.toString());
|
||||||
while (states.size() > 0) {
|
while (states.size() > 0) {
|
||||||
star.setMemento(states.pop());
|
star.setMemento(states.pop());
|
||||||
System.out.println(star);
|
LOGGER.info(star.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,8 @@ package com.iluwatar.message.channel;
|
|||||||
import org.apache.camel.CamelContext;
|
import org.apache.camel.CamelContext;
|
||||||
import org.apache.camel.builder.RouteBuilder;
|
import org.apache.camel.builder.RouteBuilder;
|
||||||
import org.apache.camel.impl.DefaultCamelContext;
|
import org.apache.camel.impl.DefaultCamelContext;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -50,6 +52,8 @@ import org.apache.camel.impl.DefaultCamelContext;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point
|
||||||
*/
|
*/
|
||||||
@ -66,7 +70,7 @@ public class App {
|
|||||||
});
|
});
|
||||||
|
|
||||||
context.start();
|
context.start();
|
||||||
context.getRoutes().stream().forEach(r -> System.out.println(r));
|
context.getRoutes().stream().forEach(r -> LOGGER.info(r.toString()));
|
||||||
context.stop();
|
context.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.model.view.controller;
|
package com.iluwatar.model.view.controller;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* GiantView displays the giant
|
* GiantView displays the giant
|
||||||
@ -29,7 +32,9 @@ package com.iluwatar.model.view.controller;
|
|||||||
*/
|
*/
|
||||||
public class GiantView {
|
public class GiantView {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(GiantView.class);
|
||||||
|
|
||||||
public void displayGiant(GiantModel giant) {
|
public void displayGiant(GiantModel giant) {
|
||||||
System.out.println(giant);
|
LOGGER.info(giant.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.monad;
|
package com.iluwatar.monad;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
@ -42,6 +45,8 @@ import java.util.function.Predicate;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point.
|
* Program entry point.
|
||||||
*
|
*
|
||||||
@ -49,7 +54,7 @@ public class App {
|
|||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
User user = new User("user", 24, Sex.FEMALE, "foobar.com");
|
User user = new User("user", 24, Sex.FEMALE, "foobar.com");
|
||||||
System.out.println(Validator.of(user).validate(User::getName, Objects::nonNull, "name is null")
|
LOGGER.info(Validator.of(user).validate(User::getName, Objects::nonNull, "name is null")
|
||||||
.validate(User::getName, name -> !name.isEmpty(), "name is empty")
|
.validate(User::getName, name -> !name.isEmpty(), "name is empty")
|
||||||
.validate(User::getEmail, email -> !email.contains("@"), "email doesn't containt '@'")
|
.validate(User::getEmail, email -> !email.contains("@"), "email doesn't containt '@'")
|
||||||
.validate(User::getAge, age -> age > 20 && age < 30, "age isn't between...").get().toString());
|
.validate(User::getAge, age -> age > 20 && age < 30, "age isn't between...").get().toString());
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.monostate;
|
package com.iluwatar.monostate;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* The Server class. Each Server sits behind a LoadBalancer which delegates the call to the servers
|
* The Server class. Each Server sits behind a LoadBalancer which delegates the call to the servers
|
||||||
@ -29,6 +32,9 @@ package com.iluwatar.monostate;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Server {
|
public class Server {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Server.class);
|
||||||
|
|
||||||
public final String host;
|
public final String host;
|
||||||
public final int port;
|
public final int port;
|
||||||
public final int id;
|
public final int id;
|
||||||
@ -51,7 +57,7 @@ public class Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void serve(Request request) {
|
public void serve(Request request) {
|
||||||
System.out.println("Server ID " + id + " associated to host : " + getHost() + " and Port "
|
LOGGER.info("Server ID {} associated to host : {} and port {}. Processed request with value {}",
|
||||||
+ getPort() + " Processed request with value " + request.value);
|
id, host, port, request.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.multiton;
|
package com.iluwatar.multiton;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Whereas Singleton design pattern introduces single globally accessible object the Multiton
|
* Whereas Singleton design pattern introduces single globally accessible object the Multiton
|
||||||
@ -35,20 +38,22 @@ package com.iluwatar.multiton;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point
|
||||||
*
|
*
|
||||||
* @param args command line args
|
* @param args command line args
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("KHAMUL=" + Nazgul.getInstance(NazgulName.KHAMUL));
|
LOGGER.info("KHAMUL={}", Nazgul.getInstance(NazgulName.KHAMUL));
|
||||||
System.out.println("MURAZOR=" + Nazgul.getInstance(NazgulName.MURAZOR));
|
LOGGER.info("MURAZOR={}", Nazgul.getInstance(NazgulName.MURAZOR));
|
||||||
System.out.println("DWAR=" + Nazgul.getInstance(NazgulName.DWAR));
|
LOGGER.info("DWAR={}", Nazgul.getInstance(NazgulName.DWAR));
|
||||||
System.out.println("JI_INDUR=" + Nazgul.getInstance(NazgulName.JI_INDUR));
|
LOGGER.info("JI_INDUR={}", Nazgul.getInstance(NazgulName.JI_INDUR));
|
||||||
System.out.println("AKHORAHIL=" + Nazgul.getInstance(NazgulName.AKHORAHIL));
|
LOGGER.info("AKHORAHIL={}", Nazgul.getInstance(NazgulName.AKHORAHIL));
|
||||||
System.out.println("HOARMURATH=" + Nazgul.getInstance(NazgulName.HOARMURATH));
|
LOGGER.info("HOARMURATH={}", Nazgul.getInstance(NazgulName.HOARMURATH));
|
||||||
System.out.println("ADUNAPHEL=" + Nazgul.getInstance(NazgulName.ADUNAPHEL));
|
LOGGER.info("ADUNAPHEL={}", Nazgul.getInstance(NazgulName.ADUNAPHEL));
|
||||||
System.out.println("REN=" + Nazgul.getInstance(NazgulName.REN));
|
LOGGER.info("REN={}", Nazgul.getInstance(NazgulName.REN));
|
||||||
System.out.println("UVATHA=" + Nazgul.getInstance(NazgulName.UVATHA));
|
LOGGER.info("UVATHA={}", Nazgul.getInstance(NazgulName.UVATHA));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,9 @@
|
|||||||
|
|
||||||
package com.iluwatar.mute;
|
package com.iluwatar.mute;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -46,6 +49,8 @@ import java.sql.SQLException;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point.
|
* Program entry point.
|
||||||
*
|
*
|
||||||
@ -88,7 +93,7 @@ public class App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void utilizeResource(Resource resource) throws SQLException {
|
private static void utilizeResource(Resource resource) throws SQLException {
|
||||||
System.out.println("Utilizing acquired resource: " + resource);
|
LOGGER.info("Utilizing acquired resource: {}", resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Resource acquireResource() throws SQLException {
|
private static Resource acquireResource() throws SQLException {
|
||||||
|
@ -32,9 +32,13 @@ import java.io.PrintStream;
|
|||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
import org.junit.rules.ExpectedException;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class MuteTest {
|
public class MuteTest {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(MuteTest.class);
|
||||||
|
|
||||||
private static final String MESSAGE = "should not occur";
|
private static final String MESSAGE = "should not occur";
|
||||||
|
|
||||||
@Rule public ExpectedException exception = ExpectedException.none();
|
@Rule public ExpectedException exception = ExpectedException.none();
|
||||||
@ -69,7 +73,7 @@ public class MuteTest {
|
|||||||
|
|
||||||
|
|
||||||
private void methodNotThrowingAnyException() {
|
private void methodNotThrowingAnyException() {
|
||||||
System.out.println("Executed successfully");
|
LOGGER.info("Executed successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void methodThrowingException() throws Exception {
|
private void methodThrowingException() throws Exception {
|
||||||
|
@ -22,12 +22,17 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.mutex;
|
package com.iluwatar.mutex;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thief is a class which continually tries to acquire a jar and take a bean
|
* Thief is a class which continually tries to acquire a jar and take a bean
|
||||||
* from it. When the jar is empty the thief stops.
|
* from it. When the jar is empty the thief stops.
|
||||||
*/
|
*/
|
||||||
public class Thief extends Thread {
|
public class Thief extends Thread {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Thief.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the thief.
|
* The name of the thief.
|
||||||
*/
|
*/
|
||||||
@ -53,10 +58,10 @@ public class Thief extends Thread {
|
|||||||
|
|
||||||
while (jar.takeBean()) {
|
while (jar.takeBean()) {
|
||||||
beans = beans + 1;
|
beans = beans + 1;
|
||||||
System.out.println(name + " took a bean.");
|
LOGGER.info("{} took a bean.", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(name + " took " + beans + " beans.");
|
LOGGER.info("{} took {} beans.", name, beans);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
# Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
# or more contributor license agreements. See the NOTICE file
|
|
||||||
# distributed with this work for additional information
|
|
||||||
# regarding copyright ownership. The ASF licenses this file
|
|
||||||
# to you under the Apache License, Version 2.0 (the
|
|
||||||
# "License"); you may not use this file except in compliance
|
|
||||||
# with the License. You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing,
|
|
||||||
# software distributed under the License is distributed on an
|
|
||||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
# KIND, either express or implied. See the License for the
|
|
||||||
# specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
|
|
||||||
# LOG4J Configuration
|
|
||||||
# ===================
|
|
||||||
|
|
||||||
# Basic logging goes to "datanucleus.log"
|
|
||||||
log4j.appender.A1=org.apache.log4j.FileAppender
|
|
||||||
log4j.appender.A1.File=datanucleus.log
|
|
||||||
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss,SSS} (%t) %-5p [%c] - %m%n
|
|
||||||
#log4j.appender.A1.Threshold=INFO
|
|
||||||
|
|
||||||
# Categories
|
|
||||||
# Each category can be set to a "level", and to direct to an appender
|
|
||||||
|
|
||||||
# Default to DEBUG level for all DataNucleus categories
|
|
||||||
log4j.logger.DataNucleus = DEBUG, A1
|
|
||||||
|
|
||||||
log4j.category.com.mchange.v2.c3p0=INFO, A1
|
|
||||||
log4j.category.com.mchange.v2.resourcepool=INFO, A1
|
|
||||||
log4j.category.org.logicalcobwebs.proxool=INFO,A1
|
|
||||||
|
|
||||||
|
|
||||||
# Hbase libs logging
|
|
||||||
log4j.category.org.apache.hadoop=INFO,A1
|
|
||||||
log4j.category.org.apache.zookeeper=INFO,A1
|
|
@ -1,111 +0,0 @@
|
|||||||
# Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
# or more contributor license agreements. See the NOTICE file
|
|
||||||
# distributed with this work for additional information
|
|
||||||
# regarding copyright ownership. The ASF licenses this file
|
|
||||||
# to you under the Apache License, Version 2.0 (the
|
|
||||||
# "License"); you may not use this file except in compliance
|
|
||||||
# with the License. You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing,
|
|
||||||
# software distributed under the License is distributed on an
|
|
||||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
# KIND, either express or implied. See the License for the
|
|
||||||
# specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# Isis uses log4j is used to provide system logging
|
|
||||||
#
|
|
||||||
log4j.rootCategory=INFO, Console
|
|
||||||
|
|
||||||
# The console appender
|
|
||||||
log4j.appender.Console=org.apache.log4j.ConsoleAppender
|
|
||||||
log4j.appender.Console.target=System.out
|
|
||||||
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} [%-20c{1} %-10t %-5p] %m%n
|
|
||||||
|
|
||||||
log4j.appender.File=org.apache.log4j.RollingFileAppender
|
|
||||||
log4j.appender.File.file=isis.log
|
|
||||||
log4j.appender.File.append=false
|
|
||||||
log4j.appender.File.layout=org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.File.layout.ConversionPattern=%d [%-20c{1} %-10t %-5p] %m%n
|
|
||||||
|
|
||||||
log4j.appender.translations-po=org.apache.log4j.FileAppender
|
|
||||||
log4j.appender.translations-po.File=./translations.pot
|
|
||||||
log4j.appender.translations-po.Append=false
|
|
||||||
log4j.appender.translations-po.layout=org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.translations-po.layout.ConversionPattern=%m%n
|
|
||||||
|
|
||||||
! turn on the internal log4j debugging flag so we can see what it is doing
|
|
||||||
#log4j.debug=true
|
|
||||||
|
|
||||||
|
|
||||||
# DataNucleus
|
|
||||||
# the first two log the DML and DDL (if set to DEBUG)
|
|
||||||
log4j.logger.DataNucleus.Datastore.Native=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.Datastore.Schema=DEBUG, Console
|
|
||||||
# the remainder can probably be left to WARN
|
|
||||||
log4j.logger.DataNucleus.Persistence=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.Transaction=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.Connection=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.Query=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.Cache=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.MetaData=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.Datastore=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.Datastore.Persist=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.Datastore.Retrieve=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.General=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.Lifecycle=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.ValueGeneration=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.Enhancer=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.SchemaTool=ERROR, Console
|
|
||||||
log4j.logger.DataNucleus.JDO=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.JPA=ERROR, Console
|
|
||||||
log4j.logger.DataNucleus.JCA=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.IDE=ERROR, Console
|
|
||||||
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Native=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Schema=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Persistence=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Transaction=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Connection=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Query=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Cache=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.MetaData=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Datastore=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Datastore.Persist=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Datastore.Retrieve=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.General=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Lifecycle=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.ValueGeneration=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Enhancer=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.SchemaTool=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.JDO=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.JPA=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.JCA=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.IDE=false
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# if using log4jdbc-remix as JDBC driver
|
|
||||||
#log4j.logger.jdbc.sqlonly=DEBUG, sql, Console
|
|
||||||
#log4j.additivity.jdbc.sqlonly=false
|
|
||||||
#log4j.logger.jdbc.resultsettable=DEBUG, jdbc, Console
|
|
||||||
#log4j.additivity.jdbc.resultsettable=false
|
|
||||||
|
|
||||||
#log4j.logger.jdbc.audit=WARN,jdbc, Console
|
|
||||||
#log4j.additivity.jdbc.audit=false
|
|
||||||
#log4j.logger.jdbc.resultset=WARN,jdbc
|
|
||||||
#log4j.additivity.jdbc.resultset=false
|
|
||||||
#log4j.logger.jdbc.sqltiming=WARN,sqltiming
|
|
||||||
#log4j.additivity.jdbc.sqltiming=false
|
|
||||||
#log4j.logger.jdbc.connection=FATAL,connection
|
|
||||||
#log4j.additivity.jdbc.connection=false
|
|
||||||
|
|
||||||
|
|
||||||
log4j.logger.org.apache.isis.core.runtime.services.i18n.po.PoWriter=INFO,translations-po
|
|
||||||
log4j.additivity.org.apache.isis.core.runtime.services.i18n.po.PotWriter=false
|
|
@ -1,187 +0,0 @@
|
|||||||
# Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
# or more contributor license agreements. See the NOTICE file
|
|
||||||
# distributed with this work for additional information
|
|
||||||
# regarding copyright ownership. The ASF licenses this file
|
|
||||||
# to you under the Apache License, Version 2.0 (the
|
|
||||||
# "License"); you may not use this file except in compliance
|
|
||||||
# with the License. You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing,
|
|
||||||
# software distributed under the License is distributed on an
|
|
||||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
# KIND, either express or implied. See the License for the
|
|
||||||
# specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# Isis uses log4j is used to provide system logging
|
|
||||||
#
|
|
||||||
log4j.rootCategory=INFO, Console
|
|
||||||
#log4j.rootCategory=DEBUG, Console
|
|
||||||
|
|
||||||
|
|
||||||
# The console appender
|
|
||||||
log4j.appender.Console=org.apache.log4j.ConsoleAppender
|
|
||||||
log4j.appender.Console.target=System.out
|
|
||||||
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} [%-20c{1} %-10t %-5p] %m%n
|
|
||||||
|
|
||||||
|
|
||||||
# The stderr appender
|
|
||||||
log4j.appender.Stderr=org.apache.log4j.ConsoleAppender
|
|
||||||
log4j.appender.Stderr.target=System.err
|
|
||||||
log4j.appender.Stderr.layout=org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.Stderr.layout.ConversionPattern=%d{ABSOLUTE} [%-20c{1} %-10t %-5p] %m%n
|
|
||||||
|
|
||||||
|
|
||||||
# other appenders
|
|
||||||
log4j.appender.File=org.apache.log4j.RollingFileAppender
|
|
||||||
log4j.appender.File.file=isis.log
|
|
||||||
log4j.appender.File.append=false
|
|
||||||
log4j.appender.File.layout=org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.File.layout.ConversionPattern=%d [%-20c{1} %-10t %-5p] %m%n
|
|
||||||
|
|
||||||
log4j.appender.sql=org.apache.log4j.FileAppender
|
|
||||||
log4j.appender.sql.File=./logs/sql.log
|
|
||||||
log4j.appender.sql.Append=false
|
|
||||||
log4j.appender.sql.layout=org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.sql.layout.ConversionPattern=-----> %d{yyyy-MM-dd HH:mm:ss.SSS} %m%n%n
|
|
||||||
|
|
||||||
log4j.appender.sqltiming=org.apache.log4j.FileAppender
|
|
||||||
log4j.appender.sqltiming.File=./logs/sqltiming.log
|
|
||||||
log4j.appender.sqltiming.Append=false
|
|
||||||
log4j.appender.sqltiming.layout=org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.sqltiming.layout.ConversionPattern=-----> %d{yyyy-MM-dd HH:mm:ss.SSS} %m%n%n
|
|
||||||
|
|
||||||
log4j.appender.jdbc=org.apache.log4j.FileAppender
|
|
||||||
log4j.appender.jdbc.File=./logs/jdbc.log
|
|
||||||
log4j.appender.jdbc.Append=false
|
|
||||||
log4j.appender.jdbc.layout=org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.jdbc.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} %m%n
|
|
||||||
|
|
||||||
log4j.appender.connection=org.apache.log4j.FileAppender
|
|
||||||
log4j.appender.connection.File=./logs/connection.log
|
|
||||||
log4j.appender.connection.Append=false
|
|
||||||
log4j.appender.connection.layout=org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.connection.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} %m%n
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
! turn on the internal log4j debugging flag so we can see what it is doing
|
|
||||||
#log4j.debug=true
|
|
||||||
|
|
||||||
|
|
||||||
# DataNucleus
|
|
||||||
# the first two log the DML and DDL (if set to DEBUG)
|
|
||||||
log4j.logger.DataNucleus.Datastore.Native=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.Datastore.Schema=DEBUG, Console
|
|
||||||
# the remainder can probably be left to WARN
|
|
||||||
log4j.logger.DataNucleus.Persistence=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.Transaction=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.Connection=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.Query=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.Cache=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.MetaData=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.Datastore=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.Datastore.Persist=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.Datastore.Retrieve=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.General=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.Lifecycle=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.ValueGeneration=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.Enhancer=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.SchemaTool=ERROR, Console
|
|
||||||
log4j.logger.DataNucleus.JDO=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.JPA=ERROR, Console
|
|
||||||
log4j.logger.DataNucleus.JCA=WARN, Console
|
|
||||||
log4j.logger.DataNucleus.IDE=ERROR, Console
|
|
||||||
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Native=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Schema=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Persistence=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Transaction=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Connection=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Query=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Cache=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.MetaData=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Datastore=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Datastore.Persist=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Datastore.Retrieve=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.General=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Lifecycle=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.ValueGeneration=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.Enhancer=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.SchemaTool=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.JDO=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.JPA=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.JCA=false
|
|
||||||
log4j.additivity.DataNucleus.Datastore.IDE=false
|
|
||||||
|
|
||||||
|
|
||||||
# if using log4jdbc-remix as JDBC driver
|
|
||||||
#log4j.logger.jdbc.sqlonly=DEBUG, sql, Console
|
|
||||||
#log4j.additivity.jdbc.sqlonly=false
|
|
||||||
#log4j.logger.jdbc.resultsettable=DEBUG, jdbc, Console
|
|
||||||
#log4j.additivity.jdbc.resultsettable=false
|
|
||||||
|
|
||||||
#log4j.logger.jdbc.audit=WARN,jdbc, Console
|
|
||||||
#log4j.additivity.jdbc.audit=false
|
|
||||||
#log4j.logger.jdbc.resultset=WARN,jdbc
|
|
||||||
#log4j.additivity.jdbc.resultset=false
|
|
||||||
#log4j.logger.jdbc.sqltiming=WARN,sqltiming
|
|
||||||
#log4j.additivity.jdbc.sqltiming=false
|
|
||||||
#log4j.logger.jdbc.connection=FATAL,connection
|
|
||||||
#log4j.additivity.jdbc.connection=false
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# track Isis/JDO lifecycle integration
|
|
||||||
|
|
||||||
#log4j.logger.org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.persistence.FrameworkSynchronizer=DEBUG, Console
|
|
||||||
#log4j.additivity.org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.persistence.FrameworkSynchronizer=false
|
|
||||||
|
|
||||||
#log4j.logger.org.apache.isis.objectstore.jdo.datanucleus.persistence.IsisLifecycleListener=DEBUG,Console
|
|
||||||
#log4j.additivity.org.apache.isis.objectstore.jdo.datanucleus.persistence.IsisLifecycleListener=false
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# track Isis/Wicket lifecycle integration
|
|
||||||
|
|
||||||
#log4j.logger.org.apache.isis.viewer.wicket.viewer.integration.wicket.WebRequestCycleForIsis=DEBUG, Console
|
|
||||||
#log4j.additivity.org.apache.isis.viewer.wicket.viewer.integration.wicket.WebRequestCycleForIsis=false
|
|
||||||
|
|
||||||
#log4j.logger.org.apache.isis.viewer.wicket.viewer.integration.isis.IsisContextForWicket=INFO,Console
|
|
||||||
#log4j.additivity.org.apache.isis.viewer.wicket.viewer.integration.isis.IsisContextForWicket=false
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# quieten some of the noisier classes in Isis' bootstrapping
|
|
||||||
log4j.logger.org.apache.isis.core.metamodel.specloader.specimpl.FacetedMethodsBuilder=WARN,Console
|
|
||||||
log4j.additivity.org.apache.isis.core.metamodel.specloader.specimpl.FacetedMethodsBuilder=false
|
|
||||||
|
|
||||||
log4j.logger.org.apache.isis.core.metamodel.specloader.ServiceInitializer=WARN,Console
|
|
||||||
log4j.additivity.org.apache.isis.core.metamodel.specloader.ServiceInitializer=false
|
|
||||||
|
|
||||||
log4j.logger.org.apache.isis.core.runtime.services.ServicesInstallerFromConfiguration=WARN,Console
|
|
||||||
log4j.additivity.org.apache.isis.core.runtime.services.ServicesInstallerFromConfiguration=false
|
|
||||||
|
|
||||||
log4j.logger.org.apache.isis.core.commons.config.IsisConfigurationDefault=WARN,Console
|
|
||||||
log4j.additivity.org.apache.isis.core.commons.config.IsisConfigurationDefault=false
|
|
||||||
|
|
||||||
log4j.logger.org.apache.isis.core.runtime.installers.InstallerLookupDefault=WARN,Console
|
|
||||||
log4j.additivity.org.apache.isis.core.runtime.installers.InstallerLookupDefault=false
|
|
||||||
|
|
||||||
|
|
||||||
# quieten Shiro
|
|
||||||
log4j.logger.org.apache.shiro.realm.AuthorizingRealm=WARN,Console
|
|
||||||
log4j.additivity.log4j.logger.org.apache.shiro.realm.AuthorizingRealm=false
|
|
||||||
|
|
||||||
|
|
||||||
# Application-specific logging
|
|
||||||
log4j.logger.dom.simple.SimpleObject=DEBUG, Stderr
|
|
||||||
log4j.additivity.dom.simple.SimpleObject=false
|
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.nullobject;
|
package com.iluwatar.nullobject;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Implementation for binary tree's normal nodes.
|
* Implementation for binary tree's normal nodes.
|
||||||
@ -29,6 +32,8 @@ package com.iluwatar.nullobject;
|
|||||||
*/
|
*/
|
||||||
public class NodeImpl implements Node {
|
public class NodeImpl implements Node {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(NodeImpl.class);
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final Node left;
|
private final Node left;
|
||||||
private final Node right;
|
private final Node right;
|
||||||
@ -64,7 +69,7 @@ public class NodeImpl implements Node {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void walk() {
|
public void walk() {
|
||||||
System.out.println(name);
|
LOGGER.info(name);
|
||||||
if (left.getTreeSize() > 0) {
|
if (left.getTreeSize() > 0) {
|
||||||
left.walk();
|
left.walk();
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.object.pool;
|
package com.iluwatar.object.pool;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* When it is necessary to work with a large number of objects that are particularly expensive to
|
* When it is necessary to work with a large number of objects that are particularly expensive to
|
||||||
@ -44,6 +47,8 @@ package com.iluwatar.object.pool;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point
|
||||||
*
|
*
|
||||||
@ -51,24 +56,24 @@ public class App {
|
|||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
OliphauntPool pool = new OliphauntPool();
|
OliphauntPool pool = new OliphauntPool();
|
||||||
System.out.println(pool);
|
LOGGER.info(pool.toString());
|
||||||
Oliphaunt oliphaunt1 = pool.checkOut();
|
Oliphaunt oliphaunt1 = pool.checkOut();
|
||||||
System.out.println("Checked out " + oliphaunt1);
|
LOGGER.info("Checked out {}", oliphaunt1);
|
||||||
System.out.println(pool);
|
LOGGER.info(pool.toString());
|
||||||
Oliphaunt oliphaunt2 = pool.checkOut();
|
Oliphaunt oliphaunt2 = pool.checkOut();
|
||||||
System.out.println("Checked out " + oliphaunt2);
|
LOGGER.info("Checked out {}", oliphaunt2);
|
||||||
Oliphaunt oliphaunt3 = pool.checkOut();
|
Oliphaunt oliphaunt3 = pool.checkOut();
|
||||||
System.out.println("Checked out " + oliphaunt3);
|
LOGGER.info("Checked out {}", oliphaunt3);
|
||||||
System.out.println(pool);
|
LOGGER.info(pool.toString());
|
||||||
System.out.println("Checking in " + oliphaunt1);
|
LOGGER.info("Checking in {}", oliphaunt1);
|
||||||
pool.checkIn(oliphaunt1);
|
pool.checkIn(oliphaunt1);
|
||||||
System.out.println("Checking in " + oliphaunt2);
|
LOGGER.info("Checking in {}", oliphaunt2);
|
||||||
pool.checkIn(oliphaunt2);
|
pool.checkIn(oliphaunt2);
|
||||||
System.out.println(pool);
|
LOGGER.info(pool.toString());
|
||||||
Oliphaunt oliphaunt4 = pool.checkOut();
|
Oliphaunt oliphaunt4 = pool.checkOut();
|
||||||
System.out.println("Checked out " + oliphaunt4);
|
LOGGER.info("Checked out {}", oliphaunt4);
|
||||||
Oliphaunt oliphaunt5 = pool.checkOut();
|
Oliphaunt oliphaunt5 = pool.checkOut();
|
||||||
System.out.println("Checked out " + oliphaunt5);
|
LOGGER.info("Checked out {}", oliphaunt5);
|
||||||
System.out.println(pool);
|
LOGGER.info(pool.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,8 @@ package com.iluwatar.observer;
|
|||||||
import com.iluwatar.observer.generic.GHobbits;
|
import com.iluwatar.observer.generic.GHobbits;
|
||||||
import com.iluwatar.observer.generic.GOrcs;
|
import com.iluwatar.observer.generic.GOrcs;
|
||||||
import com.iluwatar.observer.generic.GWeather;
|
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 {
|
public class App {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point
|
||||||
*
|
*
|
||||||
@ -58,7 +62,7 @@ public class App {
|
|||||||
weather.timePasses();
|
weather.timePasses();
|
||||||
|
|
||||||
// Generic observer inspired by Java Generics and Collection by Naftalin & Wadler
|
// 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 gWeather = new GWeather();
|
||||||
gWeather.addObserver(new GOrcs());
|
gWeather.addObserver(new GOrcs());
|
||||||
gWeather.addObserver(new GHobbits());
|
gWeather.addObserver(new GHobbits());
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.observer;
|
package com.iluwatar.observer;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Hobbits
|
* Hobbits
|
||||||
@ -29,20 +32,22 @@ package com.iluwatar.observer;
|
|||||||
*/
|
*/
|
||||||
public class Hobbits implements WeatherObserver {
|
public class Hobbits implements WeatherObserver {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Hobbits.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(WeatherType currentWeather) {
|
public void update(WeatherType currentWeather) {
|
||||||
switch (currentWeather) {
|
switch (currentWeather) {
|
||||||
case COLD:
|
case COLD:
|
||||||
System.out.println("The hobbits are shivering in the cold weather.");
|
LOGGER.info("The hobbits are shivering in the cold weather.");
|
||||||
break;
|
break;
|
||||||
case RAINY:
|
case RAINY:
|
||||||
System.out.println("The hobbits look for cover from the rain.");
|
LOGGER.info("The hobbits look for cover from the rain.");
|
||||||
break;
|
break;
|
||||||
case SUNNY:
|
case SUNNY:
|
||||||
System.out.println("The happy hobbits bade in the warm sun.");
|
LOGGER.info("The happy hobbits bade in the warm sun.");
|
||||||
break;
|
break;
|
||||||
case WINDY:
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.observer;
|
package com.iluwatar.observer;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Orcs
|
* Orcs
|
||||||
@ -29,20 +32,22 @@ package com.iluwatar.observer;
|
|||||||
*/
|
*/
|
||||||
public class Orcs implements WeatherObserver {
|
public class Orcs implements WeatherObserver {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Orcs.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(WeatherType currentWeather) {
|
public void update(WeatherType currentWeather) {
|
||||||
switch (currentWeather) {
|
switch (currentWeather) {
|
||||||
case COLD:
|
case COLD:
|
||||||
System.out.println("The orcs are freezing cold.");
|
LOGGER.info("The orcs are freezing cold.");
|
||||||
break;
|
break;
|
||||||
case RAINY:
|
case RAINY:
|
||||||
System.out.println("The orcs are dripping wet.");
|
LOGGER.info("The orcs are dripping wet.");
|
||||||
break;
|
break;
|
||||||
case SUNNY:
|
case SUNNY:
|
||||||
System.out.println("The sun hurts the orcs' eyes.");
|
LOGGER.info("The sun hurts the orcs' eyes.");
|
||||||
break;
|
break;
|
||||||
case WINDY:
|
case WINDY:
|
||||||
System.out.println("The orc smell almost vanishes in the wind.");
|
LOGGER.info("The orc smell almost vanishes in the wind.");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.observer;
|
package com.iluwatar.observer;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -33,6 +36,8 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class Weather {
|
public class Weather {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Weather.class);
|
||||||
|
|
||||||
private WeatherType currentWeather;
|
private WeatherType currentWeather;
|
||||||
private List<WeatherObserver> observers;
|
private List<WeatherObserver> observers;
|
||||||
|
|
||||||
@ -55,7 +60,7 @@ public class Weather {
|
|||||||
public void timePasses() {
|
public void timePasses() {
|
||||||
WeatherType[] enumValues = WeatherType.values();
|
WeatherType[] enumValues = WeatherType.values();
|
||||||
currentWeather = enumValues[(currentWeather.ordinal() + 1) % enumValues.length];
|
currentWeather = enumValues[(currentWeather.ordinal() + 1) % enumValues.length];
|
||||||
System.out.println("The weather changed to " + currentWeather + ".");
|
LOGGER.info("The weather changed to {}.", currentWeather);
|
||||||
notifyObservers();
|
notifyObservers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
package com.iluwatar.observer.generic;
|
package com.iluwatar.observer.generic;
|
||||||
|
|
||||||
import com.iluwatar.observer.WeatherType;
|
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 {
|
public class GHobbits implements Race {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(GHobbits.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(GWeather weather, WeatherType weatherType) {
|
public void update(GWeather weather, WeatherType weatherType) {
|
||||||
switch (weatherType) {
|
switch (weatherType) {
|
||||||
case COLD:
|
case COLD:
|
||||||
System.out.println("The hobbits are shivering in the cold weather.");
|
LOGGER.info("The hobbits are shivering in the cold weather.");
|
||||||
break;
|
break;
|
||||||
case RAINY:
|
case RAINY:
|
||||||
System.out.println("The hobbits look for cover from the rain.");
|
LOGGER.info("The hobbits look for cover from the rain.");
|
||||||
break;
|
break;
|
||||||
case SUNNY:
|
case SUNNY:
|
||||||
System.out.println("The happy hobbits bade in the warm sun.");
|
LOGGER.info("The happy hobbits bade in the warm sun.");
|
||||||
break;
|
break;
|
||||||
case WINDY:
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
package com.iluwatar.observer.generic;
|
package com.iluwatar.observer.generic;
|
||||||
|
|
||||||
import com.iluwatar.observer.WeatherType;
|
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 {
|
public class GOrcs implements Race {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(GOrcs.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(GWeather weather, WeatherType weatherType) {
|
public void update(GWeather weather, WeatherType weatherType) {
|
||||||
switch (weatherType) {
|
switch (weatherType) {
|
||||||
case COLD:
|
case COLD:
|
||||||
System.out.println("The orcs are freezing cold.");
|
LOGGER.info("The orcs are freezing cold.");
|
||||||
break;
|
break;
|
||||||
case RAINY:
|
case RAINY:
|
||||||
System.out.println("The orcs are dripping wet.");
|
LOGGER.info("The orcs are dripping wet.");
|
||||||
break;
|
break;
|
||||||
case SUNNY:
|
case SUNNY:
|
||||||
System.out.println("The sun hurts the orcs' eyes.");
|
LOGGER.info("The sun hurts the orcs' eyes.");
|
||||||
break;
|
break;
|
||||||
case WINDY:
|
case WINDY:
|
||||||
System.out.println("The orc smell almost vanishes in the wind.");
|
LOGGER.info("The orc smell almost vanishes in the wind.");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
package com.iluwatar.observer.generic;
|
package com.iluwatar.observer.generic;
|
||||||
|
|
||||||
import com.iluwatar.observer.WeatherType;
|
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> {
|
public class GWeather extends Observable<GWeather, Race, WeatherType> {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(GWeather.class);
|
||||||
|
|
||||||
private WeatherType currentWeather;
|
private WeatherType currentWeather;
|
||||||
|
|
||||||
public GWeather() {
|
public GWeather() {
|
||||||
@ -43,7 +47,7 @@ public class GWeather extends Observable<GWeather, Race, WeatherType> {
|
|||||||
public void timePasses() {
|
public void timePasses() {
|
||||||
WeatherType[] enumValues = WeatherType.values();
|
WeatherType[] enumValues = WeatherType.values();
|
||||||
currentWeather = enumValues[(currentWeather.ordinal() + 1) % enumValues.length];
|
currentWeather = enumValues[(currentWeather.ordinal() + 1) % enumValues.length];
|
||||||
System.out.println("The weather changed to " + currentWeather + ".");
|
LOGGER.info("The weather changed to {}.", currentWeather);
|
||||||
notifyObservers(currentWeather);
|
notifyObservers(currentWeather);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,11 +23,15 @@
|
|||||||
package com.iluwatar.poison.pill;
|
package com.iluwatar.poison.pill;
|
||||||
|
|
||||||
import com.iluwatar.poison.pill.Message.Headers;
|
import com.iluwatar.poison.pill.Message.Headers;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class responsible for receiving and handling submitted to the queue messages
|
* Class responsible for receiving and handling submitted to the queue messages
|
||||||
*/
|
*/
|
||||||
public class Consumer {
|
public class Consumer {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Consumer.class);
|
||||||
|
|
||||||
private final MqSubscribePoint queue;
|
private final MqSubscribePoint queue;
|
||||||
private final String name;
|
private final String name;
|
||||||
@ -46,19 +50,18 @@ public class Consumer {
|
|||||||
try {
|
try {
|
||||||
msg = queue.take();
|
msg = queue.take();
|
||||||
if (Message.POISON_PILL.equals(msg)) {
|
if (Message.POISON_PILL.equals(msg)) {
|
||||||
System.out.println(String.format("Consumer %s receive request to terminate.", name));
|
LOGGER.info("Consumer {} receive request to terminate.", name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// allow thread to exit
|
// allow thread to exit
|
||||||
System.err.println(e);
|
LOGGER.error("Exception caught.", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String sender = msg.getHeader(Headers.SENDER);
|
String sender = msg.getHeader(Headers.SENDER);
|
||||||
String body = msg.getBody();
|
String body = msg.getBody();
|
||||||
System.out.println(String.format("Message [%s] from [%s] received by [%s]", body, sender,
|
LOGGER.info("Message [{}] from [{}] received by [{}]", body, sender, name);
|
||||||
name));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,8 @@ package com.iluwatar.poison.pill;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import com.iluwatar.poison.pill.Message.Headers;
|
import com.iluwatar.poison.pill.Message.Headers;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class responsible for producing unit of work that can be expressed as message and submitted to
|
* Class responsible for producing unit of work that can be expressed as message and submitted to
|
||||||
@ -32,6 +34,8 @@ import com.iluwatar.poison.pill.Message.Headers;
|
|||||||
*/
|
*/
|
||||||
public class Producer {
|
public class Producer {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Producer.class);
|
||||||
|
|
||||||
private final MqPublishPoint queue;
|
private final MqPublishPoint queue;
|
||||||
private final String name;
|
private final String name;
|
||||||
private boolean isStopped;
|
private boolean isStopped;
|
||||||
@ -62,7 +66,7 @@ public class Producer {
|
|||||||
queue.put(msg);
|
queue.put(msg);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// allow thread to exit
|
// allow thread to exit
|
||||||
System.err.println(e);
|
LOGGER.error("Exception caught.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +79,7 @@ public class Producer {
|
|||||||
queue.put(Message.POISON_PILL);
|
queue.put(Message.POISON_PILL);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// allow thread to exit
|
// allow thread to exit
|
||||||
System.err.println(e);
|
LOGGER.error("Exception caught.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
25
pom.xml
25
pom.xml
@ -39,7 +39,6 @@
|
|||||||
<jacoco.version>0.7.2.201409121644</jacoco.version>
|
<jacoco.version>0.7.2.201409121644</jacoco.version>
|
||||||
<commons-dbcp.version>1.4</commons-dbcp.version>
|
<commons-dbcp.version>1.4</commons-dbcp.version>
|
||||||
<camel.version>2.16.1</camel.version>
|
<camel.version>2.16.1</camel.version>
|
||||||
<log4j.version>1.2.17</log4j.version>
|
|
||||||
<guava.version>19.0</guava.version>
|
<guava.version>19.0</guava.version>
|
||||||
<systemrules.version>1.15.1</systemrules.version>
|
<systemrules.version>1.15.1</systemrules.version>
|
||||||
<mockito.version>1.10.19</mockito.version>
|
<mockito.version>1.10.19</mockito.version>
|
||||||
@ -49,6 +48,8 @@
|
|||||||
<urm.version>1.4.1</urm.version>
|
<urm.version>1.4.1</urm.version>
|
||||||
<guice.version>4.0</guice.version>
|
<guice.version>4.0</guice.version>
|
||||||
<mongo-java-driver.version>3.3.0</mongo-java-driver.version>
|
<mongo-java-driver.version>3.3.0</mongo-java-driver.version>
|
||||||
|
<slf4j.version>1.7.21</slf4j.version>
|
||||||
|
<logback.version>1.1.7</logback.version>
|
||||||
</properties>
|
</properties>
|
||||||
<modules>
|
<modules>
|
||||||
<module>abstract-factory</module>
|
<module>abstract-factory</module>
|
||||||
@ -210,11 +211,6 @@
|
|||||||
<version>${mockito.version}</version>
|
<version>${mockito.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>log4j</groupId>
|
|
||||||
<artifactId>log4j</artifactId>
|
|
||||||
<version>${log4j.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
@ -251,6 +247,23 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>${slf4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
<version>${logback.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-core</artifactId>
|
||||||
|
<version>${logback.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<pluginManagement>
|
<pluginManagement>
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.privateclassdata;
|
package com.iluwatar.privateclassdata;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Immutable stew class, protected with Private Class Data pattern
|
* Immutable stew class, protected with Private Class Data pattern
|
||||||
@ -29,6 +32,8 @@ package com.iluwatar.privateclassdata;
|
|||||||
*/
|
*/
|
||||||
public class ImmutableStew {
|
public class ImmutableStew {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(ImmutableStew.class);
|
||||||
|
|
||||||
private StewData data;
|
private StewData data;
|
||||||
|
|
||||||
public ImmutableStew(int numPotatoes, int numCarrots, int numMeat, int numPeppers) {
|
public ImmutableStew(int numPotatoes, int numCarrots, int numMeat, int numPeppers) {
|
||||||
@ -39,8 +44,7 @@ public class ImmutableStew {
|
|||||||
* Mix the stew
|
* Mix the stew
|
||||||
*/
|
*/
|
||||||
public void mix() {
|
public void mix() {
|
||||||
System.out.println(String.format(
|
LOGGER.info("Mixing the immutable stew we find: {} potatoes, {} carrots, {} meat and {} peppers",
|
||||||
"Mixing the immutable stew we find: %d potatoes, %d carrots, %d meat and %d peppers",
|
data.getNumPotatoes(), data.getNumCarrots(), data.getNumMeat(), data.getNumPeppers());
|
||||||
data.getNumPotatoes(), data.getNumCarrots(), data.getNumMeat(), data.getNumPeppers()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.privateclassdata;
|
package com.iluwatar.privateclassdata;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Mutable stew class
|
* Mutable stew class
|
||||||
@ -29,6 +32,8 @@ package com.iluwatar.privateclassdata;
|
|||||||
*/
|
*/
|
||||||
public class Stew {
|
public class Stew {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Stew.class);
|
||||||
|
|
||||||
private int numPotatoes;
|
private int numPotatoes;
|
||||||
private int numCarrots;
|
private int numCarrots;
|
||||||
private int numMeat;
|
private int numMeat;
|
||||||
@ -48,16 +53,15 @@ public class Stew {
|
|||||||
* Mix the stew
|
* Mix the stew
|
||||||
*/
|
*/
|
||||||
public void mix() {
|
public void mix() {
|
||||||
System.out.println(String.format(
|
LOGGER.info("Mixing the stew we find: {} potatoes, {} carrots, {} meat and {} peppers",
|
||||||
"Mixing the stew we find: %d potatoes, %d carrots, %d meat and %d peppers", numPotatoes,
|
numPotatoes, numCarrots, numMeat, numPeppers);
|
||||||
numCarrots, numMeat, numPeppers));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Taste the stew
|
* Taste the stew
|
||||||
*/
|
*/
|
||||||
public void taste() {
|
public void taste() {
|
||||||
System.out.println("Tasting the stew");
|
LOGGER.info("Tasting the stew");
|
||||||
if (numPotatoes > 0) {
|
if (numPotatoes > 0) {
|
||||||
numPotatoes--;
|
numPotatoes--;
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user