diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/App.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/App.java index 3f77a521c..d18f1abed 100644 --- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/App.java +++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/App.java @@ -1,29 +1,37 @@ -package com.iluwatar.abstractfactory; - -/** - * - * The essence of the Abstract Factory pattern is a factory interface - * (KingdomFactory) and its implementations (ElfKingdomFactory, - * OrcKingdomFactory). - * - * The example uses both concrete implementations to create a king, a castle and - * an army. - * - */ -public class App { - - public static void main(String[] args) { - createKingdom(new ElfKingdomFactory()); - createKingdom(new OrcKingdomFactory()); - } - - public static void createKingdom(KingdomFactory factory) { - King king = factory.createKing(); - Castle castle = factory.createCastle(); - Army army = factory.createArmy(); - System.out.println("The kingdom was created."); - System.out.println(king); - System.out.println(castle); - System.out.println(army); - } -} +package com.iluwatar.abstractfactory; + +/** + * + * The essence of the Abstract Factory pattern is a factory interface + * ({@link KingdomFactory}) and its implementations ({@link ElfKingdomFactory}, + * {@link OrcKingdomFactory}). + * <p> + * The example uses both concrete implementations to create a king, a castle and + * an army. + * + */ +public class App { + + /** + * Program entry point + * @param args command line arguments + */ + public static void main(String[] args) { + createKingdom(new ElfKingdomFactory()); + createKingdom(new OrcKingdomFactory()); + } + + /** + * Creates kingdom + * @param factory + */ + public static void createKingdom(KingdomFactory factory) { + King king = factory.createKing(); + Castle castle = factory.createCastle(); + Army army = factory.createArmy(); + System.out.println("The kingdom was created."); + System.out.println(king); + System.out.println(castle); + System.out.println(army); + } +} diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/Army.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/Army.java index 39e023e3b..225331517 100644 --- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/Army.java +++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/Army.java @@ -1,5 +1,10 @@ -package com.iluwatar.abstractfactory; - -public interface Army { - -} +package com.iluwatar.abstractfactory; + +/** + * + * Army interface + * + */ +public interface Army { + +} diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/Castle.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/Castle.java index 277daea56..272a97bf3 100644 --- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/Castle.java +++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/Castle.java @@ -1,5 +1,10 @@ -package com.iluwatar.abstractfactory; - -public interface Castle { - -} +package com.iluwatar.abstractfactory; + +/** + * + * Castle interface + * + */ +public interface Castle { + +} diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfArmy.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfArmy.java index 473106222..d77fe8ebd 100644 --- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfArmy.java +++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfArmy.java @@ -1,10 +1,15 @@ -package com.iluwatar.abstractfactory; - -public class ElfArmy implements Army { - - @Override - public String toString() { - return "This is the Elven Army!"; - } - -} +package com.iluwatar.abstractfactory; + +/** + * + * ElfArmy + * + */ +public class ElfArmy implements Army { + + @Override + public String toString() { + return "This is the Elven Army!"; + } + +} diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfCastle.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfCastle.java index 851baf84f..5c2b2a62a 100644 --- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfCastle.java +++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfCastle.java @@ -1,10 +1,15 @@ -package com.iluwatar.abstractfactory; - -public class ElfCastle implements Castle { - - @Override - public String toString() { - return "This is the Elven castle!"; - } - -} +package com.iluwatar.abstractfactory; + +/** + * + * ElfCastle + * + */ +public class ElfCastle implements Castle { + + @Override + public String toString() { + return "This is the Elven castle!"; + } + +} diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfKing.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfKing.java index eafaccf49..df475a354 100644 --- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfKing.java +++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfKing.java @@ -1,10 +1,15 @@ -package com.iluwatar.abstractfactory; - -public class ElfKing implements King { - - @Override - public String toString() { - return "This is the Elven king!"; - } - -} +package com.iluwatar.abstractfactory; + +/** + * + * ElfKing + * + */ +public class ElfKing implements King { + + @Override + public String toString() { + return "This is the Elven king!"; + } + +} diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfKingdomFactory.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfKingdomFactory.java index eb4b99685..0d62fa5f2 100644 --- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfKingdomFactory.java +++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfKingdomFactory.java @@ -1,22 +1,22 @@ -package com.iluwatar.abstractfactory; - -/** - * - * Concrete factory. - * - */ -public class ElfKingdomFactory implements KingdomFactory { - - public Castle createCastle() { - return new ElfCastle(); - } - - public King createKing() { - return new ElfKing(); - } - - public Army createArmy() { - return new ElfArmy(); - } - -} +package com.iluwatar.abstractfactory; + +/** + * + * ElfKingdomFactory concrete factory. + * + */ +public class ElfKingdomFactory implements KingdomFactory { + + public Castle createCastle() { + return new ElfCastle(); + } + + public King createKing() { + return new ElfKing(); + } + + public Army createArmy() { + return new ElfArmy(); + } + +} diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/King.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/King.java index 12a9c1f13..0b75dbb0a 100644 --- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/King.java +++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/King.java @@ -1,5 +1,10 @@ -package com.iluwatar.abstractfactory; - -public interface King { - -} +package com.iluwatar.abstractfactory; + +/** + * + * King interface + * + */ +public interface King { + +} diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/KingdomFactory.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/KingdomFactory.java index e5b4b4050..00bcd1755 100644 --- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/KingdomFactory.java +++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/KingdomFactory.java @@ -1,16 +1,16 @@ -package com.iluwatar.abstractfactory; - -/** - * - * The factory interface. - * - */ -public interface KingdomFactory { - - Castle createCastle(); - - King createKing(); - - Army createArmy(); - -} +package com.iluwatar.abstractfactory; + +/** + * + * KingdomFactory factory interface. + * + */ +public interface KingdomFactory { + + Castle createCastle(); + + King createKing(); + + Army createArmy(); + +} diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcArmy.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcArmy.java index b0e202d51..d331252dc 100644 --- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcArmy.java +++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcArmy.java @@ -1,10 +1,15 @@ -package com.iluwatar.abstractfactory; - -public class OrcArmy implements Army { - - @Override - public String toString() { - return "This is the Orcish Army!"; - } - -} +package com.iluwatar.abstractfactory; + +/** + * + * OrcArmy + * + */ +public class OrcArmy implements Army { + + @Override + public String toString() { + return "This is the Orcish Army!"; + } + +} diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcCastle.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcCastle.java index 785884a59..fd09d9c17 100644 --- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcCastle.java +++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcCastle.java @@ -1,10 +1,15 @@ -package com.iluwatar.abstractfactory; - -public class OrcCastle implements Castle { - - @Override - public String toString() { - return "This is the Orcish castle!"; - } - -} +package com.iluwatar.abstractfactory; + +/** + * + * OrcCastle + * + */ +public class OrcCastle implements Castle { + + @Override + public String toString() { + return "This is the Orcish castle!"; + } + +} diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcKing.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcKing.java index 27ea8afd4..5bae8f31b 100644 --- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcKing.java +++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcKing.java @@ -1,10 +1,15 @@ -package com.iluwatar.abstractfactory; - -public class OrcKing implements King { - - @Override - public String toString() { - return "This is the Orc king!"; - } - -} +package com.iluwatar.abstractfactory; + +/** + * + * OrcKing + * + */ +public class OrcKing implements King { + + @Override + public String toString() { + return "This is the Orc king!"; + } + +} diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcKingdomFactory.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcKingdomFactory.java index 2f2a2a54d..4fdea6656 100644 --- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcKingdomFactory.java +++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcKingdomFactory.java @@ -1,22 +1,22 @@ -package com.iluwatar.abstractfactory; - -/** - * - * Concrete factory. - * - */ -public class OrcKingdomFactory implements KingdomFactory { - - public Castle createCastle() { - return new OrcCastle(); - } - - public King createKing() { - return new OrcKing(); - } - - public Army createArmy() { - return new OrcArmy(); - } - -} +package com.iluwatar.abstractfactory; + +/** + * + * OrcKingdomFactory concrete factory. + * + */ +public class OrcKingdomFactory implements KingdomFactory { + + public Castle createCastle() { + return new OrcCastle(); + } + + public King createKing() { + return new OrcKing(); + } + + public Army createArmy() { + return new OrcArmy(); + } + +} diff --git a/abstract-factory/src/test/java/com/iluwatar/abstractfactory/AppTest.java b/abstract-factory/src/test/java/com/iluwatar/abstractfactory/AppTest.java index 0241ed8ce..91db0a4be 100644 --- a/abstract-factory/src/test/java/com/iluwatar/abstractfactory/AppTest.java +++ b/abstract-factory/src/test/java/com/iluwatar/abstractfactory/AppTest.java @@ -1,13 +1,18 @@ -package com.iluwatar.abstractfactory; -import org.junit.Test; - -import com.iluwatar.abstractfactory.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.abstractfactory; +import org.junit.Test; + +import com.iluwatar.abstractfactory.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/adapter/src/main/java/com/iluwatar/adapter/App.java b/adapter/src/main/java/com/iluwatar/adapter/App.java index 43a93fa44..3d10a4d41 100644 --- a/adapter/src/main/java/com/iluwatar/adapter/App.java +++ b/adapter/src/main/java/com/iluwatar/adapter/App.java @@ -1,21 +1,25 @@ -package com.iluwatar.adapter; - -/** - * - * There are two variations of the Adapter pattern: The class adapter implements - * the adaptee's interface whereas the object adapter uses composition to - * contain the adaptee in the adapter object. This example uses the object - * adapter approach. - * - * The Adapter (GnomeEngineer) converts the interface of the target class - * (GoblinGlider) into a suitable one expected by the client - * (GnomeEngineeringManager). - * - */ -public class App { - - public static void main(String[] args) { - Engineer manager = new GnomeEngineeringManager(); - manager.operateDevice(); - } -} +package com.iluwatar.adapter; + +/** + * + * There are two variations of the Adapter pattern: The class adapter implements + * the adaptee's interface whereas the object adapter uses composition to + * contain the adaptee in the adapter object. This example uses the object + * adapter approach. + * <p> + * The Adapter ({@link GnomeEngineer}) converts the interface of the target class + * ({@link GoblinGlider}) into a suitable one expected by the client + * ({@link GnomeEngineeringManager}). + * + */ +public class App { + + /** + * Program entry point + * @param args command line args + */ + public static void main(String[] args) { + Engineer manager = new GnomeEngineeringManager(); + manager.operateDevice(); + } +} diff --git a/adapter/src/main/java/com/iluwatar/adapter/GnomeEngineer.java b/adapter/src/main/java/com/iluwatar/adapter/GnomeEngineer.java index 62fab599f..35cbc9573 100644 --- a/adapter/src/main/java/com/iluwatar/adapter/GnomeEngineer.java +++ b/adapter/src/main/java/com/iluwatar/adapter/GnomeEngineer.java @@ -1,24 +1,24 @@ -package com.iluwatar.adapter; - -/** - * - * Adapter class. Adapts the interface of the device (GoblinGlider) into - * Engineer interface expected by the client (GnomeEngineeringManager). - * - */ -public class GnomeEngineer implements Engineer { - - private GoblinGlider glider; - - public GnomeEngineer() { - glider = new GoblinGlider(); - } - - @Override - public void operateDevice() { - glider.attachGlider(); - glider.gainSpeed(); - glider.takeOff(); - } - -} +package com.iluwatar.adapter; + +/** + * + * Adapter class. Adapts the interface of the device ({@link GoblinGlider}) into + * {@link Engineer} interface expected by the client ({@link GnomeEngineeringManager}). + * + */ +public class GnomeEngineer implements Engineer { + + private GoblinGlider glider; + + public GnomeEngineer() { + glider = new GoblinGlider(); + } + + @Override + public void operateDevice() { + glider.attachGlider(); + glider.gainSpeed(); + glider.takeOff(); + } + +} diff --git a/adapter/src/main/java/com/iluwatar/adapter/GnomeEngineeringManager.java b/adapter/src/main/java/com/iluwatar/adapter/GnomeEngineeringManager.java index 6d0010d74..d95065b88 100644 --- a/adapter/src/main/java/com/iluwatar/adapter/GnomeEngineeringManager.java +++ b/adapter/src/main/java/com/iluwatar/adapter/GnomeEngineeringManager.java @@ -1,20 +1,20 @@ -package com.iluwatar.adapter; - -/** - * - * GnomeEngineering manager uses Engineer to operate devices. - * - */ -public class GnomeEngineeringManager implements Engineer { - - private Engineer engineer; - - public GnomeEngineeringManager() { - engineer = new GnomeEngineer(); - } - - @Override - public void operateDevice() { - engineer.operateDevice(); - } -} +package com.iluwatar.adapter; + +/** + * + * GnomeEngineering manager uses {@link Engineer} to operate devices. + * + */ +public class GnomeEngineeringManager implements Engineer { + + private Engineer engineer; + + public GnomeEngineeringManager() { + engineer = new GnomeEngineer(); + } + + @Override + public void operateDevice() { + engineer.operateDevice(); + } +} diff --git a/adapter/src/test/java/com/iluwatar/adapter/AppTest.java b/adapter/src/test/java/com/iluwatar/adapter/AppTest.java index cd9d713b0..3d877815a 100644 --- a/adapter/src/test/java/com/iluwatar/adapter/AppTest.java +++ b/adapter/src/test/java/com/iluwatar/adapter/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.adapter; - -import org.junit.Test; - -import com.iluwatar.adapter.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.adapter; + +import org.junit.Test; + +import com.iluwatar.adapter.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/App.java b/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/App.java index de4dfe926..688d8482f 100644 --- a/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/App.java +++ b/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/App.java @@ -3,29 +3,24 @@ package com.iluwatar.async.method.invocation; import java.util.concurrent.Callable; /** - * <p> * This application demonstrates the async method invocation pattern. Key parts of the pattern are * <code>AsyncResult</code> which is an intermediate container for an asynchronously evaluated value, * <code>AsyncCallback</code> which can be provided to be executed on task completion and * <code>AsyncExecutor</code> that manages the execution of the async tasks. - * </p> * <p> * The main method shows example flow of async invocations. The main thread starts multiple tasks with * variable durations and then continues its own work. When the main thread has done it's job it collects * the results of the async tasks. Two of the tasks are handled with callbacks, meaning the callbacks are * executed immediately when the tasks complete. - * </p> * <p> * Noteworthy difference of thread usage between the async results and callbacks is that the async results * are collected in the main thread but the callbacks are executed within the worker threads. This should be * noted when working with thread pools. - * </p> * <p> * Java provides its own implementations of async method invocation pattern. FutureTask, CompletableFuture * and ExecutorService are the real world implementations of this pattern. But due to the nature of parallel * programming, the implementations are not trivial. This example does not take all possible scenarios into * account but rather provides a simple version that helps to understand the pattern. - * </p> * * @see AsyncResult * @see AsyncCallback diff --git a/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncCallback.java b/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncCallback.java index 067b79d43..46556a48e 100644 --- a/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncCallback.java +++ b/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncCallback.java @@ -2,6 +2,13 @@ package com.iluwatar.async.method.invocation; import java.util.Optional; +/** + * + * AsyncCallback interface + * + * @param <T> + * + */ public interface AsyncCallback<T> { /** diff --git a/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncExecutor.java b/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncExecutor.java index 4bf837a4f..5c5098487 100644 --- a/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncExecutor.java +++ b/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncExecutor.java @@ -3,6 +3,11 @@ package com.iluwatar.async.method.invocation; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; +/** + * + * AsyncExecutor interface + * + */ public interface AsyncExecutor { /** diff --git a/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncResult.java b/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncResult.java index 689095e9d..405bec251 100644 --- a/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncResult.java +++ b/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncResult.java @@ -2,6 +2,12 @@ package com.iluwatar.async.method.invocation; import java.util.concurrent.ExecutionException; +/** + * + * AsyncResult interface + * + * @param <T> + */ public interface AsyncResult<T> { /** diff --git a/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutor.java b/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutor.java index 18b27c3b6..a3ed51af3 100644 --- a/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutor.java +++ b/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutor.java @@ -6,7 +6,9 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicInteger; /** + * * Implementation of async executor that creates a new thread for every task. + * */ public class ThreadAsyncExecutor implements AsyncExecutor { diff --git a/async-method-invocation/src/test/java/com/iluwatar/async/method/invocation/AppTest.java b/async-method-invocation/src/test/java/com/iluwatar/async/method/invocation/AppTest.java index 989fa6d1d..5faec5356 100644 --- a/async-method-invocation/src/test/java/com/iluwatar/async/method/invocation/AppTest.java +++ b/async-method-invocation/src/test/java/com/iluwatar/async/method/invocation/AppTest.java @@ -2,6 +2,11 @@ package com.iluwatar.async.method.invocation; import org.junit.Test; +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/bridge/etc/bridge.png b/bridge/etc/bridge.png index 472fe51e7..00d3e611c 100644 Binary files a/bridge/etc/bridge.png and b/bridge/etc/bridge.png differ diff --git a/bridge/etc/bridge.ucls b/bridge/etc/bridge.ucls index 86455e7fb..2eda6e1d1 100644 --- a/bridge/etc/bridge.ucls +++ b/bridge/etc/bridge.ucls @@ -1,18 +1,18 @@ <?xml version="1.0" encoding="UTF-8"?> <class-diagram version="1.1.8" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true" realizations="true" associations="true" dependencies="false" nesting-relationships="true"> - <class id="1" language="java" name="com.iluwatar.bridge.FlyingMagicWeaponImp" project="bridge" - file="/bridge/src/main/java/com/iluwatar/bridge/FlyingMagicWeaponImp.java" binary="false" corner="BOTTOM_RIGHT"> - <position height="105" width="192" x="193" y="297"/> + <class id="1" language="java" name="com.iluwatar.bridge.FlyingMagicWeaponImpl" project="bridge" + file="/bridge/src/main/java/com/iluwatar/bridge/FlyingMagicWeaponImpl.java" binary="false" corner="BOTTOM_RIGHT"> + <position height="-1" width="-1" x="515" y="591"/> <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" sort-features="false" accessors="true" visibility="true"> <attributes public="true" package="true" protected="true" private="true" static="true"/> <operations public="true" package="true" protected="true" private="true" static="true"/> </display> </class> - <class id="2" language="java" name="com.iluwatar.bridge.SoulEatingMagicWeaponImp" project="bridge" - file="/bridge/src/main/java/com/iluwatar/bridge/SoulEatingMagicWeaponImp.java" binary="false" corner="BOTTOM_RIGHT"> - <position height="105" width="226" x="425" y="297"/> + <class id="2" language="java" name="com.iluwatar.bridge.SoulEatingMagicWeaponImpl" project="bridge" + file="/bridge/src/main/java/com/iluwatar/bridge/SoulEatingMagicWeaponImpl.java" binary="false" corner="BOTTOM_RIGHT"> + <position height="-1" width="-1" x="791" y="605"/> <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" sort-features="false" accessors="true" visibility="true"> <attributes public="true" package="true" protected="true" private="true" static="true"/> @@ -21,25 +21,25 @@ </class> <class id="3" language="java" name="com.iluwatar.bridge.Stormbringer" project="bridge" file="/bridge/src/main/java/com/iluwatar/bridge/Stormbringer.java" binary="false" corner="BOTTOM_RIGHT"> - <position height="160" width="125" x="425" y="442"/> + <position height="-1" width="-1" x="791" y="788"/> <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" sort-features="false" accessors="true" visibility="true"> <attributes public="true" package="true" protected="true" private="true" static="true"/> <operations public="true" package="true" protected="true" private="true" static="true"/> </display> </class> - <class id="4" language="java" name="com.iluwatar.bridge.MagicWeaponImp" project="bridge" - file="/bridge/src/main/java/com/iluwatar/bridge/MagicWeaponImp.java" binary="false" corner="BOTTOM_RIGHT"> - <position height="141" width="149" x="221" y="79"/> + <class id="4" language="java" name="com.iluwatar.bridge.MagicWeaponImpl" project="bridge" + file="/bridge/src/main/java/com/iluwatar/bridge/MagicWeaponImpl.java" binary="false" corner="BOTTOM_RIGHT"> + <position height="-1" width="-1" x="791" y="433"/> <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" sort-features="false" accessors="true" visibility="true"> <attributes public="true" package="true" protected="true" private="true" static="true"/> <operations public="true" package="true" protected="true" private="true" static="true"/> </display> </class> - <class id="5" language="java" name="com.iluwatar.bridge.BlindingMagicWeaponImp" project="bridge" - file="/bridge/src/main/java/com/iluwatar/bridge/BlindingMagicWeaponImp.java" binary="false" corner="BOTTOM_RIGHT"> - <position height="105" width="208" x="691" y="297"/> + <class id="5" language="java" name="com.iluwatar.bridge.BlindingMagicWeaponImpl" project="bridge" + file="/bridge/src/main/java/com/iluwatar/bridge/BlindingMagicWeaponImpl.java" binary="false" corner="BOTTOM_RIGHT"> + <position height="-1" width="-1" x="1105" y="593"/> <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" sort-features="false" accessors="true" visibility="true"> <attributes public="true" package="true" protected="true" private="true" static="true"/> @@ -48,7 +48,7 @@ </class> <class id="6" language="java" name="com.iluwatar.bridge.SoulEatingMagicWeapon" project="bridge" file="/bridge/src/main/java/com/iluwatar/bridge/SoulEatingMagicWeapon.java" binary="false" corner="BOTTOM_RIGHT"> - <position height="178" width="347" x="410" y="79"/> + <position height="-1" width="-1" x="380" y="21"/> <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" sort-features="false" accessors="true" visibility="true"> <attributes public="true" package="true" protected="true" private="true" static="true"/> @@ -57,7 +57,7 @@ </class> <class id="7" language="java" name="com.iluwatar.bridge.Excalibur" project="bridge" file="/bridge/src/main/java/com/iluwatar/bridge/Excalibur.java" binary="false" corner="BOTTOM_RIGHT"> - <position height="160" width="124" x="691" y="442"/> + <position height="-1" width="-1" x="1105" y="782"/> <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" sort-features="false" accessors="true" visibility="true"> <attributes public="true" package="true" protected="true" private="true" static="true"/> @@ -66,7 +66,7 @@ </class> <class id="8" language="java" name="com.iluwatar.bridge.Mjollnir" project="bridge" file="/bridge/src/main/java/com/iluwatar/bridge/Mjollnir.java" binary="false" corner="BOTTOM_RIGHT"> - <position height="160" width="124" x="193" y="442"/> + <position height="-1" width="-1" x="515" y="788"/> <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" sort-features="false" accessors="true" visibility="true"> <attributes public="true" package="true" protected="true" private="true" static="true"/> @@ -75,7 +75,7 @@ </class> <class id="9" language="java" name="com.iluwatar.bridge.BlindingMagicWeapon" project="bridge" file="/bridge/src/main/java/com/iluwatar/bridge/BlindingMagicWeapon.java" binary="false" corner="BOTTOM_RIGHT"> - <position height="178" width="313" x="797" y="79"/> + <position height="-1" width="-1" x="791" y="14"/> <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" sort-features="false" accessors="true" visibility="true"> <attributes public="true" package="true" protected="true" private="true" static="true"/> @@ -84,7 +84,7 @@ </class> <class id="10" language="java" name="com.iluwatar.bridge.MagicWeapon" project="bridge" file="/bridge/src/main/java/com/iluwatar/bridge/MagicWeapon.java" binary="false" corner="BOTTOM_RIGHT"> - <position height="159" width="221" x="644" y="-120"/> + <position height="-1" width="-1" x="791" y="237"/> <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" sort-features="false" accessors="true" visibility="true"> <attributes public="true" package="true" protected="true" private="true" static="true"/> @@ -93,7 +93,7 @@ </class> <class id="11" language="java" name="com.iluwatar.bridge.FlyingMagicWeapon" project="bridge" file="/bridge/src/main/java/com/iluwatar/bridge/FlyingMagicWeapon.java" binary="false" corner="BOTTOM_RIGHT"> - <position height="178" width="291" x="1150" y="79"/> + <position height="-1" width="-1" x="1144" y="12"/> <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" sort-features="false" accessors="true" visibility="true"> <attributes public="true" package="true" protected="true" private="true" static="true"/> @@ -101,48 +101,52 @@ </display> </class> <generalization id="12"> - <end type="SOURCE" refId="11"/> - <end type="TARGET" refId="10"/> + <end type="SOURCE" refId="8"/> + <end type="TARGET" refId="1"/> </generalization> <generalization id="13"> <end type="SOURCE" refId="1"/> <end type="TARGET" refId="4"/> </generalization> <generalization id="14"> - <end type="SOURCE" refId="2"/> - <end type="TARGET" refId="4"/> - </generalization> - <generalization id="15"> - <end type="SOURCE" refId="7"/> - <end type="TARGET" refId="5"/> - </generalization> - <generalization id="16"> - <end type="SOURCE" refId="6"/> - <end type="TARGET" refId="10"/> - </generalization> - <generalization id="17"> <end type="SOURCE" refId="9"/> <end type="TARGET" refId="10"/> </generalization> - <generalization id="18"> - <end type="SOURCE" refId="3"/> - <end type="TARGET" refId="2"/> + <generalization id="15"> + <end type="SOURCE" refId="2"/> + <end type="TARGET" refId="4"/> </generalization> - <association id="19"> + <association id="16"> <end type="SOURCE" refId="10" navigable="false"> - <attribute id="20" name="imp"/> - <multiplicity id="21" minimum="0" maximum="1"/> + <attribute id="17" name="imp"> + <position height="0" width="0" x="478" y="284"/> + </attribute> + <multiplicity id="18" minimum="0" maximum="1"> + <position height="0" width="0" x="478" y="284"/> + </multiplicity> </end> <end type="TARGET" refId="4" navigable="true"/> <display labels="true" multiplicity="true"/> </association> - <generalization id="22"> + <generalization id="19"> <end type="SOURCE" refId="5"/> <end type="TARGET" refId="4"/> </generalization> + <generalization id="20"> + <end type="SOURCE" refId="6"/> + <end type="TARGET" refId="10"/> + </generalization> + <generalization id="21"> + <end type="SOURCE" refId="7"/> + <end type="TARGET" refId="5"/> + </generalization> + <generalization id="22"> + <end type="SOURCE" refId="3"/> + <end type="TARGET" refId="2"/> + </generalization> <generalization id="23"> - <end type="SOURCE" refId="8"/> - <end type="TARGET" refId="1"/> + <end type="SOURCE" refId="11"/> + <end type="TARGET" refId="10"/> </generalization> <classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" sort-features="false" accessors="true" visibility="true"> diff --git a/bridge/etc/bridge_1.png b/bridge/etc/bridge_1.png deleted file mode 100644 index 3152efdf6..000000000 Binary files a/bridge/etc/bridge_1.png and /dev/null differ diff --git a/bridge/index.md b/bridge/index.md index 8c05f14cf..6ef1c6519 100644 --- a/bridge/index.md +++ b/bridge/index.md @@ -11,7 +11,7 @@ tags: Java vary independently. - + **Applicability:** Use the Bridge pattern when diff --git a/bridge/src/main/java/com/iluwatar/bridge/App.java b/bridge/src/main/java/com/iluwatar/bridge/App.java index 3797653d4..e8774caea 100644 --- a/bridge/src/main/java/com/iluwatar/bridge/App.java +++ b/bridge/src/main/java/com/iluwatar/bridge/App.java @@ -1,35 +1,39 @@ -package com.iluwatar.bridge; - -/** - * - * In Bridge pattern both abstraction (MagicWeapon) and implementation - * (MagicWeaponImp) have their own class hierarchies. The interface of the - * implementations can be changed without affecting the clients. - * - */ -public class App { - - public static void main(String[] args) { - BlindingMagicWeapon blindingMagicWeapon = new BlindingMagicWeapon( - new Excalibur()); - blindingMagicWeapon.wield(); - blindingMagicWeapon.blind(); - blindingMagicWeapon.swing(); - blindingMagicWeapon.unwield(); - - FlyingMagicWeapon flyingMagicWeapon = new FlyingMagicWeapon( - new Mjollnir()); - flyingMagicWeapon.wield(); - flyingMagicWeapon.fly(); - flyingMagicWeapon.swing(); - flyingMagicWeapon.unwield(); - - SoulEatingMagicWeapon soulEatingMagicWeapon = new SoulEatingMagicWeapon( - new Stormbringer()); - soulEatingMagicWeapon.wield(); - soulEatingMagicWeapon.swing(); - soulEatingMagicWeapon.eatSoul(); - soulEatingMagicWeapon.unwield(); - - } -} +package com.iluwatar.bridge; + +/** + * + * In Bridge pattern both abstraction ({@link MagicWeapon}) and implementation + * ({@link MagicWeaponImpl}) have their own class hierarchies. The interface of the + * implementations can be changed without affecting the clients. + * + */ +public class App { + + /** + * Program entry point + * @param args command line args + */ + public static void main(String[] args) { + BlindingMagicWeapon blindingMagicWeapon = new BlindingMagicWeapon( + new Excalibur()); + blindingMagicWeapon.wield(); + blindingMagicWeapon.blind(); + blindingMagicWeapon.swing(); + blindingMagicWeapon.unwield(); + + FlyingMagicWeapon flyingMagicWeapon = new FlyingMagicWeapon( + new Mjollnir()); + flyingMagicWeapon.wield(); + flyingMagicWeapon.fly(); + flyingMagicWeapon.swing(); + flyingMagicWeapon.unwield(); + + SoulEatingMagicWeapon soulEatingMagicWeapon = new SoulEatingMagicWeapon( + new Stormbringer()); + soulEatingMagicWeapon.wield(); + soulEatingMagicWeapon.swing(); + soulEatingMagicWeapon.eatSoul(); + soulEatingMagicWeapon.unwield(); + + } +} diff --git a/bridge/src/main/java/com/iluwatar/bridge/BlindingMagicWeapon.java b/bridge/src/main/java/com/iluwatar/bridge/BlindingMagicWeapon.java index 5421c6d5e..bf4bac8f9 100644 --- a/bridge/src/main/java/com/iluwatar/bridge/BlindingMagicWeapon.java +++ b/bridge/src/main/java/com/iluwatar/bridge/BlindingMagicWeapon.java @@ -1,33 +1,38 @@ -package com.iluwatar.bridge; - -public class BlindingMagicWeapon extends MagicWeapon { - - public BlindingMagicWeapon(BlindingMagicWeaponImp imp) { - super(imp); - } - - @Override - public BlindingMagicWeaponImp getImp() { - return (BlindingMagicWeaponImp) imp; - } - - @Override - public void wield() { - getImp().wieldImp(); - } - - @Override - public void swing() { - getImp().swingImp(); - } - - @Override - public void unwield() { - getImp().unwieldImp(); - } - - public void blind() { - getImp().blindImp(); - } - -} +package com.iluwatar.bridge; + +/** + * + * BlindingMagicWeapon + * + */ +public class BlindingMagicWeapon extends MagicWeapon { + + public BlindingMagicWeapon(BlindingMagicWeaponImpl imp) { + super(imp); + } + + @Override + public BlindingMagicWeaponImpl getImp() { + return (BlindingMagicWeaponImpl) imp; + } + + @Override + public void wield() { + getImp().wieldImp(); + } + + @Override + public void swing() { + getImp().swingImp(); + } + + @Override + public void unwield() { + getImp().unwieldImp(); + } + + public void blind() { + getImp().blindImp(); + } + +} diff --git a/bridge/src/main/java/com/iluwatar/bridge/BlindingMagicWeaponImp.java b/bridge/src/main/java/com/iluwatar/bridge/BlindingMagicWeaponImp.java deleted file mode 100644 index 0686ce917..000000000 --- a/bridge/src/main/java/com/iluwatar/bridge/BlindingMagicWeaponImp.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.iluwatar.bridge; - -public abstract class BlindingMagicWeaponImp extends MagicWeaponImp { - - public abstract void blindImp(); - -} diff --git a/bridge/src/main/java/com/iluwatar/bridge/BlindingMagicWeaponImpl.java b/bridge/src/main/java/com/iluwatar/bridge/BlindingMagicWeaponImpl.java new file mode 100644 index 000000000..31dffb042 --- /dev/null +++ b/bridge/src/main/java/com/iluwatar/bridge/BlindingMagicWeaponImpl.java @@ -0,0 +1,12 @@ +package com.iluwatar.bridge; + +/** + * + * BlindingMagicWeaponImpl + * + */ +public abstract class BlindingMagicWeaponImpl extends MagicWeaponImpl { + + public abstract void blindImp(); + +} diff --git a/bridge/src/main/java/com/iluwatar/bridge/Excalibur.java b/bridge/src/main/java/com/iluwatar/bridge/Excalibur.java index 52298c900..9f7078139 100644 --- a/bridge/src/main/java/com/iluwatar/bridge/Excalibur.java +++ b/bridge/src/main/java/com/iluwatar/bridge/Excalibur.java @@ -1,26 +1,31 @@ -package com.iluwatar.bridge; - -public class Excalibur extends BlindingMagicWeaponImp { - - @Override - public void wieldImp() { - System.out.println("wielding Excalibur"); - } - - @Override - public void swingImp() { - System.out.println("swinging Excalibur"); - } - - @Override - public void unwieldImp() { - System.out.println("unwielding Excalibur"); - } - - @Override - public void blindImp() { - System.out - .println("bright light streams from Excalibur blinding the enemy"); - } - -} +package com.iluwatar.bridge; + +/** + * + * Excalibur + * + */ +public class Excalibur extends BlindingMagicWeaponImpl { + + @Override + public void wieldImp() { + System.out.println("wielding Excalibur"); + } + + @Override + public void swingImp() { + System.out.println("swinging Excalibur"); + } + + @Override + public void unwieldImp() { + System.out.println("unwielding Excalibur"); + } + + @Override + public void blindImp() { + System.out + .println("bright light streams from Excalibur blinding the enemy"); + } + +} diff --git a/bridge/src/main/java/com/iluwatar/bridge/FlyingMagicWeapon.java b/bridge/src/main/java/com/iluwatar/bridge/FlyingMagicWeapon.java index 9cb1902f9..542e7d97e 100644 --- a/bridge/src/main/java/com/iluwatar/bridge/FlyingMagicWeapon.java +++ b/bridge/src/main/java/com/iluwatar/bridge/FlyingMagicWeapon.java @@ -1,32 +1,37 @@ -package com.iluwatar.bridge; - -public class FlyingMagicWeapon extends MagicWeapon { - - public FlyingMagicWeapon(FlyingMagicWeaponImp imp) { - super(imp); - } - - public FlyingMagicWeaponImp getImp() { - return (FlyingMagicWeaponImp) imp; - } - - @Override - public void wield() { - getImp().wieldImp(); - } - - @Override - public void swing() { - getImp().swingImp(); - } - - @Override - public void unwield() { - getImp().unwieldImp(); - } - - public void fly() { - getImp().flyImp(); - } - -} +package com.iluwatar.bridge; + +/** + * + * FlyingMagicWeapon + * + */ +public class FlyingMagicWeapon extends MagicWeapon { + + public FlyingMagicWeapon(FlyingMagicWeaponImpl imp) { + super(imp); + } + + public FlyingMagicWeaponImpl getImp() { + return (FlyingMagicWeaponImpl) imp; + } + + @Override + public void wield() { + getImp().wieldImp(); + } + + @Override + public void swing() { + getImp().swingImp(); + } + + @Override + public void unwield() { + getImp().unwieldImp(); + } + + public void fly() { + getImp().flyImp(); + } + +} diff --git a/bridge/src/main/java/com/iluwatar/bridge/FlyingMagicWeaponImp.java b/bridge/src/main/java/com/iluwatar/bridge/FlyingMagicWeaponImp.java deleted file mode 100644 index 37fa8a0f9..000000000 --- a/bridge/src/main/java/com/iluwatar/bridge/FlyingMagicWeaponImp.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.iluwatar.bridge; - -public abstract class FlyingMagicWeaponImp extends MagicWeaponImp { - - public abstract void flyImp(); - -} diff --git a/bridge/src/main/java/com/iluwatar/bridge/FlyingMagicWeaponImpl.java b/bridge/src/main/java/com/iluwatar/bridge/FlyingMagicWeaponImpl.java new file mode 100644 index 000000000..8b7a10f2f --- /dev/null +++ b/bridge/src/main/java/com/iluwatar/bridge/FlyingMagicWeaponImpl.java @@ -0,0 +1,12 @@ +package com.iluwatar.bridge; + +/** + * + * FlyingMagicWeaponImpl + * + */ +public abstract class FlyingMagicWeaponImpl extends MagicWeaponImpl { + + public abstract void flyImp(); + +} diff --git a/bridge/src/main/java/com/iluwatar/bridge/MagicWeapon.java b/bridge/src/main/java/com/iluwatar/bridge/MagicWeapon.java index b03435c51..b2b82839c 100644 --- a/bridge/src/main/java/com/iluwatar/bridge/MagicWeapon.java +++ b/bridge/src/main/java/com/iluwatar/bridge/MagicWeapon.java @@ -1,26 +1,26 @@ -package com.iluwatar.bridge; - -/** - * - * Abstraction interface. - * - */ -public abstract class MagicWeapon { - - protected MagicWeaponImp imp; - - public MagicWeapon(MagicWeaponImp imp) { - this.imp = imp; - } - - public abstract void wield(); - - public abstract void swing(); - - public abstract void unwield(); - - public MagicWeaponImp getImp() { - return imp; - } - -} +package com.iluwatar.bridge; + +/** + * + * MagicWeapon + * + */ +public abstract class MagicWeapon { + + protected MagicWeaponImpl imp; + + public MagicWeapon(MagicWeaponImpl imp) { + this.imp = imp; + } + + public abstract void wield(); + + public abstract void swing(); + + public abstract void unwield(); + + public MagicWeaponImpl getImp() { + return imp; + } + +} diff --git a/bridge/src/main/java/com/iluwatar/bridge/MagicWeaponImp.java b/bridge/src/main/java/com/iluwatar/bridge/MagicWeaponImpl.java similarity index 65% rename from bridge/src/main/java/com/iluwatar/bridge/MagicWeaponImp.java rename to bridge/src/main/java/com/iluwatar/bridge/MagicWeaponImpl.java index cf972c115..bd2a3b8d7 100644 --- a/bridge/src/main/java/com/iluwatar/bridge/MagicWeaponImp.java +++ b/bridge/src/main/java/com/iluwatar/bridge/MagicWeaponImpl.java @@ -1,16 +1,16 @@ -package com.iluwatar.bridge; - -/** - * - * Implementation interface. - * - */ -public abstract class MagicWeaponImp { - - public abstract void wieldImp(); - - public abstract void swingImp(); - - public abstract void unwieldImp(); - -} +package com.iluwatar.bridge; + +/** + * + * MagicWeaponImpl + * + */ +public abstract class MagicWeaponImpl { + + public abstract void wieldImp(); + + public abstract void swingImp(); + + public abstract void unwieldImp(); + +} diff --git a/bridge/src/main/java/com/iluwatar/bridge/Mjollnir.java b/bridge/src/main/java/com/iluwatar/bridge/Mjollnir.java index 0c21f8d07..887173add 100644 --- a/bridge/src/main/java/com/iluwatar/bridge/Mjollnir.java +++ b/bridge/src/main/java/com/iluwatar/bridge/Mjollnir.java @@ -1,26 +1,31 @@ -package com.iluwatar.bridge; - -public class Mjollnir extends FlyingMagicWeaponImp { - - @Override - public void wieldImp() { - System.out.println("wielding Mjollnir"); - } - - @Override - public void swingImp() { - System.out.println("swinging Mjollnir"); - } - - @Override - public void unwieldImp() { - System.out.println("unwielding Mjollnir"); - } - - @Override - public void flyImp() { - System.out - .println("Mjollnir hits the enemy in the air and returns back to the owner's hand"); - } - -} +package com.iluwatar.bridge; + +/** + * + * Mjollnir + * + */ +public class Mjollnir extends FlyingMagicWeaponImpl { + + @Override + public void wieldImp() { + System.out.println("wielding Mjollnir"); + } + + @Override + public void swingImp() { + System.out.println("swinging Mjollnir"); + } + + @Override + public void unwieldImp() { + System.out.println("unwielding Mjollnir"); + } + + @Override + public void flyImp() { + System.out + .println("Mjollnir hits the enemy in the air and returns back to the owner's hand"); + } + +} diff --git a/bridge/src/main/java/com/iluwatar/bridge/SoulEatingMagicWeapon.java b/bridge/src/main/java/com/iluwatar/bridge/SoulEatingMagicWeapon.java index dbbec102d..3310b6488 100644 --- a/bridge/src/main/java/com/iluwatar/bridge/SoulEatingMagicWeapon.java +++ b/bridge/src/main/java/com/iluwatar/bridge/SoulEatingMagicWeapon.java @@ -1,33 +1,38 @@ -package com.iluwatar.bridge; - -public class SoulEatingMagicWeapon extends MagicWeapon { - - public SoulEatingMagicWeapon(SoulEatingMagicWeaponImp imp) { - super(imp); - } - - @Override - public SoulEatingMagicWeaponImp getImp() { - return (SoulEatingMagicWeaponImp) imp; - } - - @Override - public void wield() { - getImp().wieldImp(); - } - - @Override - public void swing() { - getImp().swingImp(); - } - - @Override - public void unwield() { - getImp().unwieldImp(); - } - - public void eatSoul() { - getImp().eatSoulImp(); - } - -} +package com.iluwatar.bridge; + +/** + * + * SoulEatingMagicWeapon + * + */ +public class SoulEatingMagicWeapon extends MagicWeapon { + + public SoulEatingMagicWeapon(SoulEatingMagicWeaponImpl imp) { + super(imp); + } + + @Override + public SoulEatingMagicWeaponImpl getImp() { + return (SoulEatingMagicWeaponImpl) imp; + } + + @Override + public void wield() { + getImp().wieldImp(); + } + + @Override + public void swing() { + getImp().swingImp(); + } + + @Override + public void unwield() { + getImp().unwieldImp(); + } + + public void eatSoul() { + getImp().eatSoulImp(); + } + +} diff --git a/bridge/src/main/java/com/iluwatar/bridge/SoulEatingMagicWeaponImp.java b/bridge/src/main/java/com/iluwatar/bridge/SoulEatingMagicWeaponImp.java deleted file mode 100644 index 3c1a557dd..000000000 --- a/bridge/src/main/java/com/iluwatar/bridge/SoulEatingMagicWeaponImp.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.iluwatar.bridge; - -public abstract class SoulEatingMagicWeaponImp extends MagicWeaponImp { - - public abstract void eatSoulImp(); - -} diff --git a/bridge/src/main/java/com/iluwatar/bridge/SoulEatingMagicWeaponImpl.java b/bridge/src/main/java/com/iluwatar/bridge/SoulEatingMagicWeaponImpl.java new file mode 100644 index 000000000..9ec112031 --- /dev/null +++ b/bridge/src/main/java/com/iluwatar/bridge/SoulEatingMagicWeaponImpl.java @@ -0,0 +1,12 @@ +package com.iluwatar.bridge; + +/** + * + * SoulEatingMagicWeaponImpl + * + */ +public abstract class SoulEatingMagicWeaponImpl extends MagicWeaponImpl { + + public abstract void eatSoulImp(); + +} diff --git a/bridge/src/main/java/com/iluwatar/bridge/Stormbringer.java b/bridge/src/main/java/com/iluwatar/bridge/Stormbringer.java index 55b5960c9..589156fe3 100644 --- a/bridge/src/main/java/com/iluwatar/bridge/Stormbringer.java +++ b/bridge/src/main/java/com/iluwatar/bridge/Stormbringer.java @@ -1,25 +1,30 @@ -package com.iluwatar.bridge; - -public class Stormbringer extends SoulEatingMagicWeaponImp { - - @Override - public void wieldImp() { - System.out.println("wielding Stormbringer"); - } - - @Override - public void swingImp() { - System.out.println("swinging Stormbringer"); - } - - @Override - public void unwieldImp() { - System.out.println("unwielding Stormbringer"); - } - - @Override - public void eatSoulImp() { - System.out.println("Stormbringer devours the enemy's soul"); - } - -} +package com.iluwatar.bridge; + +/** + * + * Stormbringer + * + */ +public class Stormbringer extends SoulEatingMagicWeaponImpl { + + @Override + public void wieldImp() { + System.out.println("wielding Stormbringer"); + } + + @Override + public void swingImp() { + System.out.println("swinging Stormbringer"); + } + + @Override + public void unwieldImp() { + System.out.println("unwielding Stormbringer"); + } + + @Override + public void eatSoulImp() { + System.out.println("Stormbringer devours the enemy's soul"); + } + +} diff --git a/bridge/src/test/java/com/iluwatar/bridge/AppTest.java b/bridge/src/test/java/com/iluwatar/bridge/AppTest.java index 196008950..b53111c8e 100644 --- a/bridge/src/test/java/com/iluwatar/bridge/AppTest.java +++ b/bridge/src/test/java/com/iluwatar/bridge/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.bridge; - -import org.junit.Test; - -import com.iluwatar.bridge.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.bridge; + +import org.junit.Test; + +import com.iluwatar.bridge.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/builder/src/main/java/com/iluwatar/builder/App.java b/builder/src/main/java/com/iluwatar/builder/App.java index e38e5a0c3..bcdbb8821 100644 --- a/builder/src/main/java/com/iluwatar/builder/App.java +++ b/builder/src/main/java/com/iluwatar/builder/App.java @@ -1,38 +1,42 @@ -package com.iluwatar.builder; - -import com.iluwatar. builder.Hero.HeroBuilder; - -/** - * - * This is the Builder pattern variation as described by Joshua Bloch in - * Effective Java 2nd Edition. - * - * We want to build Hero objects, but its construction is complex because of the - * many parameters needed. To aid the user we introduce HeroBuilder class. - * HeroBuilder takes the minimum parameters to build Hero object in its - * constructor. After that additional configuration for the Hero object can be - * done using the fluent HeroBuilder interface. When configuration is ready the - * build method is called to receive the final Hero object. - * - */ -public class App { - - public static void main(String[] args) { - - Hero mage = new HeroBuilder(Profession.MAGE, "Riobard") - .withHairColor(HairColor.BLACK).withWeapon(Weapon.DAGGER) - .build(); - System.out.println(mage); - - Hero warrior = new HeroBuilder(Profession.WARRIOR, "Amberjill") - .withHairColor(HairColor.BLOND) - .withHairType(HairType.LONG_CURLY).withArmor(Armor.CHAIN_MAIL) - .withWeapon(Weapon.SWORD).build(); - System.out.println(warrior); - - Hero thief = new HeroBuilder(Profession.THIEF, "Desmond") - .withHairType(HairType.BALD).withWeapon(Weapon.BOW).build(); - System.out.println(thief); - - } -} +package com.iluwatar.builder; + +import com.iluwatar. builder.Hero.HeroBuilder; + +/** + * + * This is the Builder pattern variation as described by Joshua Bloch in + * Effective Java 2nd Edition. + * <p> + * We want to build {@link Hero} objects, but its construction is complex because of the + * many parameters needed. To aid the user we introduce {@link HeroBuilder} class. + * {@link HeroBuilder} takes the minimum parameters to build {@link Hero} object in its + * constructor. After that additional configuration for the {@link Hero} object can be + * done using the fluent {@link HeroBuilder} interface. When configuration is ready the + * build method is called to receive the final {@link Hero} object. + * + */ +public class App { + + /** + * Program entry point + * @param args command line args + */ + public static void main(String[] args) { + + Hero mage = new HeroBuilder(Profession.MAGE, "Riobard") + .withHairColor(HairColor.BLACK).withWeapon(Weapon.DAGGER) + .build(); + System.out.println(mage); + + Hero warrior = new HeroBuilder(Profession.WARRIOR, "Amberjill") + .withHairColor(HairColor.BLOND) + .withHairType(HairType.LONG_CURLY).withArmor(Armor.CHAIN_MAIL) + .withWeapon(Weapon.SWORD).build(); + System.out.println(warrior); + + Hero thief = new HeroBuilder(Profession.THIEF, "Desmond") + .withHairType(HairType.BALD).withWeapon(Weapon.BOW).build(); + System.out.println(thief); + + } +} diff --git a/builder/src/main/java/com/iluwatar/builder/Armor.java b/builder/src/main/java/com/iluwatar/builder/Armor.java index ebec6a47d..95fcba43b 100644 --- a/builder/src/main/java/com/iluwatar/builder/Armor.java +++ b/builder/src/main/java/com/iluwatar/builder/Armor.java @@ -1,17 +1,22 @@ -package com.iluwatar.builder; - -public enum Armor { - - CLOTHES("clothes"), LEATHER("leather"), CHAIN_MAIL("chain mail"), PLATE_MAIL("plate mail"); - - private String title; - - Armor(String title) { - this.title = title; - } - - @Override - public String toString() { - return title; - } -} +package com.iluwatar.builder; + +/** + * + * Armor enumeration + * + */ +public enum Armor { + + CLOTHES("clothes"), LEATHER("leather"), CHAIN_MAIL("chain mail"), PLATE_MAIL("plate mail"); + + private String title; + + Armor(String title) { + this.title = title; + } + + @Override + public String toString() { + return title; + } +} diff --git a/builder/src/main/java/com/iluwatar/builder/HairColor.java b/builder/src/main/java/com/iluwatar/builder/HairColor.java index a73044754..dd8ec2ecc 100644 --- a/builder/src/main/java/com/iluwatar/builder/HairColor.java +++ b/builder/src/main/java/com/iluwatar/builder/HairColor.java @@ -1,12 +1,17 @@ -package com.iluwatar.builder; - -public enum HairColor { - - WHITE, BLOND, RED, BROWN, BLACK; - - @Override - public String toString() { - return name().toLowerCase(); - } - -} +package com.iluwatar.builder; + +/** + * + * HairColor enumeration + * + */ +public enum HairColor { + + WHITE, BLOND, RED, BROWN, BLACK; + + @Override + public String toString() { + return name().toLowerCase(); + } + +} diff --git a/builder/src/main/java/com/iluwatar/builder/HairType.java b/builder/src/main/java/com/iluwatar/builder/HairType.java index 075699a58..ea49c0470 100644 --- a/builder/src/main/java/com/iluwatar/builder/HairType.java +++ b/builder/src/main/java/com/iluwatar/builder/HairType.java @@ -1,17 +1,22 @@ -package com.iluwatar.builder; - -public enum HairType { - - BALD("bald"), SHORT("short"), CURLY("curly"), LONG_STRAIGHT("long straight"), LONG_CURLY("long curly"); - - private String title; - - HairType(String title) { - this.title = title; - } - - @Override - public String toString() { - return title; - } -} +package com.iluwatar.builder; + +/** + * + * HairType enumeration + * + */ +public enum HairType { + + BALD("bald"), SHORT("short"), CURLY("curly"), LONG_STRAIGHT("long straight"), LONG_CURLY("long curly"); + + private String title; + + HairType(String title) { + this.title = title; + } + + @Override + public String toString() { + return title; + } +} diff --git a/builder/src/main/java/com/iluwatar/builder/Hero.java b/builder/src/main/java/com/iluwatar/builder/Hero.java index 75513eeda..05304bf09 100644 --- a/builder/src/main/java/com/iluwatar/builder/Hero.java +++ b/builder/src/main/java/com/iluwatar/builder/Hero.java @@ -2,7 +2,7 @@ package com.iluwatar.builder; /** * - * The class with many parameters. + * Hero, the class with many parameters. * */ public class Hero { diff --git a/builder/src/main/java/com/iluwatar/builder/Profession.java b/builder/src/main/java/com/iluwatar/builder/Profession.java index 487fc5133..c9a7cc4e9 100644 --- a/builder/src/main/java/com/iluwatar/builder/Profession.java +++ b/builder/src/main/java/com/iluwatar/builder/Profession.java @@ -1,12 +1,17 @@ -package com.iluwatar.builder; - -public enum Profession { - - WARRIOR, THIEF, MAGE, PRIEST; - - @Override - public String toString() { - return name().toLowerCase(); - } - -} +package com.iluwatar.builder; + +/** + * + * Profession enumeration + * + */ +public enum Profession { + + WARRIOR, THIEF, MAGE, PRIEST; + + @Override + public String toString() { + return name().toLowerCase(); + } + +} diff --git a/builder/src/main/java/com/iluwatar/builder/Weapon.java b/builder/src/main/java/com/iluwatar/builder/Weapon.java index 99622ddac..af71c596d 100644 --- a/builder/src/main/java/com/iluwatar/builder/Weapon.java +++ b/builder/src/main/java/com/iluwatar/builder/Weapon.java @@ -1,12 +1,17 @@ -package com.iluwatar.builder; - -public enum Weapon { - - DAGGER, SWORD, AXE, WARHAMMER, BOW; - - @Override - public String toString() { - return name().toLowerCase(); - } - -} +package com.iluwatar.builder; + +/** + * + * Weapon enumeration + * + */ +public enum Weapon { + + DAGGER, SWORD, AXE, WARHAMMER, BOW; + + @Override + public String toString() { + return name().toLowerCase(); + } + +} diff --git a/builder/src/test/java/com/iluwatar/builder/AppTest.java b/builder/src/test/java/com/iluwatar/builder/AppTest.java index 462ad3a9a..acae1ca70 100644 --- a/builder/src/test/java/com/iluwatar/builder/AppTest.java +++ b/builder/src/test/java/com/iluwatar/builder/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.builder; - -import org.junit.Test; - -import com.iluwatar. builder.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.builder; + +import org.junit.Test; + +import com.iluwatar. builder.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/business-delegate/src/main/java/com/iluwatar/business/delegate/App.java b/business-delegate/src/main/java/com/iluwatar/business/delegate/App.java index 214d8232f..eea7608eb 100644 --- a/business-delegate/src/main/java/com/iluwatar/business/delegate/App.java +++ b/business-delegate/src/main/java/com/iluwatar/business/delegate/App.java @@ -2,21 +2,25 @@ package com.iluwatar.business.delegate; /** * - * The Business Delegate pattern adds an abstraction layer between presentation and business tiers. + * The Business Delegate pattern adds an abstraction layer between the presentation and business tiers. * By using the pattern we gain loose coupling between the tiers. The Business Delegate encapsulates * knowledge about how to locate, connect to, and interact with the business objects that make up * the application. - * + * <p> * Some of the services the Business Delegate uses are instantiated directly, and some can be retrieved * through service lookups. The Business Delegate itself may contain business logic too potentially tying * together multiple service calls, exception handling, retrying etc. - * - * In this example the client (Client) utilizes a business delegate (BusinessDelegate) to execute a task. + * <p> + * In this example the client ({@link Client}) utilizes a business delegate ({@link BusinessDelegate}) to execute a task. * The Business Delegate then selects the appropriate service and makes the service call. * */ public class App { + /** + * Program entry point + * @param args command line args + */ public static void main(String[] args) { BusinessDelegate businessDelegate = new BusinessDelegate(); diff --git a/business-delegate/src/main/java/com/iluwatar/business/delegate/BusinessDelegate.java b/business-delegate/src/main/java/com/iluwatar/business/delegate/BusinessDelegate.java index d70646820..cf0809b97 100644 --- a/business-delegate/src/main/java/com/iluwatar/business/delegate/BusinessDelegate.java +++ b/business-delegate/src/main/java/com/iluwatar/business/delegate/BusinessDelegate.java @@ -2,7 +2,7 @@ package com.iluwatar.business.delegate; /** * - * BusinessDelegate separates presentation and business tiers + * BusinessDelegate separates the presentation and business tiers * */ public class BusinessDelegate { diff --git a/business-delegate/src/test/java/com/iluwatar/business/delegate/AppTest.java b/business-delegate/src/test/java/com/iluwatar/business/delegate/AppTest.java index 3a3dce68e..7ce63c2b4 100644 --- a/business-delegate/src/test/java/com/iluwatar/business/delegate/AppTest.java +++ b/business-delegate/src/test/java/com/iluwatar/business/delegate/AppTest.java @@ -4,6 +4,11 @@ import org.junit.Test; import com.iluwatar.business.delegate.App; +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/callback/src/main/java/com/iluwatar/callback/App.java b/callback/src/main/java/com/iluwatar/callback/App.java index 546a6b507..513a32415 100644 --- a/callback/src/main/java/com/iluwatar/callback/App.java +++ b/callback/src/main/java/com/iluwatar/callback/App.java @@ -1,8 +1,10 @@ package com.iluwatar.callback; /** - * Callback pattern is more native for functional languages where function is treated as first-class citizen. - * Prior to Java8 can be simulated using simple (alike command) interfaces. + * + * Callback pattern is more native for functional languages where functions are treated as first-class citizens. + * Prior to Java 8 callbacks can be simulated using simple (alike command) interfaces. + * */ public class App { diff --git a/callback/src/main/java/com/iluwatar/callback/Callback.java b/callback/src/main/java/com/iluwatar/callback/Callback.java index 9e757e218..81a421c0d 100644 --- a/callback/src/main/java/com/iluwatar/callback/Callback.java +++ b/callback/src/main/java/com/iluwatar/callback/Callback.java @@ -1,7 +1,9 @@ package com.iluwatar.callback; /** + * * Callback interface + * */ public interface Callback { diff --git a/callback/src/main/java/com/iluwatar/callback/SimpleTask.java b/callback/src/main/java/com/iluwatar/callback/SimpleTask.java index f8a27ba10..58f35709f 100644 --- a/callback/src/main/java/com/iluwatar/callback/SimpleTask.java +++ b/callback/src/main/java/com/iluwatar/callback/SimpleTask.java @@ -1,7 +1,9 @@ package com.iluwatar.callback; /** + * * Implementation of task that need to be executed + * */ public class SimpleTask extends Task { diff --git a/callback/src/main/java/com/iluwatar/callback/Task.java b/callback/src/main/java/com/iluwatar/callback/Task.java index df7bf8ae8..db4b66dc5 100644 --- a/callback/src/main/java/com/iluwatar/callback/Task.java +++ b/callback/src/main/java/com/iluwatar/callback/Task.java @@ -1,7 +1,9 @@ package com.iluwatar.callback; /** + * * Template-method class for callback hook execution + * */ public abstract class Task { diff --git a/callback/src/test/java/com/iluwatar/callback/AppTest.java b/callback/src/test/java/com/iluwatar/callback/AppTest.java index 5d7febcee..aceac1c62 100644 --- a/callback/src/test/java/com/iluwatar/callback/AppTest.java +++ b/callback/src/test/java/com/iluwatar/callback/AppTest.java @@ -4,6 +4,11 @@ import org.junit.Test; import com.iluwatar.callback.App; +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/chain/src/main/java/com/iluwatar/chain/App.java b/chain/src/main/java/com/iluwatar/chain/App.java index 21d206696..5f98b2478 100644 --- a/chain/src/main/java/com/iluwatar/chain/App.java +++ b/chain/src/main/java/com/iluwatar/chain/App.java @@ -1,22 +1,26 @@ -package com.iluwatar.chain; - -/** - * - * Chain of Responsibility organizes request handlers (RequestHandler) into a - * chain where each handler has a chance to act on the request on its turn. In - * this example the king (OrcKing) makes requests and the military orcs - * (OrcCommander, OrcOfficer, OrcSoldier) form the handler chain. - * - */ -public class App { - - public static void main(String[] args) { - - OrcKing king = new OrcKing(); - king.makeRequest(new Request(RequestType.DEFEND_CASTLE, "defend castle")); - king.makeRequest(new Request(RequestType.TORTURE_PRISONER, - "torture prisoner")); - king.makeRequest(new Request(RequestType.COLLECT_TAX, "collect tax")); - - } -} +package com.iluwatar.chain; + +/** + * + * Chain of Responsibility organizes request handlers ({@link RequestHandler}) into a + * chain where each handler has a chance to act on the request on its turn. In + * this example the king ({@link OrcKing}) makes requests and the military orcs + * ({@link OrcCommander}, {@link OrcOfficer}, {@link OrcSoldier}) form the handler chain. + * + */ +public class App { + + /** + * Program entry point + * @param args command line args + */ + public static void main(String[] args) { + + OrcKing king = new OrcKing(); + king.makeRequest(new Request(RequestType.DEFEND_CASTLE, "defend castle")); + king.makeRequest(new Request(RequestType.TORTURE_PRISONER, + "torture prisoner")); + king.makeRequest(new Request(RequestType.COLLECT_TAX, "collect tax")); + + } +} diff --git a/chain/src/main/java/com/iluwatar/chain/OrcCommander.java b/chain/src/main/java/com/iluwatar/chain/OrcCommander.java index 1f5f4de86..fb5134e01 100644 --- a/chain/src/main/java/com/iluwatar/chain/OrcCommander.java +++ b/chain/src/main/java/com/iluwatar/chain/OrcCommander.java @@ -1,22 +1,27 @@ -package com.iluwatar.chain; - -public class OrcCommander extends RequestHandler { - - public OrcCommander(RequestHandler handler) { - super(handler); - } - - @Override - public void handleRequest(Request req) { - if (req.getRequestType().equals(RequestType.DEFEND_CASTLE)) { - printHandling(req); - } else { - super.handleRequest(req); - } - } - - @Override - public String toString() { - return "Orc commander"; - } -} +package com.iluwatar.chain; + +/** + * + * OrcCommander + * + */ +public class OrcCommander extends RequestHandler { + + public OrcCommander(RequestHandler handler) { + super(handler); + } + + @Override + public void handleRequest(Request req) { + if (req.getRequestType().equals(RequestType.DEFEND_CASTLE)) { + printHandling(req); + } else { + super.handleRequest(req); + } + } + + @Override + public String toString() { + return "Orc commander"; + } +} diff --git a/chain/src/main/java/com/iluwatar/chain/OrcKing.java b/chain/src/main/java/com/iluwatar/chain/OrcKing.java index afd2616fe..b39959935 100644 --- a/chain/src/main/java/com/iluwatar/chain/OrcKing.java +++ b/chain/src/main/java/com/iluwatar/chain/OrcKing.java @@ -1,24 +1,24 @@ -package com.iluwatar.chain; - -/** - * - * Makes requests that are handled by the chain. - * - */ -public class OrcKing { - - RequestHandler chain; - - public OrcKing() { - buildChain(); - } - - private void buildChain() { - chain = new OrcCommander(new OrcOfficer(new OrcSoldier(null))); - } - - public void makeRequest(Request req) { - chain.handleRequest(req); - } - -} +package com.iluwatar.chain; + +/** + * + * OrcKing makes requests that are handled by the chain. + * + */ +public class OrcKing { + + RequestHandler chain; + + public OrcKing() { + buildChain(); + } + + private void buildChain() { + chain = new OrcCommander(new OrcOfficer(new OrcSoldier(null))); + } + + public void makeRequest(Request req) { + chain.handleRequest(req); + } + +} diff --git a/chain/src/main/java/com/iluwatar/chain/OrcOfficer.java b/chain/src/main/java/com/iluwatar/chain/OrcOfficer.java index c09729cc8..131cb1101 100644 --- a/chain/src/main/java/com/iluwatar/chain/OrcOfficer.java +++ b/chain/src/main/java/com/iluwatar/chain/OrcOfficer.java @@ -1,23 +1,28 @@ -package com.iluwatar.chain; - -public class OrcOfficer extends RequestHandler { - - public OrcOfficer(RequestHandler handler) { - super(handler); - } - - @Override - public void handleRequest(Request req) { - if (req.getRequestType().equals(RequestType.TORTURE_PRISONER)) { - printHandling(req); - } else { - super.handleRequest(req); - } - } - - @Override - public String toString() { - return "Orc officer"; - } - -} +package com.iluwatar.chain; + +/** + * + * OrcOfficer + * + */ +public class OrcOfficer extends RequestHandler { + + public OrcOfficer(RequestHandler handler) { + super(handler); + } + + @Override + public void handleRequest(Request req) { + if (req.getRequestType().equals(RequestType.TORTURE_PRISONER)) { + printHandling(req); + } else { + super.handleRequest(req); + } + } + + @Override + public String toString() { + return "Orc officer"; + } + +} diff --git a/chain/src/main/java/com/iluwatar/chain/OrcSoldier.java b/chain/src/main/java/com/iluwatar/chain/OrcSoldier.java index f52c7d543..a681dfb77 100644 --- a/chain/src/main/java/com/iluwatar/chain/OrcSoldier.java +++ b/chain/src/main/java/com/iluwatar/chain/OrcSoldier.java @@ -1,22 +1,27 @@ -package com.iluwatar.chain; - -public class OrcSoldier extends RequestHandler { - - public OrcSoldier(RequestHandler handler) { - super(handler); - } - - @Override - public void handleRequest(Request req) { - if (req.getRequestType().equals(RequestType.COLLECT_TAX)) { - printHandling(req); - } else { - super.handleRequest(req); - } - } - - @Override - public String toString() { - return "Orc soldier"; - } -} +package com.iluwatar.chain; + +/** + * + * OrcSoldier + * + */ +public class OrcSoldier extends RequestHandler { + + public OrcSoldier(RequestHandler handler) { + super(handler); + } + + @Override + public void handleRequest(Request req) { + if (req.getRequestType().equals(RequestType.COLLECT_TAX)) { + printHandling(req); + } else { + super.handleRequest(req); + } + } + + @Override + public String toString() { + return "Orc soldier"; + } +} diff --git a/chain/src/main/java/com/iluwatar/chain/Request.java b/chain/src/main/java/com/iluwatar/chain/Request.java index ad55522f0..558ee65d1 100644 --- a/chain/src/main/java/com/iluwatar/chain/Request.java +++ b/chain/src/main/java/com/iluwatar/chain/Request.java @@ -1,33 +1,38 @@ -package com.iluwatar.chain; - -public class Request { - - private String requestDescription; - private RequestType requestType; - - public Request(RequestType requestType, String requestDescription) { - this.setRequestType(requestType); - this.setRequestDescription(requestDescription); - } - - public String getRequestDescription() { - return requestDescription; - } - - public void setRequestDescription(String requestDescription) { - this.requestDescription = requestDescription; - } - - public RequestType getRequestType() { - return requestType; - } - - public void setRequestType(RequestType requestType) { - this.requestType = requestType; - } - - @Override - public String toString() { - return getRequestDescription(); - } -} +package com.iluwatar.chain; + +/** + * + * Request + * + */ +public class Request { + + private String requestDescription; + private RequestType requestType; + + public Request(RequestType requestType, String requestDescription) { + this.setRequestType(requestType); + this.setRequestDescription(requestDescription); + } + + public String getRequestDescription() { + return requestDescription; + } + + public void setRequestDescription(String requestDescription) { + this.requestDescription = requestDescription; + } + + public RequestType getRequestType() { + return requestType; + } + + public void setRequestType(RequestType requestType) { + this.requestType = requestType; + } + + @Override + public String toString() { + return getRequestDescription(); + } +} diff --git a/chain/src/main/java/com/iluwatar/chain/RequestHandler.java b/chain/src/main/java/com/iluwatar/chain/RequestHandler.java index dbb8b10a6..5570c20ce 100644 --- a/chain/src/main/java/com/iluwatar/chain/RequestHandler.java +++ b/chain/src/main/java/com/iluwatar/chain/RequestHandler.java @@ -1,23 +1,28 @@ -package com.iluwatar.chain; - -public abstract class RequestHandler { - - private RequestHandler next; - - public RequestHandler(RequestHandler next) { - this.next = next; - } - - public void handleRequest(Request req) { - if (next != null) { - next.handleRequest(req); - } - } - - protected void printHandling(Request req) { - System.out.println(this + " handling request \"" + req + "\""); - } - - @Override - public abstract String toString(); -} +package com.iluwatar.chain; + +/** + * + * RequestHandler + * + */ +public abstract class RequestHandler { + + private RequestHandler next; + + public RequestHandler(RequestHandler next) { + this.next = next; + } + + public void handleRequest(Request req) { + if (next != null) { + next.handleRequest(req); + } + } + + protected void printHandling(Request req) { + System.out.println(this + " handling request \"" + req + "\""); + } + + @Override + public abstract String toString(); +} diff --git a/chain/src/main/java/com/iluwatar/chain/RequestType.java b/chain/src/main/java/com/iluwatar/chain/RequestType.java index 21727535e..9ad975d2f 100644 --- a/chain/src/main/java/com/iluwatar/chain/RequestType.java +++ b/chain/src/main/java/com/iluwatar/chain/RequestType.java @@ -1,7 +1,12 @@ -package com.iluwatar.chain; - -public enum RequestType { - - DEFEND_CASTLE, TORTURE_PRISONER, COLLECT_TAX - -} +package com.iluwatar.chain; + +/** + * + * RequestType enumeration + * + */ +public enum RequestType { + + DEFEND_CASTLE, TORTURE_PRISONER, COLLECT_TAX + +} diff --git a/chain/src/test/java/com/iluwatar/chain/AppTest.java b/chain/src/test/java/com/iluwatar/chain/AppTest.java index 5edba69bb..aa52e60e2 100644 --- a/chain/src/test/java/com/iluwatar/chain/AppTest.java +++ b/chain/src/test/java/com/iluwatar/chain/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.chain; - -import org.junit.Test; - -import com.iluwatar.chain.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.chain; + +import org.junit.Test; + +import com.iluwatar.chain.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/command/src/main/java/com/iluwatar/command/App.java b/command/src/main/java/com/iluwatar/command/App.java index 6d9df821c..fc05afa66 100644 --- a/command/src/main/java/com/iluwatar/command/App.java +++ b/command/src/main/java/com/iluwatar/command/App.java @@ -3,15 +3,15 @@ package com.iluwatar.command; /** * * In Command pattern actions are objects that can be executed and undone. - * + * <p> * Four terms always associated with the command pattern are command, receiver, invoker and client. A command - * object (spell) knows about receiver (target) and invokes a method of the receiver. Values for parameters of + * object (spell) knows about the receiver (target) and invokes a method of the receiver. Values for parameters of * the receiver method are stored in the command. The receiver then does the work. An invoker object (wizard) * knows how to execute a command, and optionally does bookkeeping about the command execution. The invoker * does not know anything about a concrete command, it knows only about command interface. Both an invoker object * and several command objects are held by a client object (app). The client decides which commands to execute at * which points. To execute a command, it passes the command object to the invoker object. - * + * <p> * In other words, in this example the wizard casts spells on the goblin. The wizard keeps track of the previous * spells cast, so it is easy to undo them. In addition, the wizard keeps track of the spells undone, so they * can be redone. @@ -20,6 +20,10 @@ package com.iluwatar.command; */ public class App { + /** + * Program entry point + * @param args command line args + */ public static void main(String[] args) { Wizard wizard = new Wizard(); Goblin goblin = new Goblin(); diff --git a/command/src/test/java/com/iluwatar/command/AppTest.java b/command/src/test/java/com/iluwatar/command/AppTest.java index 454f92b63..2fd5c16b4 100644 --- a/command/src/test/java/com/iluwatar/command/AppTest.java +++ b/command/src/test/java/com/iluwatar/command/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.command; - -import org.junit.Test; - -import com.iluwatar.command.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.command; + +import org.junit.Test; + +import com.iluwatar.command.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/composite/src/main/java/com/iluwatar/composite/App.java b/composite/src/main/java/com/iluwatar/composite/App.java index 6dd62a552..7dfd15443 100644 --- a/composite/src/main/java/com/iluwatar/composite/App.java +++ b/composite/src/main/java/com/iluwatar/composite/App.java @@ -1,25 +1,29 @@ -package com.iluwatar.composite; - -/** - * - * With Composite we can treat tree hierarchies of objects with uniform - * interface (LetterComposite). In this example we have sentences composed of - * words composed of letters. - * - */ -public class App { - - public static void main(String[] args) { - System.out.println("Message from the orcs: "); - - LetterComposite orcMessage = new Messenger().messageFromOrcs(); - orcMessage.print(); - - System.out.println("\n"); - - System.out.println("Message from the elves: "); - - LetterComposite elfMessage = new Messenger().messageFromElves(); - elfMessage.print(); - } -} +package com.iluwatar.composite; + +/** + * + * With Composite we can treat tree hierarchies of objects with uniform + * interface ({@link LetterComposite}). In this example we have sentences composed of + * words composed of letters. + * + */ +public class App { + + /** + * Program entry point + * @param args command line args + */ + public static void main(String[] args) { + System.out.println("Message from the orcs: "); + + LetterComposite orcMessage = new Messenger().messageFromOrcs(); + orcMessage.print(); + + System.out.println("\n"); + + System.out.println("Message from the elves: "); + + LetterComposite elfMessage = new Messenger().messageFromElves(); + elfMessage.print(); + } +} diff --git a/composite/src/main/java/com/iluwatar/composite/Letter.java b/composite/src/main/java/com/iluwatar/composite/Letter.java index 9df8b95f7..8304ea801 100644 --- a/composite/src/main/java/com/iluwatar/composite/Letter.java +++ b/composite/src/main/java/com/iluwatar/composite/Letter.java @@ -1,21 +1,26 @@ -package com.iluwatar.composite; - -public class Letter extends LetterComposite { - - private char c; - - public Letter(char c) { - this.c = c; - } - - @Override - protected void printThisBefore() { - System.out.print(c); - } - - @Override - protected void printThisAfter() { - // nop - } - -} +package com.iluwatar.composite; + +/** + * + * Letter + * + */ +public class Letter extends LetterComposite { + + private char c; + + public Letter(char c) { + this.c = c; + } + + @Override + protected void printThisBefore() { + System.out.print(c); + } + + @Override + protected void printThisAfter() { + // nop + } + +} diff --git a/composite/src/main/java/com/iluwatar/composite/Messenger.java b/composite/src/main/java/com/iluwatar/composite/Messenger.java index a849408ca..aa0560d4d 100644 --- a/composite/src/main/java/com/iluwatar/composite/Messenger.java +++ b/composite/src/main/java/com/iluwatar/composite/Messenger.java @@ -1,53 +1,58 @@ -package com.iluwatar.composite; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class Messenger { - - LetterComposite messageFromOrcs() { - - List<Word> words = new ArrayList<Word>(); - - words.add(new Word(Arrays.asList(new Letter('W'), new Letter('h'), - new Letter('e'), new Letter('r'), new Letter('e')))); - words.add(new Word(Arrays.asList(new Letter('t'), new Letter('h'), - new Letter('e'), new Letter('r'), new Letter('e')))); - words.add(new Word(Arrays.asList(new Letter('i'), new Letter('s')))); - words.add(new Word(Arrays.asList(new Letter('a')))); - words.add(new Word(Arrays.asList(new Letter('w'), new Letter('h'), - new Letter('i'), new Letter('p')))); - words.add(new Word(Arrays.asList(new Letter('t'), new Letter('h'), - new Letter('e'), new Letter('r'), new Letter('e')))); - words.add(new Word(Arrays.asList(new Letter('i'), new Letter('s')))); - words.add(new Word(Arrays.asList(new Letter('a')))); - words.add(new Word(Arrays.asList(new Letter('w'), new Letter('a'), - new Letter('y')))); - - return new Sentence(words); - - } - - LetterComposite messageFromElves() { - - List<Word> words = new ArrayList<Word>(); - - words.add(new Word(Arrays.asList(new Letter('M'), new Letter('u'), - new Letter('c'), new Letter('h')))); - words.add(new Word(Arrays.asList(new Letter('w'), new Letter('i'), - new Letter('n'), new Letter('d')))); - words.add(new Word(Arrays.asList(new Letter('p'), new Letter('o'), - new Letter('u'), new Letter('r'), new Letter('s')))); - words.add(new Word(Arrays.asList(new Letter('f'), new Letter('r'), - new Letter('o'), new Letter('m')))); - words.add(new Word(Arrays.asList(new Letter('y'), new Letter('o'), - new Letter('u'), new Letter('r')))); - words.add(new Word(Arrays.asList(new Letter('m'), new Letter('o'), - new Letter('u'), new Letter('t'), new Letter('h')))); - - return new Sentence(words); - - } - -} +package com.iluwatar.composite; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * + * Messenger + * + */ +public class Messenger { + + LetterComposite messageFromOrcs() { + + List<Word> words = new ArrayList<Word>(); + + words.add(new Word(Arrays.asList(new Letter('W'), new Letter('h'), + new Letter('e'), new Letter('r'), new Letter('e')))); + words.add(new Word(Arrays.asList(new Letter('t'), new Letter('h'), + new Letter('e'), new Letter('r'), new Letter('e')))); + words.add(new Word(Arrays.asList(new Letter('i'), new Letter('s')))); + words.add(new Word(Arrays.asList(new Letter('a')))); + words.add(new Word(Arrays.asList(new Letter('w'), new Letter('h'), + new Letter('i'), new Letter('p')))); + words.add(new Word(Arrays.asList(new Letter('t'), new Letter('h'), + new Letter('e'), new Letter('r'), new Letter('e')))); + words.add(new Word(Arrays.asList(new Letter('i'), new Letter('s')))); + words.add(new Word(Arrays.asList(new Letter('a')))); + words.add(new Word(Arrays.asList(new Letter('w'), new Letter('a'), + new Letter('y')))); + + return new Sentence(words); + + } + + LetterComposite messageFromElves() { + + List<Word> words = new ArrayList<Word>(); + + words.add(new Word(Arrays.asList(new Letter('M'), new Letter('u'), + new Letter('c'), new Letter('h')))); + words.add(new Word(Arrays.asList(new Letter('w'), new Letter('i'), + new Letter('n'), new Letter('d')))); + words.add(new Word(Arrays.asList(new Letter('p'), new Letter('o'), + new Letter('u'), new Letter('r'), new Letter('s')))); + words.add(new Word(Arrays.asList(new Letter('f'), new Letter('r'), + new Letter('o'), new Letter('m')))); + words.add(new Word(Arrays.asList(new Letter('y'), new Letter('o'), + new Letter('u'), new Letter('r')))); + words.add(new Word(Arrays.asList(new Letter('m'), new Letter('o'), + new Letter('u'), new Letter('t'), new Letter('h')))); + + return new Sentence(words); + + } + +} diff --git a/composite/src/main/java/com/iluwatar/composite/Sentence.java b/composite/src/main/java/com/iluwatar/composite/Sentence.java index c83c520de..2fc13701b 100644 --- a/composite/src/main/java/com/iluwatar/composite/Sentence.java +++ b/composite/src/main/java/com/iluwatar/composite/Sentence.java @@ -1,23 +1,28 @@ -package com.iluwatar.composite; - -import java.util.List; - -public class Sentence extends LetterComposite { - - public Sentence(List<Word> words) { - for (Word w : words) { - this.add(w); - } - } - - @Override - protected void printThisBefore() { - // nop - } - - @Override - protected void printThisAfter() { - System.out.print("."); - } - -} +package com.iluwatar.composite; + +import java.util.List; + +/** + * + * Sentence + * + */ +public class Sentence extends LetterComposite { + + public Sentence(List<Word> words) { + for (Word w : words) { + this.add(w); + } + } + + @Override + protected void printThisBefore() { + // nop + } + + @Override + protected void printThisAfter() { + System.out.print("."); + } + +} diff --git a/composite/src/main/java/com/iluwatar/composite/Word.java b/composite/src/main/java/com/iluwatar/composite/Word.java index 393cd2019..e715ed28a 100644 --- a/composite/src/main/java/com/iluwatar/composite/Word.java +++ b/composite/src/main/java/com/iluwatar/composite/Word.java @@ -1,23 +1,28 @@ -package com.iluwatar.composite; - -import java.util.List; - -public class Word extends LetterComposite { - - public Word(List<Letter> letters) { - for (Letter l : letters) { - this.add(l); - } - } - - @Override - protected void printThisBefore() { - System.out.print(" "); - } - - @Override - protected void printThisAfter() { - // nop - } - -} +package com.iluwatar.composite; + +import java.util.List; + +/** + * + * Word + * + */ +public class Word extends LetterComposite { + + public Word(List<Letter> letters) { + for (Letter l : letters) { + this.add(l); + } + } + + @Override + protected void printThisBefore() { + System.out.print(" "); + } + + @Override + protected void printThisAfter() { + // nop + } + +} diff --git a/composite/src/test/java/com/iluwatar/composite/AppTest.java b/composite/src/test/java/com/iluwatar/composite/AppTest.java index 5057efe68..872ccea78 100644 --- a/composite/src/test/java/com/iluwatar/composite/AppTest.java +++ b/composite/src/test/java/com/iluwatar/composite/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.composite; - -import org.junit.Test; - -import com.iluwatar.composite.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.composite; + +import org.junit.Test; + +import com.iluwatar.composite.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/dao/src/main/java/com/iluwatar/dao/App.java b/dao/src/main/java/com/iluwatar/dao/App.java index dd96cf807..ac6794973 100644 --- a/dao/src/main/java/com/iluwatar/dao/App.java +++ b/dao/src/main/java/com/iluwatar/dao/App.java @@ -1,47 +1,56 @@ -package com.iluwatar.dao; - -import java.util.ArrayList; -import java.util.List; - -/** - * - * With the DAO pattern, we can use various method calls to retrieve/add/delete/update data without directly - * interacting with the data. The below example demonstrates basic operations(CRUD): select, add, update, and delete. - */ -public class App { - - public static void main(String[] args) { - - CustomerDaoImpl customerDao = new CustomerDaoImpl(generateSampleCustomers()); - - System.out.println("customerDao.getAllCustomers(): " + customerDao.getAllCustomers()); - System.out.println("customerDao.getCusterById(2): " + customerDao.getCusterById(2)); - - Customer customer = new Customer(4, "Dan", "Danson"); - customerDao.addCustomer(customer); - - System.out.println("customerDao.getAllCustomers(): " + customerDao.getAllCustomers()); - - customer.setFirstName("Daniel"); - customer.setLastName("Danielson"); - customerDao.updateCustomer(customer); - - System.out.println("customerDao.getAllCustomers(): " + customerDao.getAllCustomers()); - - customerDao.deleteCustomer(customer); - - System.out.println("customerDao.getAllCustomers(): " + customerDao.getAllCustomers()); - } - - public static List<Customer> generateSampleCustomers() { - Customer customer1 = new Customer(1, "Adam", "Adamson"); - Customer customer2 = new Customer(2, "Bob", "Bobson"); - Customer customer3 = new Customer(3, "Carl", "Carlson"); - - List<Customer> customers = new ArrayList<Customer>(); - customers.add(customer1); - customers.add(customer2); - customers.add(customer3); - return customers; - } -} +package com.iluwatar.dao; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * With the DAO pattern, we can use various method calls to retrieve/add/delete/update data without directly + * interacting with the data. The below example demonstrates basic operations(CRUD): select, add, update, and delete. + * + */ +public class App { + + /** + * Program entry point + * @param args command line args + */ + public static void main(String[] args) { + + CustomerDaoImpl customerDao = new CustomerDaoImpl(generateSampleCustomers()); + + System.out.println("customerDao.getAllCustomers(): " + customerDao.getAllCustomers()); + System.out.println("customerDao.getCusterById(2): " + customerDao.getCusterById(2)); + + Customer customer = new Customer(4, "Dan", "Danson"); + customerDao.addCustomer(customer); + + System.out.println("customerDao.getAllCustomers(): " + customerDao.getAllCustomers()); + + customer.setFirstName("Daniel"); + customer.setLastName("Danielson"); + customerDao.updateCustomer(customer); + + System.out.println("customerDao.getAllCustomers(): " + customerDao.getAllCustomers()); + + customerDao.deleteCustomer(customer); + + System.out.println("customerDao.getAllCustomers(): " + customerDao.getAllCustomers()); + } + + /** + * Generate customers + * @return list of customers + */ + public static List<Customer> generateSampleCustomers() { + Customer customer1 = new Customer(1, "Adam", "Adamson"); + Customer customer2 = new Customer(2, "Bob", "Bobson"); + Customer customer3 = new Customer(3, "Carl", "Carlson"); + + List<Customer> customers = new ArrayList<Customer>(); + customers.add(customer1); + customers.add(customer2); + customers.add(customer3); + return customers; + } +} diff --git a/dao/src/main/java/com/iluwatar/dao/Customer.java b/dao/src/main/java/com/iluwatar/dao/Customer.java index 7900fee67..8cfdd8034 100644 --- a/dao/src/main/java/com/iluwatar/dao/Customer.java +++ b/dao/src/main/java/com/iluwatar/dao/Customer.java @@ -1,6 +1,12 @@ package com.iluwatar.dao; +/** + * + * Customer + * + */ public class Customer { + private int id; private String firstName; private String lastName; diff --git a/dao/src/main/java/com/iluwatar/dao/CustomerDao.java b/dao/src/main/java/com/iluwatar/dao/CustomerDao.java index f201d945d..2a50d2bfb 100644 --- a/dao/src/main/java/com/iluwatar/dao/CustomerDao.java +++ b/dao/src/main/java/com/iluwatar/dao/CustomerDao.java @@ -2,7 +2,13 @@ package com.iluwatar.dao; import java.util.List; +/** + * + * CustomerDao + * + */ public interface CustomerDao { + public List<Customer> getAllCustomers(); public Customer getCusterById(int id); public void addCustomer(Customer customer); diff --git a/dao/src/main/java/com/iluwatar/dao/CustomerDaoImpl.java b/dao/src/main/java/com/iluwatar/dao/CustomerDaoImpl.java index ff5332798..4403b57ed 100644 --- a/dao/src/main/java/com/iluwatar/dao/CustomerDaoImpl.java +++ b/dao/src/main/java/com/iluwatar/dao/CustomerDaoImpl.java @@ -3,11 +3,13 @@ package com.iluwatar.dao; import java.util.List; /** + * * The data access object (DAO) is an object that provides an abstract interface to some type of database or other persistence mechanism. * By mapping application calls to the persistence layer, DAO provide some specific data operations without exposing details of the database. * This isolation supports the Single responsibility principle. It separates what data accesses the application needs, in terms of * domain-specific objects and data types (the public interface of the DAO), from how these needs can be satisfied with a specific DBMS, * database schema, etc. + * */ public class CustomerDaoImpl implements CustomerDao { diff --git a/dao/src/test/java/com/iluwatar/dao/AppTest.java b/dao/src/test/java/com/iluwatar/dao/AppTest.java index d45e0ef18..5eb1ebb11 100644 --- a/dao/src/test/java/com/iluwatar/dao/AppTest.java +++ b/dao/src/test/java/com/iluwatar/dao/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.dao; - -import org.junit.Test; - -import com.iluwatar.dao.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.dao; + +import org.junit.Test; + +import com.iluwatar.dao.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/decorator/src/main/java/com/iluwatar/decorator/App.java b/decorator/src/main/java/com/iluwatar/decorator/App.java index f424f51b9..88e1c7103 100644 --- a/decorator/src/main/java/com/iluwatar/decorator/App.java +++ b/decorator/src/main/java/com/iluwatar/decorator/App.java @@ -1,29 +1,33 @@ -package com.iluwatar.decorator; - -/** - * - * Decorator pattern is more flexible alternative to subclassing. The decorator - * class implements the same interface as the target and uses composition to - * "decorate" calls to the target. - * - * Using decorator pattern it is possible to change class behavior during - * runtime, as the example shows. - * - */ -public class App { - - public static void main(String[] args) { - - // simple troll - System.out.println("A simple looking troll approaches."); - Hostile troll = new Troll(); - troll.attack(); - troll.fleeBattle(); - - // change the behavior of the simple troll by adding a decorator - System.out.println("\nA smart looking troll surprises you."); - Hostile smart = new SmartTroll(troll); - smart.attack(); - smart.fleeBattle(); - } -} +package com.iluwatar.decorator; + +/** + * + * Decorator pattern is a more flexible alternative to subclassing. The decorator + * class implements the same interface as the target and uses composition to + * "decorate" calls to the target. + * <p> + * Using decorator pattern it is possible to change class behavior during + * runtime, as the example shows. + * + */ +public class App { + + /** + * Program entry point + * @param args command line args + */ + public static void main(String[] args) { + + // simple troll + System.out.println("A simple looking troll approaches."); + Hostile troll = new Troll(); + troll.attack(); + troll.fleeBattle(); + + // change the behavior of the simple troll by adding a decorator + System.out.println("\nA smart looking troll surprises you."); + Hostile smart = new SmartTroll(troll); + smart.attack(); + smart.fleeBattle(); + } +} diff --git a/decorator/src/main/java/com/iluwatar/decorator/SmartTroll.java b/decorator/src/main/java/com/iluwatar/decorator/SmartTroll.java index 9baa729f3..22ba88dc8 100644 --- a/decorator/src/main/java/com/iluwatar/decorator/SmartTroll.java +++ b/decorator/src/main/java/com/iluwatar/decorator/SmartTroll.java @@ -1,30 +1,30 @@ -package com.iluwatar.decorator; - -/** - * SmartTroll is a decorator for Hostile objects. - * The calls to the Hostile interface are intercepted - * and decorated. Finally the calls are delegated - * to the decorated Hostile object. - * - */ -public class SmartTroll implements Hostile { - - private Hostile decorated; - - public SmartTroll(Hostile decorated) { - this.decorated = decorated; - } - - @Override - public void attack() { - System.out.println("The troll throws a rock at you!"); - decorated.attack(); - } - - @Override - public void fleeBattle() { - System.out.println("The troll calls for help!"); - decorated.fleeBattle(); - } - -} +package com.iluwatar.decorator; + +/** + * SmartTroll 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} object. + * + */ +public class SmartTroll implements Hostile { + + private Hostile decorated; + + public SmartTroll(Hostile decorated) { + this.decorated = decorated; + } + + @Override + public void attack() { + System.out.println("The troll throws a rock at you!"); + decorated.attack(); + } + + @Override + public void fleeBattle() { + System.out.println("The troll calls for help!"); + decorated.fleeBattle(); + } + +} diff --git a/decorator/src/main/java/com/iluwatar/decorator/Troll.java b/decorator/src/main/java/com/iluwatar/decorator/Troll.java index 8d6cd0aa5..11e9b9d1a 100644 --- a/decorator/src/main/java/com/iluwatar/decorator/Troll.java +++ b/decorator/src/main/java/com/iluwatar/decorator/Troll.java @@ -1,18 +1,18 @@ -package com.iluwatar.decorator; - -/** - * - * Troll implements Hostile interface directly. - * - */ -public class Troll implements Hostile { - - public void attack() { - System.out.println("The troll swings at you with a club!"); - } - - public void fleeBattle() { - System.out.println("The troll shrieks in horror and runs away!"); - } - -} +package com.iluwatar.decorator; + +/** + * + * Troll implements {@link Hostile} interface directly. + * + */ +public class Troll implements Hostile { + + public void attack() { + System.out.println("The troll swings at you with a club!"); + } + + public void fleeBattle() { + System.out.println("The troll shrieks in horror and runs away!"); + } + +} diff --git a/decorator/src/test/java/com/iluwatar/decorator/AppTest.java b/decorator/src/test/java/com/iluwatar/decorator/AppTest.java index 28776c930..b74bd3a06 100644 --- a/decorator/src/test/java/com/iluwatar/decorator/AppTest.java +++ b/decorator/src/test/java/com/iluwatar/decorator/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.decorator; - -import org.junit.Test; - -import com.iluwatar.decorator.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.decorator; + +import org.junit.Test; + +import com.iluwatar.decorator.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/App.java b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/App.java index 5d15e3742..a882863b7 100644 --- a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/App.java +++ b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/App.java @@ -9,23 +9,27 @@ import com.google.inject.Injector; * implements so called inversion of control principle. Inversion of control has two specific rules: * - High-level modules should not depend on low-level modules. Both should depend on abstractions. * - Abstractions should not depend on details. Details should depend on abstractions. - * - * In this example we show you three different wizards. The first one (SimpleWizard) is a naive + * <p> + * In this example we show you three different wizards. The first one ({@link SimpleWizard}) is a naive * implementation violating the inversion of control principle. It depends directly on a concrete * implementation which cannot be changed. - * - * The second wizard (AdvancedWizard) is more flexible. It does not depend on any concrete implementation - * but abstraction. It utilizes Dependency Injection pattern allowing its Tobacco dependency to be + * <p> + * The second wizard ({@link AdvancedWizard}) is more flexible. It does not depend on any concrete implementation + * but abstraction. It utilizes Dependency Injection pattern allowing its {@link Tobacco} dependency to be * injected through its constructor. This way, handling the dependency is no longer the wizard's * responsibility. It is resolved outside the wizard class. - * + * <p> * The third example takes the pattern a step further. It uses Guice framework for Dependency Injection. - * TobaccoModule binds a concrete implementation to abstraction. Injector is then used to create - * GuiceWizard object with correct dependencies. + * {@link TobaccoModule} binds a concrete implementation to abstraction. Injector is then used to create + * {@link GuiceWizard} object with correct dependencies. * */ public class App { + /** + * Program entry point + * @param args command line args + */ public static void main( String[] args ) { SimpleWizard simpleWizard = new SimpleWizard(); simpleWizard.smoke(); diff --git a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/OldTobyTobacco.java b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/OldTobyTobacco.java index 08d9c0d12..9197066ee 100644 --- a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/OldTobyTobacco.java +++ b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/OldTobyTobacco.java @@ -2,7 +2,7 @@ package com.iluwatar.dependency.injection; /** * - * OldTobyTobacco concrete Tobacco implementation + * OldTobyTobacco concrete {@link Tobacco} implementation * */ public class OldTobyTobacco extends Tobacco { diff --git a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/RivendellTobacco.java b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/RivendellTobacco.java index b64a6b93b..9eb137a05 100644 --- a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/RivendellTobacco.java +++ b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/RivendellTobacco.java @@ -2,7 +2,7 @@ package com.iluwatar.dependency.injection; /** * - * RivendellTobacco concrete Tobacco implementation + * RivendellTobacco concrete {@link Tobacco} implementation * */ public class RivendellTobacco extends Tobacco { diff --git a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/SecondBreakfastTobacco.java b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/SecondBreakfastTobacco.java index 1826f269a..269f531d3 100644 --- a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/SecondBreakfastTobacco.java +++ b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/SecondBreakfastTobacco.java @@ -2,7 +2,7 @@ package com.iluwatar.dependency.injection; /** * - * SecondBreakfastTobacco concrete Tobacco implementation + * SecondBreakfastTobacco concrete {@link Tobacco} implementation * */ public class SecondBreakfastTobacco extends Tobacco { diff --git a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/TobaccoModule.java b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/TobaccoModule.java index 12c5a57ff..d2dd1072e 100644 --- a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/TobaccoModule.java +++ b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/TobaccoModule.java @@ -4,7 +4,7 @@ import com.google.inject.AbstractModule; /** * - * Guice module for binding certain concrete Tobacco implementation. + * Guice module for binding certain concrete {@link Tobacco} implementation. * */ public class TobaccoModule extends AbstractModule { diff --git a/dependency-injection/src/test/java/com/iluwatar/dependency/injection/AppTest.java b/dependency-injection/src/test/java/com/iluwatar/dependency/injection/AppTest.java index d01bc7cbe..5315fe1db 100644 --- a/dependency-injection/src/test/java/com/iluwatar/dependency/injection/AppTest.java +++ b/dependency-injection/src/test/java/com/iluwatar/dependency/injection/AppTest.java @@ -4,6 +4,11 @@ import org.junit.Test; import com.iluwatar.dependency.injection.App; +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/double-checked-locking/src/main/java/com/iluwatar/doublechecked/locking/App.java b/double-checked-locking/src/main/java/com/iluwatar/doublechecked/locking/App.java index 10d22a5b2..2a5c65813 100644 --- a/double-checked-locking/src/main/java/com/iluwatar/doublechecked/locking/App.java +++ b/double-checked-locking/src/main/java/com/iluwatar/doublechecked/locking/App.java @@ -5,13 +5,18 @@ import java.util.concurrent.Executors; /** * - * In Inventory we store the items with a given size. However, we do not store + * In {@link Inventory} we store the items with a given size. However, we do not store * more items than the inventory size. To address concurrent access problems we * use double checked locking to add item to inventory. In this method, the * thread which gets the lock first adds the item. + * */ public class App { + /** + * Program entry point + * @param args command line args + */ public static void main(String[] args) { final Inventory inventory = new Inventory(1000); ExecutorService executorService = Executors.newFixedThreadPool(3); diff --git a/double-checked-locking/src/main/java/com/iluwatar/doublechecked/locking/Inventory.java b/double-checked-locking/src/main/java/com/iluwatar/doublechecked/locking/Inventory.java index e69d30b10..9f663f272 100644 --- a/double-checked-locking/src/main/java/com/iluwatar/doublechecked/locking/Inventory.java +++ b/double-checked-locking/src/main/java/com/iluwatar/doublechecked/locking/Inventory.java @@ -5,6 +5,11 @@ import java.util.List; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +/** + * + * Inventory + * + */ public class Inventory { private int inventorySize; diff --git a/double-checked-locking/src/main/java/com/iluwatar/doublechecked/locking/Item.java b/double-checked-locking/src/main/java/com/iluwatar/doublechecked/locking/Item.java index 81db22115..8fc7f3888 100644 --- a/double-checked-locking/src/main/java/com/iluwatar/doublechecked/locking/Item.java +++ b/double-checked-locking/src/main/java/com/iluwatar/doublechecked/locking/Item.java @@ -1,6 +1,12 @@ package com.iluwatar.doublechecked.locking; +/** + * + * Item + * + */ public class Item { - String name; - int level; + + private String name; + private int level; } diff --git a/double-checked-locking/src/test/java/com/iluwatar/doublechecked/locking/AppTest.java b/double-checked-locking/src/test/java/com/iluwatar/doublechecked/locking/AppTest.java index 51db32c4f..14fd47488 100644 --- a/double-checked-locking/src/test/java/com/iluwatar/doublechecked/locking/AppTest.java +++ b/double-checked-locking/src/test/java/com/iluwatar/doublechecked/locking/AppTest.java @@ -4,6 +4,11 @@ import org.junit.Test; import com.iluwatar.doublechecked.locking.App; +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/double-dispatch/src/main/java/com/iluwatar/doubledispatch/App.java b/double-dispatch/src/main/java/com/iluwatar/doubledispatch/App.java index fa799ecfc..f32c93cb1 100644 --- a/double-dispatch/src/main/java/com/iluwatar/doubledispatch/App.java +++ b/double-dispatch/src/main/java/com/iluwatar/doubledispatch/App.java @@ -8,23 +8,27 @@ import java.util.List; * When a message with a parameter is sent to an object, the resultant behaviour is defined by the * implementation of that method in the receiver. Sometimes the behaviour must also be determined * by the type of the parameter. - * + * <p> * One way to implement this would be to create multiple instanceof-checks for the methods parameter. * However, this creates a maintenance issue. When new types are added we would also need to change * the method's implementation and add a new instanceof-check. This violates the single responsibility * principle - a class should have only one reason to change. - * + * <p> * Instead of the instanceof-checks a better way is to make another virtual call on the parameter * object. This way new functionality can be easily added without the need to modify existing * implementation (open-closed principle). - * - * In this example we have hierarchy of objects (GameObject) that can collide to each other. Each + * <p> + * In this example we have hierarchy of objects ({@link GameObject}) that can collide to each other. Each * object has its own coordinates which are checked against the other objects' coordinates. If * there is an overlap, then the objects collide utilizing the Double Dispatch pattern. * */ public class App { + /** + * Program entry point + * @param args command line args + */ public static void main( String[] args ) { // initialize game objects and print their status List<GameObject> objects = new ArrayList<>(); diff --git a/double-dispatch/src/test/java/com/iluwatar/doubledispatch/AppTest.java b/double-dispatch/src/test/java/com/iluwatar/doubledispatch/AppTest.java index 892772e09..be93ee559 100644 --- a/double-dispatch/src/test/java/com/iluwatar/doubledispatch/AppTest.java +++ b/double-dispatch/src/test/java/com/iluwatar/doubledispatch/AppTest.java @@ -4,6 +4,11 @@ import org.junit.Test; import com.iluwatar.doubledispatch.App; +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/event-aggregator/src/main/java/com/iluwatar/event/aggregator/App.java b/event-aggregator/src/main/java/com/iluwatar/event/aggregator/App.java index 44c678f81..029489077 100644 --- a/event-aggregator/src/main/java/com/iluwatar/event/aggregator/App.java +++ b/event-aggregator/src/main/java/com/iluwatar/event/aggregator/App.java @@ -7,14 +7,18 @@ import java.util.List; * * The Event Aggregator pattern channels events from multiple objects * into a single object to simplify registration for clients. - * - * In the example LordBaelish, LordVarys and Scout deliver events to - * KingsHand. KingsHand, the event aggregator, then delivers the events - * to KingJoffrey. + * <p> + * In the example {@link LordBaelish}, {@link LordVarys} and {@link Scout} deliver events to + * {@link KingsHand}. {@link KingsHand}, the event aggregator, then delivers the events + * to {@link KingJoffrey}. * */ public class App { + /** + * Program entry point + * @param args command line args + */ public static void main(String[] args) { KingJoffrey kingJoffrey = new KingJoffrey(); diff --git a/event-aggregator/src/main/java/com/iluwatar/event/aggregator/KingJoffrey.java b/event-aggregator/src/main/java/com/iluwatar/event/aggregator/KingJoffrey.java index c94d821be..da45f2f1e 100644 --- a/event-aggregator/src/main/java/com/iluwatar/event/aggregator/KingJoffrey.java +++ b/event-aggregator/src/main/java/com/iluwatar/event/aggregator/KingJoffrey.java @@ -2,7 +2,7 @@ package com.iluwatar.event.aggregator; /** * - * KingJoffrey observes events from KingsHand. + * KingJoffrey observes events from {@link KingsHand}. * */ public class KingJoffrey implements EventObserver { diff --git a/event-aggregator/src/main/java/com/iluwatar/event/aggregator/Weekday.java b/event-aggregator/src/main/java/com/iluwatar/event/aggregator/Weekday.java index 651a4e71c..bafc4f36a 100644 --- a/event-aggregator/src/main/java/com/iluwatar/event/aggregator/Weekday.java +++ b/event-aggregator/src/main/java/com/iluwatar/event/aggregator/Weekday.java @@ -1,5 +1,10 @@ package com.iluwatar.event.aggregator; +/** + * + * Weekday enumeration + * + */ public enum Weekday { MONDAY("Monday"), TUESDAY("Tuesday"), WEDNESDAY("Wednesday"), THURSDAY("Thursday"), FRIDAY("Friday"), SATURDAY("Saturday"), SUNDAY("Sunday"); diff --git a/event-aggregator/src/test/java/com/iluwatar/event/aggregator/AppTest.java b/event-aggregator/src/test/java/com/iluwatar/event/aggregator/AppTest.java index 1d2562e2c..f8f765880 100644 --- a/event-aggregator/src/test/java/com/iluwatar/event/aggregator/AppTest.java +++ b/event-aggregator/src/test/java/com/iluwatar/event/aggregator/AppTest.java @@ -3,6 +3,11 @@ import org.junit.Test; import com.iluwatar.event.aggregator.App; +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/execute-around/src/main/java/com/iluwatar/execute/around/App.java b/execute-around/src/main/java/com/iluwatar/execute/around/App.java index 8603a12bc..910a024de 100644 --- a/execute-around/src/main/java/com/iluwatar/execute/around/App.java +++ b/execute-around/src/main/java/com/iluwatar/execute/around/App.java @@ -7,14 +7,19 @@ import java.io.IOException; * The Execute Around idiom specifies some code to be executed before and after * a method. Typically the idiom is used when the API has methods to be executed in * pairs, such as resource allocation/deallocation or lock acquisition/release. - * - * In this example, we have SimpleFileWriter class that opens and closes the file + * <p> + * In this example, we have {@link SimpleFileWriter} class that opens and closes the file * for the user. The user specifies only what to do with the file by providing the - * FileWriterAction implementation. + * {@link FileWriterAction} implementation. * */ public class App { + /** + * Program entry point + * @param args command line args + * @throws IOException + */ public static void main( String[] args ) throws IOException { new SimpleFileWriter("testfile.txt", new FileWriterAction() { diff --git a/execute-around/src/main/java/com/iluwatar/execute/around/SimpleFileWriter.java b/execute-around/src/main/java/com/iluwatar/execute/around/SimpleFileWriter.java index 2de1e5d67..a7ee11d15 100644 --- a/execute-around/src/main/java/com/iluwatar/execute/around/SimpleFileWriter.java +++ b/execute-around/src/main/java/com/iluwatar/execute/around/SimpleFileWriter.java @@ -6,7 +6,7 @@ import java.io.IOException; /** * * SimpleFileWriter handles opening and closing file for the user. The user - * only has to specify what to do with the file resource through FileWriterAction + * only has to specify what to do with the file resource through {@link FileWriterAction} * parameter. * */ diff --git a/facade/src/main/java/com/iluwatar/facade/App.java b/facade/src/main/java/com/iluwatar/facade/App.java index 09d5d1a0b..0d8eccd4b 100644 --- a/facade/src/main/java/com/iluwatar/facade/App.java +++ b/facade/src/main/java/com/iluwatar/facade/App.java @@ -1,17 +1,22 @@ -package com.iluwatar.facade; - -/** - * - * Facade (DwarvenGoldmineFacade) provides simpler interface to subsystem. - * http://en.wikipedia.org/wiki/Facade_pattern - * - */ -public class App { - - public static void main(String[] args) { - DwarvenGoldmineFacade facade = new DwarvenGoldmineFacade(); - facade.startNewDay(); - facade.digOutGold(); - facade.endDay(); - } -} +package com.iluwatar.facade; + +/** + * + * Facade ({@link DwarvenGoldmineFacade}) provides simpler interface to subsystem. + * <p> + * http://en.wikipedia.org/wiki/Facade_pattern + * + */ +public class App { + + /** + * Program entry point + * @param args command line args + */ + public static void main(String[] args) { + DwarvenGoldmineFacade facade = new DwarvenGoldmineFacade(); + facade.startNewDay(); + facade.digOutGold(); + facade.endDay(); + } +} diff --git a/facade/src/test/java/com/iluwatar/facade/AppTest.java b/facade/src/test/java/com/iluwatar/facade/AppTest.java index b32b16bb1..bfca5473a 100644 --- a/facade/src/test/java/com/iluwatar/facade/AppTest.java +++ b/facade/src/test/java/com/iluwatar/facade/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.facade; - -import org.junit.Test; - -import com.iluwatar.facade.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.facade; + +import org.junit.Test; + +import com.iluwatar.facade.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/factory-method/src/main/java/com/iluwatar/factory/method/App.java b/factory-method/src/main/java/com/iluwatar/factory/method/App.java index 41b234791..69bda3489 100644 --- a/factory-method/src/main/java/com/iluwatar/factory/method/App.java +++ b/factory-method/src/main/java/com/iluwatar/factory/method/App.java @@ -2,13 +2,18 @@ package com.iluwatar.factory.method; /** * - * In Factory Method we have an interface (Blacksmith) with a method for - * creating objects (manufactureWeapon). The concrete subclasses (OrcBlacksmith, - * ElfBlacksmith) then override the method to produce objects of their liking. + * In Factory Method we have an interface ({@link Blacksmith}) with a method for + * creating objects ({@link Blacksmith#manufactureWeapon}). The concrete subclasses + * ({@link OrcBlacksmith}, {@link ElfBlacksmith}) then override the method to produce + * objects of their liking. * */ public class App { + /** + * Program entry point + * @param args command line args + */ public static void main(String[] args) { Blacksmith blacksmith; Weapon weapon; diff --git a/factory-method/src/main/java/com/iluwatar/factory/method/ElfWeapon.java b/factory-method/src/main/java/com/iluwatar/factory/method/ElfWeapon.java index a425d3ce7..75bb8a9e0 100644 --- a/factory-method/src/main/java/com/iluwatar/factory/method/ElfWeapon.java +++ b/factory-method/src/main/java/com/iluwatar/factory/method/ElfWeapon.java @@ -1,5 +1,10 @@ package com.iluwatar.factory.method; +/** + * + * ElfWeapon + * + */ public class ElfWeapon implements Weapon { private WeaponType weaponType; diff --git a/factory-method/src/main/java/com/iluwatar/factory/method/OrcWeapon.java b/factory-method/src/main/java/com/iluwatar/factory/method/OrcWeapon.java index ab9b83991..85500799e 100644 --- a/factory-method/src/main/java/com/iluwatar/factory/method/OrcWeapon.java +++ b/factory-method/src/main/java/com/iluwatar/factory/method/OrcWeapon.java @@ -1,5 +1,10 @@ package com.iluwatar.factory.method; +/** + * + * OrcWeapon + * + */ public class OrcWeapon implements Weapon { private WeaponType weaponType; diff --git a/factory-method/src/main/java/com/iluwatar/factory/method/Weapon.java b/factory-method/src/main/java/com/iluwatar/factory/method/Weapon.java index 80e7c911f..a5ae99254 100644 --- a/factory-method/src/main/java/com/iluwatar/factory/method/Weapon.java +++ b/factory-method/src/main/java/com/iluwatar/factory/method/Weapon.java @@ -1,5 +1,10 @@ package com.iluwatar.factory.method; +/** + * + * Weapon interface + * + */ public interface Weapon { } diff --git a/factory-method/src/main/java/com/iluwatar/factory/method/WeaponType.java b/factory-method/src/main/java/com/iluwatar/factory/method/WeaponType.java index 9ef82fff6..1c0341670 100644 --- a/factory-method/src/main/java/com/iluwatar/factory/method/WeaponType.java +++ b/factory-method/src/main/java/com/iluwatar/factory/method/WeaponType.java @@ -1,5 +1,10 @@ package com.iluwatar.factory.method; +/** + * + * WeaponType enumeration + * + */ public enum WeaponType { SHORT_SWORD("short sword"), SPEAR("spear"), AXE("axe"), UNDEFINED(""); diff --git a/factory-method/src/test/java/com/iluwatar/factory/method/AppTest.java b/factory-method/src/test/java/com/iluwatar/factory/method/AppTest.java index 9fa0cc5eb..c6db18b3e 100644 --- a/factory-method/src/test/java/com/iluwatar/factory/method/AppTest.java +++ b/factory-method/src/test/java/com/iluwatar/factory/method/AppTest.java @@ -4,6 +4,11 @@ import org.junit.Test; import com.iluwatar.factory.method.App; +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/flux/src/main/java/com/iluwatar/flux/app/App.java b/flux/src/main/java/com/iluwatar/flux/app/App.java index d0c7763e7..a567a92d3 100644 --- a/flux/src/main/java/com/iluwatar/flux/app/App.java +++ b/flux/src/main/java/com/iluwatar/flux/app/App.java @@ -13,18 +13,23 @@ import com.iluwatar.flux.view.MenuView; * applications. Flux eschews MVC in favor of a unidirectional data flow. When a user interacts with * a React view, the view propagates an action through a central dispatcher, to the various stores that * hold the application's data and business logic, which updates all of the views that are affected. - * + * <p> * This example has two views: menu and content. They represent typical main menu and content area of * a web page. When menu item is clicked it triggers events through the dispatcher. The events are * received and handled by the stores updating their data as needed. The stores then notify the views * that they should rerender themselves. - * + * <p> * http://facebook.github.io/flux/docs/overview.html * */ public class App { + /** + * Program entry point + * @param args command line args + */ public static void main( String[] args ) { + // initialize and wire the system MenuStore menuStore = new MenuStore(); Dispatcher.getInstance().registerStore(menuStore); diff --git a/flux/src/test/java/com/iluwatar/flux/app/AppTest.java b/flux/src/test/java/com/iluwatar/flux/app/AppTest.java index 902e5872e..ba4b592a1 100644 --- a/flux/src/test/java/com/iluwatar/flux/app/AppTest.java +++ b/flux/src/test/java/com/iluwatar/flux/app/AppTest.java @@ -4,6 +4,11 @@ import org.junit.Test; import com.iluwatar.flux.app.App; +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/flyweight/src/main/java/com/iluwatar/flyweight/App.java b/flyweight/src/main/java/com/iluwatar/flyweight/App.java index 3aa41cf2c..c08ba78a3 100644 --- a/flyweight/src/main/java/com/iluwatar/flyweight/App.java +++ b/flyweight/src/main/java/com/iluwatar/flyweight/App.java @@ -4,18 +4,22 @@ package com.iluwatar.flyweight; * * Flyweight pattern is useful when the program needs a huge amount of objects. * It provides means to decrease resource usage by sharing object instances. - * - * In this example AlchemistShop has great amount of potions on its shelves. - * To fill the shelves AlchemistShop uses PotionFactory (which represents - * the Flyweight in this example). Internally PotionFactory holds a map + * <p> + * In this example {@link AlchemistShop} has great amount of potions on its shelves. + * To fill the shelves {@link AlchemistShop} uses {@link PotionFactory} (which represents + * the Flyweight in this example). Internally {@link PotionFactory} holds a map * of the potions and lazily creates new ones when requested. - * + * <p> * To enable safe sharing, between clients and threads, Flyweight objects must * be immutable. Flyweight objects are by definition value objects. * */ public class App { + /** + * Program entry point + * @param args command line args + */ public static void main(String[] args) { AlchemistShop alchemistShop = new AlchemistShop(); alchemistShop.enumerate(); diff --git a/flyweight/src/main/java/com/iluwatar/flyweight/HealingPotion.java b/flyweight/src/main/java/com/iluwatar/flyweight/HealingPotion.java index 397cca428..a5f8f4fb8 100644 --- a/flyweight/src/main/java/com/iluwatar/flyweight/HealingPotion.java +++ b/flyweight/src/main/java/com/iluwatar/flyweight/HealingPotion.java @@ -1,11 +1,16 @@ -package com.iluwatar.flyweight; - -public class HealingPotion implements Potion { - - @Override - public void drink() { - System.out.println("You feel healed. (Potion=" - + System.identityHashCode(this) + ")"); - } - -} +package com.iluwatar.flyweight; + +/** + * + * HealingPotion + * + */ +public class HealingPotion implements Potion { + + @Override + public void drink() { + System.out.println("You feel healed. (Potion=" + + System.identityHashCode(this) + ")"); + } + +} diff --git a/flyweight/src/main/java/com/iluwatar/flyweight/HolyWaterPotion.java b/flyweight/src/main/java/com/iluwatar/flyweight/HolyWaterPotion.java index df4c4009e..750e3c568 100644 --- a/flyweight/src/main/java/com/iluwatar/flyweight/HolyWaterPotion.java +++ b/flyweight/src/main/java/com/iluwatar/flyweight/HolyWaterPotion.java @@ -1,11 +1,16 @@ -package com.iluwatar.flyweight; - -public class HolyWaterPotion implements Potion { - - @Override - public void drink() { - System.out.println("You feel blessed. (Potion=" - + System.identityHashCode(this) + ")"); - } - -} +package com.iluwatar.flyweight; + +/** + * + * HolyWaterPotion + * + */ +public class HolyWaterPotion implements Potion { + + @Override + public void drink() { + System.out.println("You feel blessed. (Potion=" + + System.identityHashCode(this) + ")"); + } + +} diff --git a/flyweight/src/main/java/com/iluwatar/flyweight/InvisibilityPotion.java b/flyweight/src/main/java/com/iluwatar/flyweight/InvisibilityPotion.java index 2156b1017..db9d261d5 100644 --- a/flyweight/src/main/java/com/iluwatar/flyweight/InvisibilityPotion.java +++ b/flyweight/src/main/java/com/iluwatar/flyweight/InvisibilityPotion.java @@ -1,11 +1,16 @@ -package com.iluwatar.flyweight; - -public class InvisibilityPotion implements Potion { - - @Override - public void drink() { - System.out.println("You become invisible. (Potion=" - + System.identityHashCode(this) + ")"); - } - -} +package com.iluwatar.flyweight; + +/** + * + * InvisibilityPotion + * + */ +public class InvisibilityPotion implements Potion { + + @Override + public void drink() { + System.out.println("You become invisible. (Potion=" + + System.identityHashCode(this) + ")"); + } + +} diff --git a/flyweight/src/main/java/com/iluwatar/flyweight/PoisonPotion.java b/flyweight/src/main/java/com/iluwatar/flyweight/PoisonPotion.java index 2dcfab7d3..dfcd3c38d 100644 --- a/flyweight/src/main/java/com/iluwatar/flyweight/PoisonPotion.java +++ b/flyweight/src/main/java/com/iluwatar/flyweight/PoisonPotion.java @@ -1,11 +1,16 @@ -package com.iluwatar.flyweight; - -public class PoisonPotion implements Potion { - - @Override - public void drink() { - System.out.println("Urgh! This is poisonous. (Potion=" - + System.identityHashCode(this) + ")"); - } - -} +package com.iluwatar.flyweight; + +/** + * + * PoisonPotion + * + */ +public class PoisonPotion implements Potion { + + @Override + public void drink() { + System.out.println("Urgh! This is poisonous. (Potion=" + + System.identityHashCode(this) + ")"); + } + +} diff --git a/flyweight/src/main/java/com/iluwatar/flyweight/StrengthPotion.java b/flyweight/src/main/java/com/iluwatar/flyweight/StrengthPotion.java index a1ffcdc53..49083cf7c 100644 --- a/flyweight/src/main/java/com/iluwatar/flyweight/StrengthPotion.java +++ b/flyweight/src/main/java/com/iluwatar/flyweight/StrengthPotion.java @@ -1,10 +1,15 @@ -package com.iluwatar.flyweight; - -public class StrengthPotion implements Potion { - - @Override - public void drink() { - System.out.println("You feel strong. (Potion=" - + System.identityHashCode(this) + ")"); - } -} +package com.iluwatar.flyweight; + +/** + * + * StrengthPotion + * + */ +public class StrengthPotion implements Potion { + + @Override + public void drink() { + System.out.println("You feel strong. (Potion=" + + System.identityHashCode(this) + ")"); + } +} diff --git a/flyweight/src/test/java/com/iluwatar/flyweight/AppTest.java b/flyweight/src/test/java/com/iluwatar/flyweight/AppTest.java index 2c93d0e10..f3b033ba7 100644 --- a/flyweight/src/test/java/com/iluwatar/flyweight/AppTest.java +++ b/flyweight/src/test/java/com/iluwatar/flyweight/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.flyweight; - -import org.junit.Test; - -import com.iluwatar.flyweight.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.flyweight; + +import org.junit.Test; + +import com.iluwatar.flyweight.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/front-controller/src/main/java/com/iluwatar/front/controller/App.java b/front-controller/src/main/java/com/iluwatar/front/controller/App.java index d17987823..18a92d37d 100644 --- a/front-controller/src/main/java/com/iluwatar/front/controller/App.java +++ b/front-controller/src/main/java/com/iluwatar/front/controller/App.java @@ -4,22 +4,26 @@ package com.iluwatar.front.controller; * * The Front Controller is a presentation tier pattern. Essentially it defines a * controller that handles all requests for a web site. - * + * <p> * The Front Controller pattern consolidates request handling through a single handler - * object (FrontController). This object can carry out the common the behavior such as + * object ({@link FrontController}). This object can carry out the common the behavior such as * authorization, request logging and routing requests to corresponding views. - * - * Typically the requests are mapped to command objects (Command) which then display - * the correct view (View). - * - * In this example we have implemented two views: ArcherView and CatapultView. These - * are displayed by sending correct request to the FrontController object. For example, - * the ArcherView gets displayed when FrontController receives request "Archer". When - * the request is unknown, we display the error view (ErrorView). + * <p> + * Typically the requests are mapped to command objects ({@link Command}) which then display + * the correct view ({@link View}). + * <p> + * In this example we have implemented two views: {@link ArcherView} and {@link CatapultView}. These + * are displayed by sending correct request to the {@link FrontController} object. For example, + * the {@link ArcherView} gets displayed when {@link FrontController} receives request "Archer". When + * the request is unknown, we display the error view ({@link ErrorView}). * */ public class App { + /** + * Program entry point + * @param args command line args + */ public static void main(String[] args) { FrontController controller = new FrontController(); controller.handleRequest("Archer"); diff --git a/front-controller/src/main/java/com/iluwatar/front/controller/ApplicationException.java b/front-controller/src/main/java/com/iluwatar/front/controller/ApplicationException.java index 3a0191831..b3963d8e9 100644 --- a/front-controller/src/main/java/com/iluwatar/front/controller/ApplicationException.java +++ b/front-controller/src/main/java/com/iluwatar/front/controller/ApplicationException.java @@ -1,8 +1,15 @@ package com.iluwatar.front.controller; +/** + * + * Custom exception type + * + */ public class ApplicationException extends RuntimeException { - public ApplicationException(Throwable cause) { + private static final long serialVersionUID = 1L; + + public ApplicationException(Throwable cause) { super(cause); } } diff --git a/front-controller/src/test/java/com/iluwatar/front/controller/AppTest.java b/front-controller/src/test/java/com/iluwatar/front/controller/AppTest.java index 2c05cf9c4..2c28aa8ce 100644 --- a/front-controller/src/test/java/com/iluwatar/front/controller/AppTest.java +++ b/front-controller/src/test/java/com/iluwatar/front/controller/AppTest.java @@ -4,6 +4,11 @@ import org.junit.Test; import com.iluwatar.front.controller.App; +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/half-sync-half-async/src/main/java/com/iluwatar/halfsynchalfasync/App.java b/half-sync-half-async/src/main/java/com/iluwatar/halfsynchalfasync/App.java index 77b1988ba..b8cec89e3 100644 --- a/half-sync-half-async/src/main/java/com/iluwatar/halfsynchalfasync/App.java +++ b/half-sync-half-async/src/main/java/com/iluwatar/halfsynchalfasync/App.java @@ -3,6 +3,7 @@ package com.iluwatar.halfsynchalfasync; import java.util.concurrent.LinkedBlockingQueue; /** + * * This application demonstrates Half-Sync/Half-Async pattern. Key parts of the pattern are * {@link AsyncTask} and {@link AsynchronousService}. * @@ -44,9 +45,14 @@ import java.util.concurrent.LinkedBlockingQueue; * Such as Priority Queue can be used as queuing layer to prioritize the way tasks are executed. * Our implementation is just one simple way of implementing this pattern, there are many variants possible * as described in its applications. + * */ public class App { + /** + * Program entry point + * @param args command line args + */ public static void main(String[] args) { AsynchronousService service = new AsynchronousService(new LinkedBlockingQueue<>()); /* @@ -66,6 +72,11 @@ public class App { service.execute(new ArithmeticSumTask(1)); } + /** + * + * ArithmeticSumTask + * + */ static class ArithmeticSumTask implements AsyncTask<Long> { private long n; diff --git a/half-sync-half-async/src/test/java/com/iluwatar/halfsynchalfasync/AppTest.java b/half-sync-half-async/src/test/java/com/iluwatar/halfsynchalfasync/AppTest.java index 54f6ea5a7..a72417aff 100644 --- a/half-sync-half-async/src/test/java/com/iluwatar/halfsynchalfasync/AppTest.java +++ b/half-sync-half-async/src/test/java/com/iluwatar/halfsynchalfasync/AppTest.java @@ -4,6 +4,11 @@ import java.util.concurrent.ExecutionException; import org.junit.Test; +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/App.java b/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/App.java index b597396f5..7cdb17fb8 100644 --- a/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/App.java +++ b/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/App.java @@ -2,13 +2,17 @@ package com.iluwatar.intercepting.filter; /** * - * This is an app that checks whether the order request is valid through pre-processing done via Filters - * Each field has its own corresponding Filter + * This is an app that checks whether the order request is valid through pre-processing done via {@link Filter}. + * Each field has its own corresponding {@link Filter} * @author joshzambales * */ public class App{ + /** + * Program entry point + * @param args command line args + */ public static void main(String[] args) { FilterManager filterManager = new FilterManager(new Target()); filterManager.addFilter(new NameFilter()); diff --git a/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/Client.java b/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/Client.java index 6c94af5c5..0125d1b9d 100644 --- a/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/Client.java +++ b/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/Client.java @@ -15,9 +15,9 @@ import javax.swing.JTextField; import javax.swing.SwingUtilities; /** - * The Client class is responsible for handling the input and running them through filters inside the filterManager + * The Client class is responsible for handling the input and running them through filters inside the {@link FilterManager}. * - * This is where Filters come to play as the client pre-processes the request before being displayed in the Target + * This is where {@link Filter}s come to play as the client pre-processes the request before being displayed in the {@link Target}. * * @author joshzambales * diff --git a/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/Filter.java b/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/Filter.java index 0782fddab..a71be5154 100644 --- a/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/Filter.java +++ b/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/Filter.java @@ -1,7 +1,7 @@ package com.iluwatar.intercepting.filter; /** - * Filter interface Filters perform certain tasks prior or after execution of + * Filters perform certain tasks prior or after execution of * request by request handler. In this case, before the request is handled by * the target, the request undergoes through each Filter * diff --git a/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/FilterManager.java b/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/FilterManager.java index 65c822c8a..d15df424a 100644 --- a/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/FilterManager.java +++ b/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/FilterManager.java @@ -1,7 +1,7 @@ package com.iluwatar.intercepting.filter; /** - * Filter Manager manages the filters and Filter Chain. + * Filter Manager manages the filters and {@link FilterChain}. * * @author joshzambales * diff --git a/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/NameFilter.java b/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/NameFilter.java index c9da2600a..201c68bca 100644 --- a/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/NameFilter.java +++ b/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/NameFilter.java @@ -1,7 +1,7 @@ package com.iluwatar.intercepting.filter; /** - * Concrete implementation of filter This filter checks if the input in the Name + * Concrete implementation of filter. This filter checks if the input in the Name * field is valid. (alphanumeric) * * @author joshzambales diff --git a/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/OrderFilter.java b/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/OrderFilter.java index bc86289b4..cdeaec6e0 100644 --- a/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/OrderFilter.java +++ b/intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/OrderFilter.java @@ -1,7 +1,7 @@ package com.iluwatar.intercepting.filter; /** - * Concrete implementation of filter This checks for the order field + * Concrete implementation of filter. This checks for the order field. * * @author joshzambales * diff --git a/intercepting-filter/src/test/java/com/iluwatar/intercepting/filter/AppTest.java b/intercepting-filter/src/test/java/com/iluwatar/intercepting/filter/AppTest.java index b12bc8db9..9d31127a2 100644 --- a/intercepting-filter/src/test/java/com/iluwatar/intercepting/filter/AppTest.java +++ b/intercepting-filter/src/test/java/com/iluwatar/intercepting/filter/AppTest.java @@ -4,6 +4,11 @@ import org.junit.Test; import com.iluwatar.intercepting.filter.App; +/** + * + * Application test. + * + */ public class AppTest { @Test diff --git a/interpreter/src/main/java/com/iluwatar/interpreter/App.java b/interpreter/src/main/java/com/iluwatar/interpreter/App.java index 56924f6b0..2273b386b 100644 --- a/interpreter/src/main/java/com/iluwatar/interpreter/App.java +++ b/interpreter/src/main/java/com/iluwatar/interpreter/App.java @@ -1,68 +1,72 @@ -package com.iluwatar.interpreter; - -import java.util.Stack; - -/** - * - * Interpreter pattern breaks sentences into expressions (Expression) that can - * be evaluated and as a whole form the result. - * - */ -public class App { - - /** - * - * Expressions can be evaluated using prefix, infix or postfix notations - * This sample uses postfix, where operator comes after the operands - * - */ - public static void main(String[] args) { - String tokenString = "4 3 2 - 1 + *"; - Stack<Expression> stack = new Stack<>(); - - String[] tokenList = tokenString.split(" "); - for (String s : tokenList) { - if (isOperator(s)) { - Expression rightExpression = stack.pop(); - Expression leftExpression = stack.pop(); - System.out - .println(String.format( - "popped from stack left: %d right: %d", - leftExpression.interpret(), - rightExpression.interpret())); - Expression operator = getOperatorInstance(s, leftExpression, - rightExpression); - System.out.println(String.format("operator: %s", operator)); - int result = operator.interpret(); - NumberExpression resultExpression = new NumberExpression(result); - stack.push(resultExpression); - System.out.println(String.format("push result to stack: %d", - resultExpression.interpret())); - } else { - Expression i = new NumberExpression(s); - stack.push(i); - System.out.println(String.format("push to stack: %d", - i.interpret())); - } - } - System.out - .println(String.format("result: %d", stack.pop().interpret())); - } - - public static boolean isOperator(String s) { - return s.equals("+") || s.equals("-") || s.equals("*"); - } - - public static Expression getOperatorInstance(String s, Expression left, - Expression right) { - switch (s) { - case "+": - return new PlusExpression(left, right); - case "-": - return new MinusExpression(left, right); - case "*": - return new MultiplyExpression(left, right); - } - return null; - } -} +package com.iluwatar.interpreter; + +import java.util.Stack; + +/** + * + * Interpreter pattern breaks sentences into expressions ({@link Expression}) that can + * be evaluated and as a whole form the result. + * + */ +public class App { + + /** + * + * Program entry point. + * <p> + * Expressions can be evaluated using prefix, infix or postfix notations + * This sample uses postfix, where operator comes after the operands + * + * @param args command line args + * + */ + public static void main(String[] args) { + String tokenString = "4 3 2 - 1 + *"; + Stack<Expression> stack = new Stack<>(); + + String[] tokenList = tokenString.split(" "); + for (String s : tokenList) { + if (isOperator(s)) { + Expression rightExpression = stack.pop(); + Expression leftExpression = stack.pop(); + System.out + .println(String.format( + "popped from stack left: %d right: %d", + leftExpression.interpret(), + rightExpression.interpret())); + Expression operator = getOperatorInstance(s, leftExpression, + rightExpression); + System.out.println(String.format("operator: %s", operator)); + int result = operator.interpret(); + NumberExpression resultExpression = new NumberExpression(result); + stack.push(resultExpression); + System.out.println(String.format("push result to stack: %d", + resultExpression.interpret())); + } else { + Expression i = new NumberExpression(s); + stack.push(i); + System.out.println(String.format("push to stack: %d", + i.interpret())); + } + } + System.out + .println(String.format("result: %d", stack.pop().interpret())); + } + + public static boolean isOperator(String s) { + return s.equals("+") || s.equals("-") || s.equals("*"); + } + + public static Expression getOperatorInstance(String s, Expression left, + Expression right) { + switch (s) { + case "+": + return new PlusExpression(left, right); + case "-": + return new MinusExpression(left, right); + case "*": + return new MultiplyExpression(left, right); + } + return null; + } +} diff --git a/interpreter/src/main/java/com/iluwatar/interpreter/Expression.java b/interpreter/src/main/java/com/iluwatar/interpreter/Expression.java index 877e5db33..e70e57f7c 100644 --- a/interpreter/src/main/java/com/iluwatar/interpreter/Expression.java +++ b/interpreter/src/main/java/com/iluwatar/interpreter/Expression.java @@ -1,9 +1,14 @@ -package com.iluwatar.interpreter; - -public abstract class Expression { - - public abstract int interpret(); - - @Override - public abstract String toString(); -} +package com.iluwatar.interpreter; + +/** + * + * Expression + * + */ +public abstract class Expression { + + public abstract int interpret(); + + @Override + public abstract String toString(); +} diff --git a/interpreter/src/main/java/com/iluwatar/interpreter/MinusExpression.java b/interpreter/src/main/java/com/iluwatar/interpreter/MinusExpression.java index 03d088604..d26f977da 100644 --- a/interpreter/src/main/java/com/iluwatar/interpreter/MinusExpression.java +++ b/interpreter/src/main/java/com/iluwatar/interpreter/MinusExpression.java @@ -1,23 +1,28 @@ -package com.iluwatar.interpreter; - -public class MinusExpression extends Expression { - - private Expression leftExpression; - private Expression rightExpression; - - public MinusExpression(Expression leftExpression, Expression rightExpression) { - this.leftExpression = leftExpression; - this.rightExpression = rightExpression; - } - - @Override - public int interpret() { - return leftExpression.interpret() - rightExpression.interpret(); - } - - @Override - public String toString() { - return "-"; - } - -} +package com.iluwatar.interpreter; + +/** + * + * MinusExpression + * + */ +public class MinusExpression extends Expression { + + private Expression leftExpression; + private Expression rightExpression; + + public MinusExpression(Expression leftExpression, Expression rightExpression) { + this.leftExpression = leftExpression; + this.rightExpression = rightExpression; + } + + @Override + public int interpret() { + return leftExpression.interpret() - rightExpression.interpret(); + } + + @Override + public String toString() { + return "-"; + } + +} diff --git a/interpreter/src/main/java/com/iluwatar/interpreter/MultiplyExpression.java b/interpreter/src/main/java/com/iluwatar/interpreter/MultiplyExpression.java index fa30e4236..9feada7ee 100644 --- a/interpreter/src/main/java/com/iluwatar/interpreter/MultiplyExpression.java +++ b/interpreter/src/main/java/com/iluwatar/interpreter/MultiplyExpression.java @@ -1,24 +1,29 @@ -package com.iluwatar.interpreter; - -public class MultiplyExpression extends Expression { - - private Expression leftExpression; - private Expression rightExpression; - - public MultiplyExpression(Expression leftExpression, - Expression rightExpression) { - this.leftExpression = leftExpression; - this.rightExpression = rightExpression; - } - - @Override - public int interpret() { - return leftExpression.interpret() * rightExpression.interpret(); - } - - @Override - public String toString() { - return "*"; - } - -} +package com.iluwatar.interpreter; + +/** + * + * MultiplyExpression + * + */ +public class MultiplyExpression extends Expression { + + private Expression leftExpression; + private Expression rightExpression; + + public MultiplyExpression(Expression leftExpression, + Expression rightExpression) { + this.leftExpression = leftExpression; + this.rightExpression = rightExpression; + } + + @Override + public int interpret() { + return leftExpression.interpret() * rightExpression.interpret(); + } + + @Override + public String toString() { + return "*"; + } + +} diff --git a/interpreter/src/main/java/com/iluwatar/interpreter/NumberExpression.java b/interpreter/src/main/java/com/iluwatar/interpreter/NumberExpression.java index 041ddccae..0cf6b034a 100644 --- a/interpreter/src/main/java/com/iluwatar/interpreter/NumberExpression.java +++ b/interpreter/src/main/java/com/iluwatar/interpreter/NumberExpression.java @@ -1,25 +1,30 @@ -package com.iluwatar.interpreter; - -public class NumberExpression extends Expression { - - private int number; - - public NumberExpression(int number) { - this.number = number; - } - - public NumberExpression(String s) { - this.number = Integer.parseInt(s); - } - - @Override - public int interpret() { - return number; - } - - @Override - public String toString() { - return "number"; - } - -} +package com.iluwatar.interpreter; + +/** + * + * NumberExpression + * + */ +public class NumberExpression extends Expression { + + private int number; + + public NumberExpression(int number) { + this.number = number; + } + + public NumberExpression(String s) { + this.number = Integer.parseInt(s); + } + + @Override + public int interpret() { + return number; + } + + @Override + public String toString() { + return "number"; + } + +} diff --git a/interpreter/src/main/java/com/iluwatar/interpreter/PlusExpression.java b/interpreter/src/main/java/com/iluwatar/interpreter/PlusExpression.java index 843a66b62..f244fa946 100644 --- a/interpreter/src/main/java/com/iluwatar/interpreter/PlusExpression.java +++ b/interpreter/src/main/java/com/iluwatar/interpreter/PlusExpression.java @@ -1,23 +1,28 @@ -package com.iluwatar.interpreter; - -public class PlusExpression extends Expression { - - private Expression leftExpression; - private Expression rightExpression; - - public PlusExpression(Expression leftExpression, Expression rightExpression) { - this.leftExpression = leftExpression; - this.rightExpression = rightExpression; - } - - @Override - public int interpret() { - return leftExpression.interpret() + rightExpression.interpret(); - } - - @Override - public String toString() { - return "+"; - } - -} +package com.iluwatar.interpreter; + +/** + * + * PlusExpression + * + */ +public class PlusExpression extends Expression { + + private Expression leftExpression; + private Expression rightExpression; + + public PlusExpression(Expression leftExpression, Expression rightExpression) { + this.leftExpression = leftExpression; + this.rightExpression = rightExpression; + } + + @Override + public int interpret() { + return leftExpression.interpret() + rightExpression.interpret(); + } + + @Override + public String toString() { + return "+"; + } + +} diff --git a/interpreter/src/test/java/com/iluwatar/interpreter/AppTest.java b/interpreter/src/test/java/com/iluwatar/interpreter/AppTest.java index f89150159..b0e486833 100644 --- a/interpreter/src/test/java/com/iluwatar/interpreter/AppTest.java +++ b/interpreter/src/test/java/com/iluwatar/interpreter/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.interpreter; - -import org.junit.Test; - -import com.iluwatar.interpreter.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.interpreter; + +import org.junit.Test; + +import com.iluwatar.interpreter.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/iterator/src/main/java/com/iluwatar/iterator/App.java b/iterator/src/main/java/com/iluwatar/iterator/App.java index 22a6ea2d7..5b59cbcbc 100644 --- a/iterator/src/main/java/com/iluwatar/iterator/App.java +++ b/iterator/src/main/java/com/iluwatar/iterator/App.java @@ -1,41 +1,45 @@ -package com.iluwatar.iterator; - -/** - * - * Iterator (ItemIterator) adds abstraction layer on top of a collection - * (TreasureChest). This way the collection can change its internal - * implementation without affecting its clients. - * - */ -public class App { - - public static void main(String[] args) { - TreasureChest chest = new TreasureChest(); - - ItemIterator ringIterator = chest.Iterator(ItemType.RING); - while (ringIterator.hasNext()) { - System.out.println(ringIterator.next()); - } - - System.out.println("----------"); - - ItemIterator potionIterator = chest.Iterator(ItemType.POTION); - while (potionIterator.hasNext()) { - System.out.println(potionIterator.next()); - } - - System.out.println("----------"); - - ItemIterator weaponIterator = chest.Iterator(ItemType.WEAPON); - while (weaponIterator.hasNext()) { - System.out.println(weaponIterator.next()); - } - - System.out.println("----------"); - - ItemIterator it = chest.Iterator(ItemType.ANY); - while (it.hasNext()) { - System.out.println(it.next()); - } - } -} +package com.iluwatar.iterator; + +/** + * + * Iterator ({@link ItemIterator}) adds abstraction layer on top of a collection + * ({@link TreasureChest}). This way the collection can change its internal + * implementation without affecting its clients. + * + */ +public class App { + + /** + * Program entry point + * @param args command line args + */ + public static void main(String[] args) { + TreasureChest chest = new TreasureChest(); + + ItemIterator ringIterator = chest.Iterator(ItemType.RING); + while (ringIterator.hasNext()) { + System.out.println(ringIterator.next()); + } + + System.out.println("----------"); + + ItemIterator potionIterator = chest.Iterator(ItemType.POTION); + while (potionIterator.hasNext()) { + System.out.println(potionIterator.next()); + } + + System.out.println("----------"); + + ItemIterator weaponIterator = chest.Iterator(ItemType.WEAPON); + while (weaponIterator.hasNext()) { + System.out.println(weaponIterator.next()); + } + + System.out.println("----------"); + + ItemIterator it = chest.Iterator(ItemType.ANY); + while (it.hasNext()) { + System.out.println(it.next()); + } + } +} diff --git a/iterator/src/main/java/com/iluwatar/iterator/Item.java b/iterator/src/main/java/com/iluwatar/iterator/Item.java index c22eba96f..4df167c6f 100644 --- a/iterator/src/main/java/com/iluwatar/iterator/Item.java +++ b/iterator/src/main/java/com/iluwatar/iterator/Item.java @@ -1,25 +1,30 @@ -package com.iluwatar.iterator; - -public class Item { - - private ItemType type; - private String name; - - public Item(ItemType type, String name) { - this.setType(type); - this.name = name; - } - - @Override - public String toString() { - return name; - } - - public ItemType getType() { - return type; - } - - public void setType(ItemType type) { - this.type = type; - } -} +package com.iluwatar.iterator; + +/** + * + * Item + * + */ +public class Item { + + private ItemType type; + private String name; + + public Item(ItemType type, String name) { + this.setType(type); + this.name = name; + } + + @Override + public String toString() { + return name; + } + + public ItemType getType() { + return type; + } + + public void setType(ItemType type) { + this.type = type; + } +} diff --git a/iterator/src/main/java/com/iluwatar/iterator/ItemIterator.java b/iterator/src/main/java/com/iluwatar/iterator/ItemIterator.java index b18cd608e..91b5b62c0 100644 --- a/iterator/src/main/java/com/iluwatar/iterator/ItemIterator.java +++ b/iterator/src/main/java/com/iluwatar/iterator/ItemIterator.java @@ -1,13 +1,13 @@ -package com.iluwatar.iterator; - -/** - * - * Iterator interface. - * - */ -public interface ItemIterator { - - boolean hasNext(); - - Item next(); -} +package com.iluwatar.iterator; + +/** + * + * ItemIterator interface. + * + */ +public interface ItemIterator { + + boolean hasNext(); + + Item next(); +} diff --git a/iterator/src/main/java/com/iluwatar/iterator/ItemType.java b/iterator/src/main/java/com/iluwatar/iterator/ItemType.java index a3d4d3f54..288590c31 100644 --- a/iterator/src/main/java/com/iluwatar/iterator/ItemType.java +++ b/iterator/src/main/java/com/iluwatar/iterator/ItemType.java @@ -1,7 +1,12 @@ -package com.iluwatar.iterator; - -public enum ItemType { - - ANY, WEAPON, RING, POTION - -} +package com.iluwatar.iterator; + +/** + * + * ItemType enumeration + * + */ +public enum ItemType { + + ANY, WEAPON, RING, POTION + +} diff --git a/iterator/src/main/java/com/iluwatar/iterator/TreasureChest.java b/iterator/src/main/java/com/iluwatar/iterator/TreasureChest.java index e20269023..f4e1337bc 100644 --- a/iterator/src/main/java/com/iluwatar/iterator/TreasureChest.java +++ b/iterator/src/main/java/com/iluwatar/iterator/TreasureChest.java @@ -1,39 +1,39 @@ -package com.iluwatar.iterator; - -import java.util.ArrayList; -import java.util.List; - -/** - * - * Collection class. - * - */ -public class TreasureChest { - - private List<Item> items; - - public TreasureChest() { - items = new ArrayList<>(); - items.add(new Item(ItemType.POTION, "Potion of courage")); - items.add(new Item(ItemType.RING, "Ring of shadows")); - items.add(new Item(ItemType.POTION, "Potion of wisdom")); - items.add(new Item(ItemType.POTION, "Potion of blood")); - items.add(new Item(ItemType.WEAPON, "Sword of silver +1")); - items.add(new Item(ItemType.POTION, "Potion of rust")); - items.add(new Item(ItemType.POTION, "Potion of healing")); - items.add(new Item(ItemType.RING, "Ring of armor")); - items.add(new Item(ItemType.WEAPON, "Steel halberd")); - items.add(new Item(ItemType.WEAPON, "Dagger of poison")); - } - - ItemIterator Iterator(ItemType type) { - return new TreasureChestItemIterator(this, type); - } - - public List<Item> getItems() { - ArrayList<Item> list = new ArrayList<>(); - list.addAll(items); - return list; - } - -} +package com.iluwatar.iterator; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * TreasureChest, the collection class. + * + */ +public class TreasureChest { + + private List<Item> items; + + public TreasureChest() { + items = new ArrayList<>(); + items.add(new Item(ItemType.POTION, "Potion of courage")); + items.add(new Item(ItemType.RING, "Ring of shadows")); + items.add(new Item(ItemType.POTION, "Potion of wisdom")); + items.add(new Item(ItemType.POTION, "Potion of blood")); + items.add(new Item(ItemType.WEAPON, "Sword of silver +1")); + items.add(new Item(ItemType.POTION, "Potion of rust")); + items.add(new Item(ItemType.POTION, "Potion of healing")); + items.add(new Item(ItemType.RING, "Ring of armor")); + items.add(new Item(ItemType.WEAPON, "Steel halberd")); + items.add(new Item(ItemType.WEAPON, "Dagger of poison")); + } + + ItemIterator Iterator(ItemType type) { + return new TreasureChestItemIterator(this, type); + } + + public List<Item> getItems() { + ArrayList<Item> list = new ArrayList<>(); + list.addAll(items); + return list; + } + +} diff --git a/iterator/src/main/java/com/iluwatar/iterator/TreasureChestItemIterator.java b/iterator/src/main/java/com/iluwatar/iterator/TreasureChestItemIterator.java index fca50725d..1a6daef4e 100644 --- a/iterator/src/main/java/com/iluwatar/iterator/TreasureChestItemIterator.java +++ b/iterator/src/main/java/com/iluwatar/iterator/TreasureChestItemIterator.java @@ -1,49 +1,54 @@ -package com.iluwatar.iterator; - -import java.util.List; - -public class TreasureChestItemIterator implements ItemIterator { - - private TreasureChest chest; - private int idx; - private ItemType type; - - public TreasureChestItemIterator(TreasureChest chest, ItemType type) { - this.chest = chest; - this.type = type; - this.idx = -1; - } - - @Override - public boolean hasNext() { - return findNextIdx() != -1; - } - - @Override - public Item next() { - idx = findNextIdx(); - if (idx != -1) { - return chest.getItems().get(idx); - } - return null; - } - - private int findNextIdx() { - - List<Item> items = chest.getItems(); - boolean found = false; - int tempIdx = idx; - while (!found) { - tempIdx++; - if (tempIdx >= items.size()) { - tempIdx = -1; - break; - } - if (type.equals(ItemType.ANY) - || items.get(tempIdx).getType().equals(type)) { - break; - } - } - return tempIdx; - } -} +package com.iluwatar.iterator; + +import java.util.List; + +/** + * + * TreasureChestItemIterator + * + */ +public class TreasureChestItemIterator implements ItemIterator { + + private TreasureChest chest; + private int idx; + private ItemType type; + + public TreasureChestItemIterator(TreasureChest chest, ItemType type) { + this.chest = chest; + this.type = type; + this.idx = -1; + } + + @Override + public boolean hasNext() { + return findNextIdx() != -1; + } + + @Override + public Item next() { + idx = findNextIdx(); + if (idx != -1) { + return chest.getItems().get(idx); + } + return null; + } + + private int findNextIdx() { + + List<Item> items = chest.getItems(); + boolean found = false; + int tempIdx = idx; + while (!found) { + tempIdx++; + if (tempIdx >= items.size()) { + tempIdx = -1; + break; + } + if (type.equals(ItemType.ANY) + || items.get(tempIdx).getType().equals(type)) { + break; + } + } + return tempIdx; + } +} diff --git a/iterator/src/test/java/com/iluwatar/iterator/AppTest.java b/iterator/src/test/java/com/iluwatar/iterator/AppTest.java index ffdbb9ba1..1c1d65e34 100644 --- a/iterator/src/test/java/com/iluwatar/iterator/AppTest.java +++ b/iterator/src/test/java/com/iluwatar/iterator/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.iterator; - -import org.junit.Test; - -import com.iluwatar.iterator.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.iterator; + +import org.junit.Test; + +import com.iluwatar.iterator.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/layers/src/main/java/com/iluwatar/layers/App.java b/layers/src/main/java/com/iluwatar/layers/App.java index 3ab5e211e..bac946265 100644 --- a/layers/src/main/java/com/iluwatar/layers/App.java +++ b/layers/src/main/java/com/iluwatar/layers/App.java @@ -4,33 +4,22 @@ import java.util.Arrays; /** * - * <p> * Layers is an architectural style where software responsibilities are * divided among the different layers of the application. - * </p> - * * <p> * This example demonstrates a traditional 3-layer architecture consisting of data access * layer, business layer and presentation layer. - * </p> - * * <p> * The data access layer is formed of Spring Data repositories <code>CakeDao</code>, <code>CakeToppingDao</code> and * <code>CakeLayerDao</code>. The repositories can be used for CRUD operations on cakes, cake toppings * and cake layers respectively. - * </p> - * * <p> * The business layer is built on top of the data access layer. <code>CakeBakingService</code> offers * methods to retrieve available cake toppings and cake layers and baked cakes. Also the * service is used to create new cakes out of cake toppings and cake layers. - * </p> - * * <p> * The presentation layer is built on the business layer and in this example it simply lists * the cakes that have been baked. - * </p> - * * <p> * We have applied so called strict layering which means that the layers can only access * the classes directly beneath them. This leads the solution to create an additional set of @@ -41,7 +30,6 @@ import java.util.Arrays; * layer DTOs (<code>CakeInfo</code>, <code>CakeToppingInfo</code>, <code>CakeLayerInfo</code>) * and returns them instead. This way the presentation layer does not have any knowledge of * other layers than the business layer and thus is not affected by changes to them. - * </p> * * @see Cake * @see CakeTopping diff --git a/layers/src/test/java/com/iluwatar/layers/AppTest.java b/layers/src/test/java/com/iluwatar/layers/AppTest.java new file mode 100644 index 000000000..e55ab4f84 --- /dev/null +++ b/layers/src/test/java/com/iluwatar/layers/AppTest.java @@ -0,0 +1,19 @@ +package com.iluwatar.layers; + +import org.junit.Test; + +import com.iluwatar.layers.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/lazy-loading/src/main/java/com/iluwatar/lazy/loading/App.java b/lazy-loading/src/main/java/com/iluwatar/lazy/loading/App.java index f12d4e20c..db09c781b 100644 --- a/lazy-loading/src/main/java/com/iluwatar/lazy/loading/App.java +++ b/lazy-loading/src/main/java/com/iluwatar/lazy/loading/App.java @@ -3,16 +3,20 @@ package com.iluwatar.lazy.loading; /** * * Lazy loading idiom defers object creation until needed. - * + * <p> * This example shows different implementations of the pattern * with increasing sophistication. - * + * <p> * Additional information and lazy loading flavours are described in * http://martinfowler.com/eaaCatalog/lazyLoad.html * */ public class App { + /** + * Program entry point + * @param args command line args + */ public static void main( String[] args ) { // Simple lazy loader - not thread safe diff --git a/lazy-loading/src/main/java/com/iluwatar/lazy/loading/Java8Holder.java b/lazy-loading/src/main/java/com/iluwatar/lazy/loading/Java8Holder.java index 6bd2382c1..a03aae352 100644 --- a/lazy-loading/src/main/java/com/iluwatar/lazy/loading/Java8Holder.java +++ b/lazy-loading/src/main/java/com/iluwatar/lazy/loading/Java8Holder.java @@ -4,8 +4,8 @@ import java.util.function.Supplier; /** * - * This lazy loader is thread safe and more efficient than HolderThreadSafe. - * It utilizes Java 8 functional interface Supplier<T> as Heavy factory. + * This lazy loader is thread safe and more efficient than {@link HolderThreadSafe}. + * It utilizes Java 8 functional interface {@link Supplier<T>} as {@link Heavy} factory. * */ public class Java8Holder { diff --git a/lazy-loading/src/test/java/com/iluwatar/lazy/loading/AppTest.java b/lazy-loading/src/test/java/com/iluwatar/lazy/loading/AppTest.java index 96e88e75f..0ef7e8ae2 100644 --- a/lazy-loading/src/test/java/com/iluwatar/lazy/loading/AppTest.java +++ b/lazy-loading/src/test/java/com/iluwatar/lazy/loading/AppTest.java @@ -4,6 +4,11 @@ import org.junit.Test; import com.iluwatar.lazy.loading.App; +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/mediator/src/main/java/com/iluwatar/mediator/App.java b/mediator/src/main/java/com/iluwatar/mediator/App.java index 6c5233d26..a7df7d39f 100644 --- a/mediator/src/main/java/com/iluwatar/mediator/App.java +++ b/mediator/src/main/java/com/iluwatar/mediator/App.java @@ -1,33 +1,37 @@ -package com.iluwatar.mediator; - -/** - * - * Mediator encapsulates how a set of objects (PartyMember) interact. Instead of - * referring to each other directly they use a mediator (Party) interface. - * - */ -public class App { - - public static void main(String[] args) { - - // create party and members - Party party = new PartyImpl(); - Hobbit hobbit = new Hobbit(); - Wizard wizard = new Wizard(); - Rogue rogue = new Rogue(); - Hunter hunter = new Hunter(); - - // add party members - party.addMember(hobbit); - party.addMember(wizard); - party.addMember(rogue); - party.addMember(hunter); - - // perform actions -> the other party members - // are notified by the party - hobbit.act(Action.ENEMY); - wizard.act(Action.TALE); - rogue.act(Action.GOLD); - hunter.act(Action.HUNT); - } -} +package com.iluwatar.mediator; + +/** + * + * Mediator encapsulates how a set of objects ({@link PartyMember}) interact. Instead of + * referring to each other directly they use a mediator ({@link Party}) interface. + * + */ +public class App { + + /** + * Program entry point + * @param args command line args + */ + public static void main(String[] args) { + + // create party and members + Party party = new PartyImpl(); + Hobbit hobbit = new Hobbit(); + Wizard wizard = new Wizard(); + Rogue rogue = new Rogue(); + Hunter hunter = new Hunter(); + + // add party members + party.addMember(hobbit); + party.addMember(wizard); + party.addMember(rogue); + party.addMember(hunter); + + // perform actions -> the other party members + // are notified by the party + hobbit.act(Action.ENEMY); + wizard.act(Action.TALE); + rogue.act(Action.GOLD); + hunter.act(Action.HUNT); + } +} diff --git a/mediator/src/main/java/com/iluwatar/mediator/PartyMember.java b/mediator/src/main/java/com/iluwatar/mediator/PartyMember.java index 4dbfd450b..fffe6dd39 100644 --- a/mediator/src/main/java/com/iluwatar/mediator/PartyMember.java +++ b/mediator/src/main/java/com/iluwatar/mediator/PartyMember.java @@ -1,15 +1,15 @@ -package com.iluwatar.mediator; - -/** - * - * Interface for party members interacting with Party. - * - */ -public interface PartyMember { - - void joinedParty(Party party); - - void partyAction(Action action); - - void act(Action action); -} +package com.iluwatar.mediator; + +/** + * + * Interface for party members interacting with {@link Party}. + * + */ +public interface PartyMember { + + void joinedParty(Party party); + + void partyAction(Action action); + + void act(Action action); +} diff --git a/mediator/src/test/java/com/iluwatar/mediator/AppTest.java b/mediator/src/test/java/com/iluwatar/mediator/AppTest.java index 79bd9478d..2b614b003 100644 --- a/mediator/src/test/java/com/iluwatar/mediator/AppTest.java +++ b/mediator/src/test/java/com/iluwatar/mediator/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.mediator; - -import org.junit.Test; - -import com.iluwatar.mediator.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.mediator; + +import org.junit.Test; + +import com.iluwatar.mediator.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/memento/src/main/java/com/iluwatar/memento/App.java b/memento/src/main/java/com/iluwatar/memento/App.java index 9411cb4fd..623ffb00e 100644 --- a/memento/src/main/java/com/iluwatar/memento/App.java +++ b/memento/src/main/java/com/iluwatar/memento/App.java @@ -1,36 +1,36 @@ -package com.iluwatar.memento; - -import java.util.Stack; - -/** - * - * Memento pattern is for storing and restoring object state. The object (Star) - * gives out a "memento" (StarMemento) that contains the state of the object. - * Later on the memento can be set back to the object restoring the state. - * - */ -public class App { - - public static void main(String[] args) { - Stack<StarMemento> states = new Stack<>(); - - Star star = new Star(StarType.SUN, 10000000, 500000); - System.out.println(star); - states.add(star.getMemento()); - star.timePasses(); - System.out.println(star); - states.add(star.getMemento()); - star.timePasses(); - System.out.println(star); - states.add(star.getMemento()); - star.timePasses(); - System.out.println(star); - states.add(star.getMemento()); - star.timePasses(); - System.out.println(star); - while (states.size() > 0) { - star.setMemento(states.pop()); - System.out.println(star); - } - } -} +package com.iluwatar.memento; + +import java.util.Stack; + +/** + * + * Memento pattern is for storing and restoring object state. The object ({@link Star}) + * gives out a "memento" ({@link StarMemento}) that contains the state of the object. + * Later on the memento can be set back to the object restoring the state. + * + */ +public class App { + + public static void main(String[] args) { + Stack<StarMemento> states = new Stack<>(); + + Star star = new Star(StarType.SUN, 10000000, 500000); + System.out.println(star); + states.add(star.getMemento()); + star.timePasses(); + System.out.println(star); + states.add(star.getMemento()); + star.timePasses(); + System.out.println(star); + states.add(star.getMemento()); + star.timePasses(); + System.out.println(star); + states.add(star.getMemento()); + star.timePasses(); + System.out.println(star); + while (states.size() > 0) { + star.setMemento(states.pop()); + System.out.println(star); + } + } +} diff --git a/memento/src/main/java/com/iluwatar/memento/StarType.java b/memento/src/main/java/com/iluwatar/memento/StarType.java index 442025525..bae853097 100644 --- a/memento/src/main/java/com/iluwatar/memento/StarType.java +++ b/memento/src/main/java/com/iluwatar/memento/StarType.java @@ -1,17 +1,22 @@ -package com.iluwatar.memento; - -public enum StarType { - - SUN("sun"), RED_GIANT("red giant"), WHITE_DWARF("white dwarf"), SUPERNOVA("supernova"), DEAD("dead star"), UNDEFINED(""); - - private String title; - - StarType(String title) { - this.title = title; - } - - @Override - public String toString() { - return title; - } -} +package com.iluwatar.memento; + +/** + * + * StarType enumeration + * + */ +public enum StarType { + + SUN("sun"), RED_GIANT("red giant"), WHITE_DWARF("white dwarf"), SUPERNOVA("supernova"), DEAD("dead star"), UNDEFINED(""); + + private String title; + + StarType(String title) { + this.title = title; + } + + @Override + public String toString() { + return title; + } +} diff --git a/memento/src/test/java/com/iluwatar/memento/AppTest.java b/memento/src/test/java/com/iluwatar/memento/AppTest.java index 72bd5946d..84afd5945 100644 --- a/memento/src/test/java/com/iluwatar/memento/AppTest.java +++ b/memento/src/test/java/com/iluwatar/memento/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.memento; - -import org.junit.Test; - -import com.iluwatar.memento.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.memento; + +import org.junit.Test; + +import com.iluwatar.memento.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/model-view-controller/src/main/java/com/iluwatar/model/view/controller/App.java b/model-view-controller/src/main/java/com/iluwatar/model/view/controller/App.java index e3d61302e..0ba34b5d4 100644 --- a/model-view-controller/src/main/java/com/iluwatar/model/view/controller/App.java +++ b/model-view-controller/src/main/java/com/iluwatar/model/view/controller/App.java @@ -4,19 +4,23 @@ package com.iluwatar.model.view.controller; * * Model-View-Controller is a pattern for implementing user interfaces. It divides the application * into three interconnected parts namely the model, the view and the controller. - * + * <p> * The central component of MVC, the model, captures the behavior of the application in terms of its problem * domain, independent of the user interface. The model directly manages the data, logic and rules of the * application. A view can be any output representation of information, such as a chart or a diagram * The third part, the controller, accepts input and converts it to commands for the model or view. - * - * In this example we have a giant (GiantModel) with statuses for health, fatigue and nourishment. GiantView - * can display the giant with its current status. GiantController receives input affecting the model and + * <p> + * In this example we have a giant ({@link GiantModel}) with statuses for health, fatigue and nourishment. {@link GiantView} + * can display the giant with its current status. {@link GiantController} receives input affecting the model and * delegates redrawing the giant to the view. * */ public class App { + /** + * Program entry point + * @param args command line args + */ public static void main( String[] args ) { // create model, view and controller GiantModel giant = new GiantModel(Health.HEALTHY, Fatigue.ALERT, Nourishment.SATURATED); diff --git a/model-view-controller/src/test/java/com/iluwatar/model/view/controller/AppTest.java b/model-view-controller/src/test/java/com/iluwatar/model/view/controller/AppTest.java index b6e2f1bff..4bb31f6e6 100644 --- a/model-view-controller/src/test/java/com/iluwatar/model/view/controller/AppTest.java +++ b/model-view-controller/src/test/java/com/iluwatar/model/view/controller/AppTest.java @@ -4,6 +4,11 @@ import org.junit.Test; import com.iluwatar.model.view.controller.App; +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/MainApp.java b/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/App.java similarity index 65% rename from model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/MainApp.java rename to model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/App.java index 73da4f733..ac6ccf091 100644 --- a/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/MainApp.java +++ b/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/App.java @@ -4,19 +4,23 @@ package com.iluwatar.model.view.presenter; * * The Model-View-Presenter(MVP) architectural pattern, helps us achieve what is * called "The separation of concerns" principle. This is accomplished - * by separating the application's logic(Model), GUIs(View), and finally - * the way that the user's actions update the application's logic(Presenter). - * - * In the following example, The FileLoader class represents the app's logic, - * the FileSelectorJFrame is the GUI and the FileSelectorPresenter is + * by separating the application's logic (Model), GUIs (View), and finally + * the way that the user's actions update the application's logic (Presenter). + * <p> + * In the following example, The {@link FileLoader} class represents the app's logic, + * the {@link FileSelectorJFrame} is the GUI and the {@link FileSelectorPresenter} is * responsible to respond to users' actions. - * + * <p> * Finally, please notice the wiring between the Presenter and the View * and between the Presenter and the Model. * */ -public class MainApp { +public class App { + /** + * Program entry point + * @param args command line args + */ public static void main(String[] args) { FileLoader loader = new FileLoader(); FileSelectorJFrame jFrame = new FileSelectorJFrame(); diff --git a/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileLoader.java b/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileLoader.java index aef5bade9..96d843f83 100644 --- a/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileLoader.java +++ b/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileLoader.java @@ -7,7 +7,7 @@ import java.io.FileReader; /** * Every instance of this class represents the Model component in the * Model-View-Presenter architectural pattern. - * + * <p> * It is responsible for reading and loading the contents of a given file. */ public class FileLoader { @@ -51,9 +51,7 @@ public class FileLoader { /** * Sets the path of the file to be loaded, to the given value. - * - * @param fileName - * The path of the file to be loaded. + * @param fileName The path of the file to be loaded. */ public void setFileName(String fileName) { this.fileName = fileName; diff --git a/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorJFrame.java b/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorJFrame.java index be3c253ed..f4d24f59f 100644 --- a/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorJFrame.java +++ b/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorJFrame.java @@ -14,7 +14,7 @@ import javax.swing.JTextArea; import javax.swing.JTextField; /** - * This class is the GUI implementation of the View component In the + * This class is the GUI implementation of the View component in the * Model-View-Presenter pattern. */ public class FileSelectorJFrame extends JFrame implements FileSelectorView, diff --git a/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorPresenter.java b/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorPresenter.java index a7842e932..7119d60bf 100644 --- a/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorPresenter.java +++ b/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorPresenter.java @@ -3,7 +3,7 @@ package com.iluwatar.model.view.presenter; /** * Every instance of this class represents the Presenter component in the * Model-View-Presenter architectural pattern. - * + * <p> * It is responsible for reacting to the user's actions and update the View * component. */ @@ -21,19 +21,15 @@ public class FileSelectorPresenter { /** * Constructor - * - * @param view - * The view component that the presenter will interact with. + * @param view The view component that the presenter will interact with. */ public FileSelectorPresenter(FileSelectorView view) { this.view = view; } /** - * Sets the FileLoader object, to the value given as parameter. - * - * @param loader - * The new FileLoader object(the Model component). + * Sets the {@link FileLoader} object, to the value given as parameter. + * @param loader The new {@link FileLoader} object(the Model component). */ public void setLoader(FileLoader loader) { this.loader = loader; diff --git a/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorStub.java b/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorStub.java index 7aa88e922..d0cec4c40 100644 --- a/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorStub.java +++ b/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorStub.java @@ -3,10 +3,10 @@ package com.iluwatar.model.view.presenter; /** * Every instance of this class represents the Stub component in the * Model-View-Presenter architectural pattern. - * + * <p> * The stub implements the View interface and it is useful when we want the test * the reaction to user events, such as mouse clicks. - * + * <p> * Since we can not test the GUI directly, the MVP pattern provides this * functionality through the View's dummy implementation, the Stub. */ diff --git a/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorView.java b/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorView.java index e4a7efaee..8cd265f9b 100644 --- a/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorView.java +++ b/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorView.java @@ -23,9 +23,7 @@ public interface FileSelectorView { /** * Sets the presenter component, to the one given as parameter. - * - * @param presenter - * The new presenter component. + * @param presenter The new presenter component. */ public void setPresenter(FileSelectorPresenter presenter); @@ -36,9 +34,7 @@ public interface FileSelectorView { /** * Sets the file's name, to the value given as parameter. - * - * @param name - * The new name of the file. + * @param name The new name of the file. */ public void setFileName(String name); @@ -49,17 +45,13 @@ public interface FileSelectorView { /** * Displays a message to the users. - * - * @param message - * The message to be displayed. + * @param message The message to be displayed. */ public void showMessage(String message); /** * Displays the data to the view. - * - * @param data - * The data to be written. + * @param data The data to be written. */ public void displayData(String data); } diff --git a/multiton/src/main/java/com/iluwatar/multiton/App.java b/multiton/src/main/java/com/iluwatar/multiton/App.java index 7e3da2123..9f2c5da78 100644 --- a/multiton/src/main/java/com/iluwatar/multiton/App.java +++ b/multiton/src/main/java/com/iluwatar/multiton/App.java @@ -6,14 +6,18 @@ package com.iluwatar.multiton; * accessible object the Multiton pattern defines many globally * accessible objects. The client asks for the correct instance * from the Multiton by passing an enumeration as parameter. - * - * In this example Nazgul is the Multiton and we can ask single - * Nazgul from it using NazgulName. The Nazguls are statically + * <p> + * In this example {@link Nazgul} is the Multiton and we can ask single + * {@link Nazgul} from it using {@link NazgulName}. The {@link Nazgul}s are statically * initialized and stored in concurrent hash map. * */ public class App { + /** + * Program entry point + * @param args command line args + */ public static void main( String[] args ) { System.out.println("KHAMUL=" + Nazgul.getInstance(NazgulName.KHAMUL)); System.out.println("MURAZOR=" + Nazgul.getInstance(NazgulName.MURAZOR)); diff --git a/multiton/src/main/java/com/iluwatar/multiton/Nazgul.java b/multiton/src/main/java/com/iluwatar/multiton/Nazgul.java index a099f9322..833923f75 100644 --- a/multiton/src/main/java/com/iluwatar/multiton/Nazgul.java +++ b/multiton/src/main/java/com/iluwatar/multiton/Nazgul.java @@ -6,7 +6,7 @@ import java.util.concurrent.ConcurrentHashMap; /** * * Nazgul is a Multiton class. Nazgul instances can be queried - * using getInstance() method. + * using {@link #getInstance} method. * */ public class Nazgul { diff --git a/multiton/src/main/java/com/iluwatar/multiton/NazgulName.java b/multiton/src/main/java/com/iluwatar/multiton/NazgulName.java index f0db192a4..cef1e43a9 100644 --- a/multiton/src/main/java/com/iluwatar/multiton/NazgulName.java +++ b/multiton/src/main/java/com/iluwatar/multiton/NazgulName.java @@ -2,7 +2,7 @@ package com.iluwatar.multiton; /** * - * Each Nazgul has different NazgulName. + * Each Nazgul has different {@link NazgulName}. * */ public enum NazgulName { diff --git a/multiton/src/test/java/com/iluwatar/multiton/AppTest.java b/multiton/src/test/java/com/iluwatar/multiton/AppTest.java index 9f5f96792..439f08e24 100644 --- a/multiton/src/test/java/com/iluwatar/multiton/AppTest.java +++ b/multiton/src/test/java/com/iluwatar/multiton/AppTest.java @@ -4,6 +4,11 @@ import org.junit.Test; import com.iluwatar.multiton.App; +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/null-object/src/main/java/com/iluwatar/nullobject/App.java b/null-object/src/main/java/com/iluwatar/nullobject/App.java index 35b05061e..9cc4a14da 100644 --- a/null-object/src/main/java/com/iluwatar/nullobject/App.java +++ b/null-object/src/main/java/com/iluwatar/nullobject/App.java @@ -5,7 +5,7 @@ package com.iluwatar.nullobject; * Null Object pattern replaces null values with neutral objects. * Many times this simplifies algorithms since no extra null checks * are needed. - * + * <p> * In this example we build a binary tree where the nodes are either * normal or Null Objects. No null values are used in the tree making * the traversal easy. @@ -13,6 +13,10 @@ package com.iluwatar.nullobject; */ public class App { + /** + * Program entry point + * @param args command line args + */ public static void main( String[] args ) { Node root = new NodeImpl("1", diff --git a/null-object/src/main/java/com/iluwatar/nullobject/NullNode.java b/null-object/src/main/java/com/iluwatar/nullobject/NullNode.java index dfa6963d0..4a0f4cd2b 100644 --- a/null-object/src/main/java/com/iluwatar/nullobject/NullNode.java +++ b/null-object/src/main/java/com/iluwatar/nullobject/NullNode.java @@ -3,7 +3,7 @@ package com.iluwatar.nullobject; /** * * Null Object implementation for binary tree node. - * + * <p> * Implemented as Singleton, since all the NullNodes are the same. * */ diff --git a/null-object/src/test/java/com/iluwatar/nullobject/AppTest.java b/null-object/src/test/java/com/iluwatar/nullobject/AppTest.java index eb12f3c4d..7ddf2cabc 100644 --- a/null-object/src/test/java/com/iluwatar/nullobject/AppTest.java +++ b/null-object/src/test/java/com/iluwatar/nullobject/AppTest.java @@ -4,6 +4,11 @@ import org.junit.Test; import com.iluwatar.nullobject.App; +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/object-pool/src/main/java/com/iluwatar/object/pool/App.java b/object-pool/src/main/java/com/iluwatar/object/pool/App.java index d47bc51be..c1893a774 100644 --- a/object-pool/src/main/java/com/iluwatar/object/pool/App.java +++ b/object-pool/src/main/java/com/iluwatar/object/pool/App.java @@ -5,21 +5,25 @@ package com.iluwatar.object.pool; * When it is necessary to work with a large number of objects that are particularly expensive to instantiate * and each object is only needed for a short period of time, the performance of an entire application may be * adversely affected. An object pool design pattern may be deemed desirable in cases such as these. - * + * <p> * The object pool design pattern creates a set of objects that may be reused. When a new object is needed, it * is requested from the pool. If a previously prepared object is available it is returned immediately, avoiding * the instantiation cost. If no objects are present in the pool, a new item is created and returned. When the * object has been used and is no longer needed, it is returned to the pool, allowing it to be used again in the * future without repeating the computationally expensive instantiation process. It is important to note that * once an object has been used and returned, existing references will become invalid. - * - * In this example we have created OliphauntPool inheriting from generic ObjectPool. Oliphaunts can be checked + * <p> + * In this example we have created {@link OliphauntPool} inheriting from generic {@link ObjectPool}. {@link Oliphaunt}s can be checked * out from the pool and later returned to it. The pool tracks created instances and their status (available, * inUse). * */ public class App { + /** + * Program entry point + * @param args command line args + */ public static void main( String[] args ) { OliphauntPool pool = new OliphauntPool(); System.out.println(pool); diff --git a/object-pool/src/test/java/com/iluwatar/object/pool/AppTest.java b/object-pool/src/test/java/com/iluwatar/object/pool/AppTest.java index c856141db..4114590ec 100644 --- a/object-pool/src/test/java/com/iluwatar/object/pool/AppTest.java +++ b/object-pool/src/test/java/com/iluwatar/object/pool/AppTest.java @@ -4,6 +4,11 @@ import org.junit.Test; import com.iluwatar.object.pool.App; +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/observer/src/main/java/com/iluwatar/observer/App.java b/observer/src/main/java/com/iluwatar/observer/App.java index 9d97084c8..bd99da841 100644 --- a/observer/src/main/java/com/iluwatar/observer/App.java +++ b/observer/src/main/java/com/iluwatar/observer/App.java @@ -1,38 +1,41 @@ -package com.iluwatar.observer; - -import com.iluwatar.observer.generic.GHobbits; -import com.iluwatar.observer.generic.GOrcs; -import com.iluwatar.observer.generic.GWeather; - -/** - * - * Observer pattern defines one-to-many relationship between objects. The target - * object sends change notifications to its registered observers. - * - */ -public class App { - - public static void main(String[] args) { - - Weather weather = new Weather(); - weather.addObserver(new Orcs()); - weather.addObserver(new Hobbits()); - - weather.timePasses(); - weather.timePasses(); - weather.timePasses(); - weather.timePasses(); - - // Generic observer inspired by Java Generics and Collection by Naftalin & Wadler - System.out.println("\n--Running generic version--"); - GWeather gWeather = new GWeather(); - gWeather.addObserver(new GOrcs()); - gWeather.addObserver(new GHobbits()); - - gWeather.timePasses(); - gWeather.timePasses(); - gWeather.timePasses(); - gWeather.timePasses(); - - } -} +package com.iluwatar.observer; + +import com.iluwatar.observer.generic.GHobbits; +import com.iluwatar.observer.generic.GOrcs; +import com.iluwatar.observer.generic.GWeather; + +/** + * + * Observer pattern defines one-to-many relationship between objects. The target + * object sends change notifications to its registered observers. + * + */ +public class App { + + /** + * Program entry point + * @param args command line args + */ + public static void main(String[] args) { + + Weather weather = new Weather(); + weather.addObserver(new Orcs()); + weather.addObserver(new Hobbits()); + + weather.timePasses(); + weather.timePasses(); + weather.timePasses(); + weather.timePasses(); + + // Generic observer inspired by Java Generics and Collection by Naftalin & Wadler + System.out.println("\n--Running generic version--"); + GWeather gWeather = new GWeather(); + gWeather.addObserver(new GOrcs()); + gWeather.addObserver(new GHobbits()); + + gWeather.timePasses(); + gWeather.timePasses(); + gWeather.timePasses(); + gWeather.timePasses(); + } +} diff --git a/observer/src/main/java/com/iluwatar/observer/Hobbits.java b/observer/src/main/java/com/iluwatar/observer/Hobbits.java index b8a4f5b4f..d15ce6109 100644 --- a/observer/src/main/java/com/iluwatar/observer/Hobbits.java +++ b/observer/src/main/java/com/iluwatar/observer/Hobbits.java @@ -1,25 +1,30 @@ -package com.iluwatar.observer; - -public class Hobbits implements WeatherObserver { - - @Override - public void update(WeatherType currentWeather) { - switch (currentWeather) { - case COLD: - System.out.println("The hobbits are shivering in the cold weather."); - break; - case RAINY: - System.out.println("The hobbits look for cover from the rain."); - break; - case SUNNY: - System.out.println("The happy hobbits bade in the warm sun."); - break; - case WINDY: - System.out.println("The hobbits hold their hats tightly in the windy weather."); - break; - default: - break; - } - } - -} +package com.iluwatar.observer; + +/** + * + * Hobbits + * + */ +public class Hobbits implements WeatherObserver { + + @Override + public void update(WeatherType currentWeather) { + switch (currentWeather) { + case COLD: + System.out.println("The hobbits are shivering in the cold weather."); + break; + case RAINY: + System.out.println("The hobbits look for cover from the rain."); + break; + case SUNNY: + System.out.println("The happy hobbits bade in the warm sun."); + break; + case WINDY: + System.out.println("The hobbits hold their hats tightly in the windy weather."); + break; + default: + break; + } + } + +} diff --git a/observer/src/main/java/com/iluwatar/observer/Orcs.java b/observer/src/main/java/com/iluwatar/observer/Orcs.java index 0e51ab450..26049bf4b 100644 --- a/observer/src/main/java/com/iluwatar/observer/Orcs.java +++ b/observer/src/main/java/com/iluwatar/observer/Orcs.java @@ -1,25 +1,30 @@ -package com.iluwatar.observer; - -public class Orcs implements WeatherObserver { - - @Override - public void update(WeatherType currentWeather) { - switch (currentWeather) { - case COLD: - System.out.println("The orcs are freezing cold."); - break; - case RAINY: - System.out.println("The orcs are dripping wet."); - break; - case SUNNY: - System.out.println("The sun hurts the orcs' eyes."); - break; - case WINDY: - System.out.println("The orc smell almost vanishes in the wind."); - break; - default: - break; - } - } - -} +package com.iluwatar.observer; + +/** + * + * Orcs + * + */ +public class Orcs implements WeatherObserver { + + @Override + public void update(WeatherType currentWeather) { + switch (currentWeather) { + case COLD: + System.out.println("The orcs are freezing cold."); + break; + case RAINY: + System.out.println("The orcs are dripping wet."); + break; + case SUNNY: + System.out.println("The sun hurts the orcs' eyes."); + break; + case WINDY: + System.out.println("The orc smell almost vanishes in the wind."); + break; + default: + break; + } + } + +} diff --git a/observer/src/main/java/com/iluwatar/observer/Weather.java b/observer/src/main/java/com/iluwatar/observer/Weather.java index 32ff13d03..c5b03c7a3 100644 --- a/observer/src/main/java/com/iluwatar/observer/Weather.java +++ b/observer/src/main/java/com/iluwatar/observer/Weather.java @@ -1,42 +1,42 @@ -package com.iluwatar.observer; - -import java.util.ArrayList; -import java.util.List; - -/** - * - * Weather can be observed by implementing WeatherObserver interface and - * registering as listener. - * - */ -public class Weather { - - private WeatherType currentWeather; - private List<WeatherObserver> observers; - - public Weather() { - observers = new ArrayList<>(); - currentWeather = WeatherType.SUNNY; - } - - public void addObserver(WeatherObserver obs) { - observers.add(obs); - } - - public void removeObserver(WeatherObserver obs) { - observers.remove(obs); - } - - public void timePasses() { - WeatherType[] enumValues = WeatherType.values(); - currentWeather = enumValues[(currentWeather.ordinal() + 1) % enumValues.length]; - System.out.println("The weather changed to " + currentWeather + "."); - notifyObservers(); - } - - private void notifyObservers() { - for (WeatherObserver obs : observers) { - obs.update(currentWeather); - } - } -} +package com.iluwatar.observer; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * Weather can be observed by implementing {@link WeatherObserver} interface and + * registering as listener. + * + */ +public class Weather { + + private WeatherType currentWeather; + private List<WeatherObserver> observers; + + public Weather() { + observers = new ArrayList<>(); + currentWeather = WeatherType.SUNNY; + } + + public void addObserver(WeatherObserver obs) { + observers.add(obs); + } + + public void removeObserver(WeatherObserver obs) { + observers.remove(obs); + } + + public void timePasses() { + WeatherType[] enumValues = WeatherType.values(); + currentWeather = enumValues[(currentWeather.ordinal() + 1) % enumValues.length]; + System.out.println("The weather changed to " + currentWeather + "."); + notifyObservers(); + } + + private void notifyObservers() { + for (WeatherObserver obs : observers) { + obs.update(currentWeather); + } + } +} diff --git a/observer/src/main/java/com/iluwatar/observer/WeatherType.java b/observer/src/main/java/com/iluwatar/observer/WeatherType.java index b16c3cc04..173a53205 100644 --- a/observer/src/main/java/com/iluwatar/observer/WeatherType.java +++ b/observer/src/main/java/com/iluwatar/observer/WeatherType.java @@ -1,12 +1,17 @@ -package com.iluwatar.observer; - -public enum WeatherType { - - SUNNY, RAINY, WINDY, COLD; - - @Override - public String toString() { - return this.name().toLowerCase(); - } - -} +package com.iluwatar.observer; + +/** + * + * WeatherType enumeration + * + */ +public enum WeatherType { + + SUNNY, RAINY, WINDY, COLD; + + @Override + public String toString() { + return this.name().toLowerCase(); + } + +} diff --git a/observer/src/main/java/com/iluwatar/observer/generic/GHobbits.java b/observer/src/main/java/com/iluwatar/observer/generic/GHobbits.java index 78caefbcf..ec19d68e1 100644 --- a/observer/src/main/java/com/iluwatar/observer/generic/GHobbits.java +++ b/observer/src/main/java/com/iluwatar/observer/generic/GHobbits.java @@ -2,6 +2,11 @@ package com.iluwatar.observer.generic; import com.iluwatar.observer.WeatherType; +/** + * + * GHobbits + * + */ public class GHobbits implements Race { @Override public void update(GWeather weather, WeatherType weatherType) { diff --git a/observer/src/main/java/com/iluwatar/observer/generic/GOrcs.java b/observer/src/main/java/com/iluwatar/observer/generic/GOrcs.java index 97518ee10..037b88a1d 100644 --- a/observer/src/main/java/com/iluwatar/observer/generic/GOrcs.java +++ b/observer/src/main/java/com/iluwatar/observer/generic/GOrcs.java @@ -2,7 +2,13 @@ package com.iluwatar.observer.generic; import com.iluwatar.observer.WeatherType; +/** + * + * GOrcs + * + */ public class GOrcs implements Race { + @Override public void update(GWeather weather, WeatherType weatherType) { switch (weatherType) { diff --git a/observer/src/main/java/com/iluwatar/observer/generic/GWeather.java b/observer/src/main/java/com/iluwatar/observer/generic/GWeather.java index c4702542c..cea86bc82 100644 --- a/observer/src/main/java/com/iluwatar/observer/generic/GWeather.java +++ b/observer/src/main/java/com/iluwatar/observer/generic/GWeather.java @@ -2,6 +2,11 @@ package com.iluwatar.observer.generic; import com.iluwatar.observer.WeatherType; +/** + * + * GWeather + * + */ public class GWeather extends Observable<GWeather, Race, WeatherType> { private WeatherType currentWeather; diff --git a/observer/src/main/java/com/iluwatar/observer/generic/Observer.java b/observer/src/main/java/com/iluwatar/observer/generic/Observer.java index 901930de8..2338f9e98 100644 --- a/observer/src/main/java/com/iluwatar/observer/generic/Observer.java +++ b/observer/src/main/java/com/iluwatar/observer/generic/Observer.java @@ -1,5 +1,13 @@ package com.iluwatar.observer.generic; +/** + * + * Observer + * + * @param <S> + * @param <O> + * @param <A> + */ public interface Observer<S extends Observable<S, O, A>, O extends Observer<S, O, A>, A> { void update(S subject, A argument); diff --git a/observer/src/main/java/com/iluwatar/observer/generic/Race.java b/observer/src/main/java/com/iluwatar/observer/generic/Race.java index 358b27758..ddc3337cb 100644 --- a/observer/src/main/java/com/iluwatar/observer/generic/Race.java +++ b/observer/src/main/java/com/iluwatar/observer/generic/Race.java @@ -2,5 +2,10 @@ package com.iluwatar.observer.generic; import com.iluwatar.observer.WeatherType; +/** + * + * Race + * + */ public interface Race extends Observer<GWeather, Race, WeatherType> { } diff --git a/observer/src/test/java/com/iluwatar/observer/AppTest.java b/observer/src/test/java/com/iluwatar/observer/AppTest.java index 9e208ce66..38d5c0503 100644 --- a/observer/src/test/java/com/iluwatar/observer/AppTest.java +++ b/observer/src/test/java/com/iluwatar/observer/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.observer; - -import org.junit.Test; - -import com.iluwatar.observer.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.observer; + +import org.junit.Test; + +import com.iluwatar.observer.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/poison-pill/src/main/java/com/iluwatar/poison/pill/App.java b/poison-pill/src/main/java/com/iluwatar/poison/pill/App.java index 8f665b1e3..526ca5b86 100644 --- a/poison-pill/src/main/java/com/iluwatar/poison/pill/App.java +++ b/poison-pill/src/main/java/com/iluwatar/poison/pill/App.java @@ -1,16 +1,22 @@ package com.iluwatar.poison.pill; /** - * One of possible approaches to terminate Producer-Consumer pattern is using PoisonPill idiom. - * If you use PoisonPill as termination signal then Producer is responsible to notify Consumer that exchange is over - * and reject any further messages. Consumer receiving PoisonPill will stop to read messages from queue. - * You also must ensure that PoisonPill will be last message that will be read from queue (if you have - * prioritized queue than this can be tricky). - * In simple cases as PoisonPill can be used just null-reference, but holding unique separate shared - * object-marker (with name "Poison" or "PoisonPill") is more clear and self describing. + * One of the possible approaches to terminate Producer-Consumer pattern is using the Poison Pill idiom. + * If you use Poison Pill as the termination signal then Producer is responsible to notify Consumer that exchange is over + * and reject any further messages. Consumer receiving Poison Pill will stop reading messages from the queue. + * You must also ensure that the Poison Pill will be the last message that will be read from the queue (if you have + * prioritized queue then this can be tricky). + * <p> + * In simple cases as Poison Pill can be used just null-reference, but holding unique separate shared + * object-marker (with name "Poison" or "Poison Pill") is more clear and self describing. + * */ public class App { + /** + * Program entry point + * @param args command line args + */ public static void main(String[] args) { MessageQueue queue = new SimpleMessageQueue(10000); diff --git a/poison-pill/src/main/java/com/iluwatar/poison/pill/Message.java b/poison-pill/src/main/java/com/iluwatar/poison/pill/Message.java index f306e0385..8e167790f 100644 --- a/poison-pill/src/main/java/com/iluwatar/poison/pill/Message.java +++ b/poison-pill/src/main/java/com/iluwatar/poison/pill/Message.java @@ -3,7 +3,8 @@ package com.iluwatar.poison.pill; import java.util.Map; /** - * Interface that implements the Message pattern and represents an inbound or outbound message as part of an {@link Producer}-{@link Consumer} exchange. + * Interface that implements the Message pattern and represents an inbound or outbound + * message as part of an {@link Producer}-{@link Consumer} exchange. */ public interface Message { diff --git a/poison-pill/src/test/java/com/iluwatar/poison/pill/AppTest.java b/poison-pill/src/test/java/com/iluwatar/poison/pill/AppTest.java index 625d849a2..0730e5b10 100644 --- a/poison-pill/src/test/java/com/iluwatar/poison/pill/AppTest.java +++ b/poison-pill/src/test/java/com/iluwatar/poison/pill/AppTest.java @@ -4,6 +4,11 @@ import org.junit.Test; import com.iluwatar.poison.pill.App; +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/private-class-data/src/main/java/com/iluwatar/privateclassdata/App.java b/private-class-data/src/main/java/com/iluwatar/privateclassdata/App.java index 8cc5254d6..a4e2ffa87 100644 --- a/private-class-data/src/main/java/com/iluwatar/privateclassdata/App.java +++ b/private-class-data/src/main/java/com/iluwatar/privateclassdata/App.java @@ -1,34 +1,38 @@ -package com.iluwatar.privateclassdata; - -/** - * - * The Private Class Data design pattern seeks to reduce exposure of attributes - * by limiting their visibility. It reduces the number of class attributes by - * encapsulating them in single data object. It allows the class designer to - * remove write privilege of attributes that are intended to be set only during - * construction, even from methods of the target class. - * - * In the example we have normal Stew class with some ingredients given in - * constructor. Then we have methods to enumerate the ingredients and to taste - * the stew. The method for tasting the stew alters the private members of the - * stew class. - * - * The problem is solved with the Private Class Data pattern. We introduce - * ImmutableStew class that contains StewData. The private data members of - * Stew are now in StewData and cannot be altered by ImmutableStew methods. - * - */ -public class App { - - public static void main( String[] args ) { - // stew is mutable - Stew stew = new Stew(1, 2, 3, 4); - stew.mix(); - stew.taste(); - stew.mix(); - - // immutable stew protected with Private Class Data pattern - ImmutableStew immutableStew = new ImmutableStew(2, 4, 3, 6); - immutableStew.mix(); - } -} +package com.iluwatar.privateclassdata; + +/** + * + * The Private Class Data design pattern seeks to reduce exposure of attributes + * by limiting their visibility. It reduces the number of class attributes by + * encapsulating them in single data object. It allows the class designer to + * remove write privilege of attributes that are intended to be set only during + * construction, even from methods of the target class. + * <p> + * In the example we have normal {@link Stew} class with some ingredients given in + * constructor. Then we have methods to enumerate the ingredients and to taste + * the stew. The method for tasting the stew alters the private members of the + * {@link Stew} class. + * + * The problem is solved with the Private Class Data pattern. We introduce + * {@link ImmutableStew} class that contains {@link StewData}. The private data members of + * {@link Stew} are now in {@link StewData} and cannot be altered by {@link ImmutableStew} methods. + * + */ +public class App { + + /** + * Program entry point + * @param args command line args + */ + public static void main( String[] args ) { + // stew is mutable + Stew stew = new Stew(1, 2, 3, 4); + stew.mix(); + stew.taste(); + stew.mix(); + + // immutable stew protected with Private Class Data pattern + ImmutableStew immutableStew = new ImmutableStew(2, 4, 3, 6); + immutableStew.mix(); + } +} diff --git a/private-class-data/src/test/java/com/iluwatar/privateclassdata/AppTest.java b/private-class-data/src/test/java/com/iluwatar/privateclassdata/AppTest.java index 8ba8c4b80..92fc9b46a 100644 --- a/private-class-data/src/test/java/com/iluwatar/privateclassdata/AppTest.java +++ b/private-class-data/src/test/java/com/iluwatar/privateclassdata/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.privateclassdata; - -import org.junit.Test; - -import com.iluwatar.privateclassdata.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.privateclassdata; + +import org.junit.Test; + +import com.iluwatar.privateclassdata.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/property/src/main/java/com/iluwatar/property/App.java b/property/src/main/java/com/iluwatar/property/App.java index 40972ab59..54c140574 100644 --- a/property/src/main/java/com/iluwatar/property/App.java +++ b/property/src/main/java/com/iluwatar/property/App.java @@ -3,14 +3,21 @@ package com.iluwatar.property; import com.iluwatar.property.Character.Type; /** - * Example of Character instantiation using Property pattern (as concept also known like Prototype inheritance). + * + * Example of {@link Character} instantiation using the Property pattern (also known as Prototype inheritance). + * <p> * In prototype inheritance instead of classes, as opposite to Java class inheritance, - * objects are used to create another objects and object hierarchies. - * Hierarchies are created using prototype chain through delegation: every object has link to parent object. - * Any base (parent) object can be amended at runtime (by adding or removal of some property), and all child objects will be affected as result. + * objects are used to create another objects and object hierarchies. Hierarchies are created using prototype chain + * through delegation: every object has link to parent object. Any base (parent) object can be amended at runtime + * (by adding or removal of some property), and all child objects will be affected as result. + * */ public class App { + /** + * Program entry point + * @param args command line args + */ public static void main(String[] args) { /* set up */ Prototype charProto = new Character(); diff --git a/property/src/test/java/com/iluwatar/property/AppTest.java b/property/src/test/java/com/iluwatar/property/AppTest.java index dc05049f8..1e8078352 100644 --- a/property/src/test/java/com/iluwatar/property/AppTest.java +++ b/property/src/test/java/com/iluwatar/property/AppTest.java @@ -4,6 +4,11 @@ import org.junit.Test; import com.iluwatar.property.App; +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/prototype/src/main/java/com/iluwatar/prototype/App.java b/prototype/src/main/java/com/iluwatar/prototype/App.java index b10de963b..4003862cb 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/App.java +++ b/prototype/src/main/java/com/iluwatar/prototype/App.java @@ -1,36 +1,40 @@ -package com.iluwatar.prototype; - -/** - * - * In Prototype we have a factory class (HeroFactoryImpl) producing objects by - * cloning existing ones. In this example the factory's prototype objects are - * given as constructor parameters. - * - */ -public class App { - - public static void main(String[] args) { - HeroFactory factory; - Mage mage; - Warlord warlord; - Beast beast; - - factory = new HeroFactoryImpl(new ElfMage(), new ElfWarlord(), - new ElfBeast()); - mage = factory.createMage(); - warlord = factory.createWarlord(); - beast = factory.createBeast(); - System.out.println(mage); - System.out.println(warlord); - System.out.println(beast); - - factory = new HeroFactoryImpl(new OrcMage(), new OrcWarlord(), - new OrcBeast()); - mage = factory.createMage(); - warlord = factory.createWarlord(); - beast = factory.createBeast(); - System.out.println(mage); - System.out.println(warlord); - System.out.println(beast); - } -} +package com.iluwatar.prototype; + +/** + * + * In Prototype we have a factory class ({@link HeroFactoryImpl}) producing objects by + * cloning the existing ones. In this example the factory's prototype objects are + * given as constructor parameters. + * + */ +public class App { + + /** + * Program entry point + * @param args command line args + */ + public static void main(String[] args) { + HeroFactory factory; + Mage mage; + Warlord warlord; + Beast beast; + + factory = new HeroFactoryImpl(new ElfMage(), new ElfWarlord(), + new ElfBeast()); + mage = factory.createMage(); + warlord = factory.createWarlord(); + beast = factory.createBeast(); + System.out.println(mage); + System.out.println(warlord); + System.out.println(beast); + + factory = new HeroFactoryImpl(new OrcMage(), new OrcWarlord(), + new OrcBeast()); + mage = factory.createMage(); + warlord = factory.createWarlord(); + beast = factory.createBeast(); + System.out.println(mage); + System.out.println(warlord); + System.out.println(beast); + } +} diff --git a/prototype/src/main/java/com/iluwatar/prototype/Beast.java b/prototype/src/main/java/com/iluwatar/prototype/Beast.java index 96cbfb2c8..028fa11b8 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/Beast.java +++ b/prototype/src/main/java/com/iluwatar/prototype/Beast.java @@ -1,8 +1,13 @@ -package com.iluwatar.prototype; - -public abstract class Beast extends Prototype { - - @Override - public abstract Beast clone() throws CloneNotSupportedException; - -} +package com.iluwatar.prototype; + +/** + * + * Beast + * + */ +public abstract class Beast extends Prototype { + + @Override + public abstract Beast clone() throws CloneNotSupportedException; + +} diff --git a/prototype/src/main/java/com/iluwatar/prototype/ElfBeast.java b/prototype/src/main/java/com/iluwatar/prototype/ElfBeast.java index 17ac87511..b2b517207 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/ElfBeast.java +++ b/prototype/src/main/java/com/iluwatar/prototype/ElfBeast.java @@ -1,21 +1,26 @@ -package com.iluwatar.prototype; - -public class ElfBeast extends Beast { - - public ElfBeast() { - } - - public ElfBeast(ElfBeast beast) { - } - - @Override - public Beast clone() throws CloneNotSupportedException { - return new ElfBeast(this); - } - - @Override - public String toString() { - return "Elven eagle"; - } - -} +package com.iluwatar.prototype; + +/** + * + * ElfBeast + * + */ +public class ElfBeast extends Beast { + + public ElfBeast() { + } + + public ElfBeast(ElfBeast beast) { + } + + @Override + public Beast clone() throws CloneNotSupportedException { + return new ElfBeast(this); + } + + @Override + public String toString() { + return "Elven eagle"; + } + +} diff --git a/prototype/src/main/java/com/iluwatar/prototype/ElfMage.java b/prototype/src/main/java/com/iluwatar/prototype/ElfMage.java index c41ce2dd6..b502350c3 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/ElfMage.java +++ b/prototype/src/main/java/com/iluwatar/prototype/ElfMage.java @@ -1,21 +1,26 @@ -package com.iluwatar.prototype; - -public class ElfMage extends Mage { - - public ElfMage() { - } - - public ElfMage(ElfMage mage) { - } - - @Override - public Mage clone() throws CloneNotSupportedException { - return new ElfMage(this); - } - - @Override - public String toString() { - return "Elven mage"; - } - -} +package com.iluwatar.prototype; + +/** + * + * ElfMage + * + */ +public class ElfMage extends Mage { + + public ElfMage() { + } + + public ElfMage(ElfMage mage) { + } + + @Override + public Mage clone() throws CloneNotSupportedException { + return new ElfMage(this); + } + + @Override + public String toString() { + return "Elven mage"; + } + +} diff --git a/prototype/src/main/java/com/iluwatar/prototype/ElfWarlord.java b/prototype/src/main/java/com/iluwatar/prototype/ElfWarlord.java index 465c1d046..7f5829797 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/ElfWarlord.java +++ b/prototype/src/main/java/com/iluwatar/prototype/ElfWarlord.java @@ -1,21 +1,26 @@ -package com.iluwatar.prototype; - -public class ElfWarlord extends Warlord { - - public ElfWarlord() { - } - - public ElfWarlord(ElfWarlord warlord) { - } - - @Override - public Warlord clone() throws CloneNotSupportedException { - return new ElfWarlord(this); - } - - @Override - public String toString() { - return "Elven warlord"; - } - -} +package com.iluwatar.prototype; + +/** + * + * ElfWarlord + * + */ +public class ElfWarlord extends Warlord { + + public ElfWarlord() { + } + + public ElfWarlord(ElfWarlord warlord) { + } + + @Override + public Warlord clone() throws CloneNotSupportedException { + return new ElfWarlord(this); + } + + @Override + public String toString() { + return "Elven warlord"; + } + +} diff --git a/prototype/src/main/java/com/iluwatar/prototype/Mage.java b/prototype/src/main/java/com/iluwatar/prototype/Mage.java index 99cee8893..7ba192487 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/Mage.java +++ b/prototype/src/main/java/com/iluwatar/prototype/Mage.java @@ -1,8 +1,13 @@ -package com.iluwatar.prototype; - -public abstract class Mage extends Prototype { - - @Override - public abstract Mage clone() throws CloneNotSupportedException; - -} +package com.iluwatar.prototype; + +/** + * + * Mage + * + */ +public abstract class Mage extends Prototype { + + @Override + public abstract Mage clone() throws CloneNotSupportedException; + +} diff --git a/prototype/src/main/java/com/iluwatar/prototype/OrcBeast.java b/prototype/src/main/java/com/iluwatar/prototype/OrcBeast.java index bae7d360e..2af2fefa9 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/OrcBeast.java +++ b/prototype/src/main/java/com/iluwatar/prototype/OrcBeast.java @@ -1,21 +1,26 @@ -package com.iluwatar.prototype; - -public class OrcBeast extends Beast { - - public OrcBeast() { - } - - public OrcBeast(OrcBeast beast) { - } - - @Override - public Beast clone() throws CloneNotSupportedException { - return new OrcBeast(this); - } - - @Override - public String toString() { - return "Orcish wolf"; - } - -} +package com.iluwatar.prototype; + +/** + * + * OrcBeast + * + */ +public class OrcBeast extends Beast { + + public OrcBeast() { + } + + public OrcBeast(OrcBeast beast) { + } + + @Override + public Beast clone() throws CloneNotSupportedException { + return new OrcBeast(this); + } + + @Override + public String toString() { + return "Orcish wolf"; + } + +} diff --git a/prototype/src/main/java/com/iluwatar/prototype/OrcMage.java b/prototype/src/main/java/com/iluwatar/prototype/OrcMage.java index a329ca61b..1f52a25d9 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/OrcMage.java +++ b/prototype/src/main/java/com/iluwatar/prototype/OrcMage.java @@ -1,21 +1,26 @@ -package com.iluwatar.prototype; - -public class OrcMage extends Mage { - - public OrcMage() { - } - - public OrcMage(OrcMage mage) { - } - - @Override - public Mage clone() throws CloneNotSupportedException { - return new OrcMage(this); - } - - @Override - public String toString() { - return "Orcish mage"; - } - -} +package com.iluwatar.prototype; + +/** + * + * OrcMage + * + */ +public class OrcMage extends Mage { + + public OrcMage() { + } + + public OrcMage(OrcMage mage) { + } + + @Override + public Mage clone() throws CloneNotSupportedException { + return new OrcMage(this); + } + + @Override + public String toString() { + return "Orcish mage"; + } + +} diff --git a/prototype/src/main/java/com/iluwatar/prototype/OrcWarlord.java b/prototype/src/main/java/com/iluwatar/prototype/OrcWarlord.java index 2832c3835..53814d1c2 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/OrcWarlord.java +++ b/prototype/src/main/java/com/iluwatar/prototype/OrcWarlord.java @@ -1,21 +1,26 @@ -package com.iluwatar.prototype; - -public class OrcWarlord extends Warlord { - - public OrcWarlord() { - } - - public OrcWarlord(OrcWarlord warlord) { - } - - @Override - public Warlord clone() throws CloneNotSupportedException { - return new OrcWarlord(this); - } - - @Override - public String toString() { - return "Orcish warlord"; - } - -} +package com.iluwatar.prototype; + +/** + * + * OrcWarlord + * + */ +public class OrcWarlord extends Warlord { + + public OrcWarlord() { + } + + public OrcWarlord(OrcWarlord warlord) { + } + + @Override + public Warlord clone() throws CloneNotSupportedException { + return new OrcWarlord(this); + } + + @Override + public String toString() { + return "Orcish warlord"; + } + +} diff --git a/prototype/src/main/java/com/iluwatar/prototype/Prototype.java b/prototype/src/main/java/com/iluwatar/prototype/Prototype.java index 2329f1e6d..eb2520c35 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/Prototype.java +++ b/prototype/src/main/java/com/iluwatar/prototype/Prototype.java @@ -1,8 +1,13 @@ -package com.iluwatar.prototype; - -public abstract class Prototype implements Cloneable { - - @Override - public abstract Object clone() throws CloneNotSupportedException; - -} +package com.iluwatar.prototype; + +/** + * + * Prototype + * + */ +public abstract class Prototype implements Cloneable { + + @Override + public abstract Object clone() throws CloneNotSupportedException; + +} diff --git a/prototype/src/main/java/com/iluwatar/prototype/Warlord.java b/prototype/src/main/java/com/iluwatar/prototype/Warlord.java index 930320d97..bfd5c594a 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/Warlord.java +++ b/prototype/src/main/java/com/iluwatar/prototype/Warlord.java @@ -1,8 +1,13 @@ -package com.iluwatar.prototype; - -public abstract class Warlord extends Prototype { - - @Override - public abstract Warlord clone() throws CloneNotSupportedException; - -} +package com.iluwatar.prototype; + +/** + * + * Warlord + * + */ +public abstract class Warlord extends Prototype { + + @Override + public abstract Warlord clone() throws CloneNotSupportedException; + +} diff --git a/prototype/src/test/java/com/iluwatar/prototype/AppTest.java b/prototype/src/test/java/com/iluwatar/prototype/AppTest.java index ecb576038..030f5472c 100644 --- a/prototype/src/test/java/com/iluwatar/prototype/AppTest.java +++ b/prototype/src/test/java/com/iluwatar/prototype/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.prototype; - -import org.junit.Test; - -import com.iluwatar.prototype.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.prototype; + +import org.junit.Test; + +import com.iluwatar.prototype.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/proxy/src/main/java/com/iluwatar/proxy/App.java b/proxy/src/main/java/com/iluwatar/proxy/App.java index 86c96466b..fb401ac9f 100644 --- a/proxy/src/main/java/com/iluwatar/proxy/App.java +++ b/proxy/src/main/java/com/iluwatar/proxy/App.java @@ -1,20 +1,20 @@ -package com.iluwatar.proxy; - -/** - * - * Proxy (WizardTowerProxy) controls access to the actual object (WizardTower). - * - */ -public class App { - - public static void main(String[] args) { - - WizardTowerProxy tower = new WizardTowerProxy(); - tower.enter(new Wizard("Red wizard")); - tower.enter(new Wizard("White wizard")); - tower.enter(new Wizard("Black wizard")); - tower.enter(new Wizard("Green wizard")); - tower.enter(new Wizard("Brown wizard")); - - } -} +package com.iluwatar.proxy; + +/** + * + * Proxy ({@link WizardTowerProxy}) controls access to the actual object ({@link WizardTower}). + * + */ +public class App { + + public static void main(String[] args) { + + WizardTowerProxy tower = new WizardTowerProxy(); + tower.enter(new Wizard("Red wizard")); + tower.enter(new Wizard("White wizard")); + tower.enter(new Wizard("Black wizard")); + tower.enter(new Wizard("Green wizard")); + tower.enter(new Wizard("Brown wizard")); + + } +} diff --git a/proxy/src/main/java/com/iluwatar/proxy/Wizard.java b/proxy/src/main/java/com/iluwatar/proxy/Wizard.java index 2060a5803..b6d5691f4 100644 --- a/proxy/src/main/java/com/iluwatar/proxy/Wizard.java +++ b/proxy/src/main/java/com/iluwatar/proxy/Wizard.java @@ -1,16 +1,21 @@ -package com.iluwatar.proxy; - -public class Wizard { - - private String name; - - public Wizard(String name) { - this.name = name; - } - - @Override - public String toString() { - return name; - } - -} +package com.iluwatar.proxy; + +/** + * + * Wizard + * + */ +public class Wizard { + + private String name; + + public Wizard(String name) { + this.name = name; + } + + @Override + public String toString() { + return name; + } + +} diff --git a/proxy/src/main/java/com/iluwatar/proxy/WizardTowerProxy.java b/proxy/src/main/java/com/iluwatar/proxy/WizardTowerProxy.java index 3563aef1d..567a998d1 100644 --- a/proxy/src/main/java/com/iluwatar/proxy/WizardTowerProxy.java +++ b/proxy/src/main/java/com/iluwatar/proxy/WizardTowerProxy.java @@ -1,23 +1,23 @@ -package com.iluwatar.proxy; - -/** - * - * The proxy controlling access to WizardTower. - * - */ -public class WizardTowerProxy extends WizardTower { - - private static final int NUM_WIZARDS_ALLOWED = 3; - - private int numWizards; - - @Override - public void enter(Wizard wizard) { - if (numWizards < NUM_WIZARDS_ALLOWED) { - super.enter(wizard); - numWizards++; - } else { - System.out.println(wizard + " is not allowed to enter!"); - } - } -} +package com.iluwatar.proxy; + +/** + * + * The proxy controlling access to the {@link WizardTower}. + * + */ +public class WizardTowerProxy extends WizardTower { + + private static final int NUM_WIZARDS_ALLOWED = 3; + + private int numWizards; + + @Override + public void enter(Wizard wizard) { + if (numWizards < NUM_WIZARDS_ALLOWED) { + super.enter(wizard); + numWizards++; + } else { + System.out.println(wizard + " is not allowed to enter!"); + } + } +} diff --git a/proxy/src/test/java/com/iluwatar/proxy/AppTest.java b/proxy/src/test/java/com/iluwatar/proxy/AppTest.java index 0cd9641df..4d21b3d9a 100644 --- a/proxy/src/test/java/com/iluwatar/proxy/AppTest.java +++ b/proxy/src/test/java/com/iluwatar/proxy/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.proxy; - -import org.junit.Test; - -import com.iluwatar.proxy.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.proxy; + +import org.junit.Test; + +import com.iluwatar.proxy.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/repository/src/main/java/com/iluwatar/repository/App.java b/repository/src/main/java/com/iluwatar/repository/App.java index 3e4d46d00..37a5f7962 100644 --- a/repository/src/main/java/com/iluwatar/repository/App.java +++ b/repository/src/main/java/com/iluwatar/repository/App.java @@ -13,14 +13,18 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; * query construction code is concentrated. This becomes more important when there are a large * number of domain classes or heavy querying. In these cases particularly, adding this layer helps * minimize duplicate query logic. - * - * In this example we utilize Spring Data to automatically generate a repository for us from the Person - * domain object. Using the PersonDao we perform CRUD operations on the entity. Underneath we have + * <p> + * In this example we utilize Spring Data to automatically generate a repository for us from the {@link Person} + * domain object. Using the {@link PersonRepository} we perform CRUD operations on the entity. Underneath we have * configured in-memory H2 database for which schema is created and dropped on each run. * */ public class App { + /** + * Program entry point + * @param args command line args + */ public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "applicationContext.xml"); diff --git a/repository/src/test/java/com/iluwatar/repository/AppTest.java b/repository/src/test/java/com/iluwatar/repository/AppTest.java index 2e638ba6b..14f597045 100644 --- a/repository/src/test/java/com/iluwatar/repository/AppTest.java +++ b/repository/src/test/java/com/iluwatar/repository/AppTest.java @@ -4,6 +4,11 @@ import org.junit.Test; import com.iluwatar.repository.App; +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/resource-acquisition-is-initialization/src/main/java/com/iluwatar/resource/acquisition/is/initialization/App.java b/resource-acquisition-is-initialization/src/main/java/com/iluwatar/resource/acquisition/is/initialization/App.java index b947d31d0..141aea4ec 100644 --- a/resource-acquisition-is-initialization/src/main/java/com/iluwatar/resource/acquisition/is/initialization/App.java +++ b/resource-acquisition-is-initialization/src/main/java/com/iluwatar/resource/acquisition/is/initialization/App.java @@ -5,27 +5,32 @@ package com.iluwatar.resource.acquisition.is.initialization; * Resource Acquisition Is Initialization pattern was developed * for exception safe resource management by C++ creator Bjarne * Stroustrup. - * + * <p> * In RAII resource is tied to object lifetime: resource allocation * is done during object creation while resource deallocation is * done during object destruction. - * + * <p> * In Java RAII is achieved with try-with-resources statement and - * interfaces Closeable and AutoCloseable. The try-with-resources + * interfaces {@link Closeable} and {@link AutoCloseable}. The try-with-resources * statement ensures that each resource is closed at the end of the - * statement. Any object that implements java.lang.AutoCloseable, which - * includes all objects which implement java.io.Closeable, can be used + * statement. Any object that implements {@link java.lang.AutoCloseable}, which + * includes all objects which implement {@link java.io.Closeable}, can be used * as a resource. * - * In this example, SlidingDoor implements AutoCloseable and - * TreasureChest implements Closeable. Running the example, we can + * In this example, {@link SlidingDoor} implements {@link AutoCloseable} and + * {@link TreasureChest} implements {@link Closeable}. Running the example, we can * observe that both resources are automatically closed. - * + * <p> * http://docs.oracle.com/javase/7/docs/technotes/guides/language/try-with-resources.html * */ public class App { + /** + * Program entry point + * @param args command line args + * @throws Exception + */ public static void main( String[] args ) throws Exception { try (SlidingDoor slidingDoor = new SlidingDoor()) { diff --git a/resource-acquisition-is-initialization/src/test/java/com/iluwatar/resource/acquisition/is/initialization/AppTest.java b/resource-acquisition-is-initialization/src/test/java/com/iluwatar/resource/acquisition/is/initialization/AppTest.java index 097ea4711..e20815c3f 100644 --- a/resource-acquisition-is-initialization/src/test/java/com/iluwatar/resource/acquisition/is/initialization/AppTest.java +++ b/resource-acquisition-is-initialization/src/test/java/com/iluwatar/resource/acquisition/is/initialization/AppTest.java @@ -4,6 +4,11 @@ import org.junit.Test; import com.iluwatar.resource.acquisition.is.initialization.App; +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/servant/src/main/java/com/iluwatar/servant/App.java b/servant/src/main/java/com/iluwatar/servant/App.java index 4951c7270..6a0ba6ca4 100644 --- a/servant/src/main/java/com/iluwatar/servant/App.java +++ b/servant/src/main/java/com/iluwatar/servant/App.java @@ -10,9 +10,14 @@ import java.util.ArrayList; * */ public class App { + static Servant jenkins = new Servant("Jenkins"); static Servant travis = new Servant("Travis"); + /** + * Program entry point + * @param args + */ public static void main(String[] args) { scenario(jenkins, 1); scenario(travis, 0); diff --git a/servant/src/main/java/com/iluwatar/servant/King.java b/servant/src/main/java/com/iluwatar/servant/King.java index 24aa1b870..29ec88192 100644 --- a/servant/src/main/java/com/iluwatar/servant/King.java +++ b/servant/src/main/java/com/iluwatar/servant/King.java @@ -1,6 +1,12 @@ package com.iluwatar.servant; +/** + * + * King + * + */ public class King implements Royalty { + private boolean isDrunk; private boolean isHungry = true; private boolean isHappy; diff --git a/servant/src/main/java/com/iluwatar/servant/Queen.java b/servant/src/main/java/com/iluwatar/servant/Queen.java index c581132de..815106725 100644 --- a/servant/src/main/java/com/iluwatar/servant/Queen.java +++ b/servant/src/main/java/com/iluwatar/servant/Queen.java @@ -1,6 +1,12 @@ package com.iluwatar.servant; +/** + * + * Queen + * + */ public class Queen implements Royalty { + private boolean isDrunk = true; private boolean isHungry; private boolean isHappy; diff --git a/servant/src/main/java/com/iluwatar/servant/Royalty.java b/servant/src/main/java/com/iluwatar/servant/Royalty.java index 02ebe3cce..543ffd8d5 100644 --- a/servant/src/main/java/com/iluwatar/servant/Royalty.java +++ b/servant/src/main/java/com/iluwatar/servant/Royalty.java @@ -1,5 +1,10 @@ package com.iluwatar.servant; +/** + * + * Royalty + * + */ interface Royalty { void getFed(); diff --git a/servant/src/main/java/com/iluwatar/servant/Servant.java b/servant/src/main/java/com/iluwatar/servant/Servant.java index b29e7fe20..8e61333d8 100644 --- a/servant/src/main/java/com/iluwatar/servant/Servant.java +++ b/servant/src/main/java/com/iluwatar/servant/Servant.java @@ -2,7 +2,13 @@ package com.iluwatar.servant; import java.util.ArrayList; +/** + * + * Servant + * + */ public class Servant { + public String name; public Servant(String name){ diff --git a/servant/src/test/java/com/iluwatar/servant/AppTest.java b/servant/src/test/java/com/iluwatar/servant/AppTest.java index bf6655f2a..94a12b207 100644 --- a/servant/src/test/java/com/iluwatar/servant/AppTest.java +++ b/servant/src/test/java/com/iluwatar/servant/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.servant; - -import org.junit.Test; - -import com.iluwatar.servant.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.servant; + +import org.junit.Test; + +import com.iluwatar.servant.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/service-layer/src/main/java/com/iluwatar/servicelayer/app/App.java b/service-layer/src/main/java/com/iluwatar/servicelayer/app/App.java index ea0419606..2d91b43d9 100644 --- a/service-layer/src/main/java/com/iluwatar/servicelayer/app/App.java +++ b/service-layer/src/main/java/com/iluwatar/servicelayer/app/App.java @@ -18,7 +18,7 @@ import com.iluwatar.servicelayer.wizard.WizardDaoImpl; /** * Service layer defines an application's boundary with a layer of services that establishes * a set of available operations and coordinates the application's response in each operation. - * + * <p> * Enterprise applications typically require different kinds of interfaces to the data * they store and the logic they implement: data loaders, user interfaces, integration gateways, * and others. Despite their different purposes, these interfaces often need common interactions @@ -26,15 +26,19 @@ import com.iluwatar.servicelayer.wizard.WizardDaoImpl; * interactions may be complex, involving transactions across multiple resources and the * coordination of several responses to an action. Encoding the logic of the interactions * separately in each interface causes a lot of duplication. - * - * The example application demonstrates interactions between a client (App) and a service - * (MagicService). The service is implemented with 3-layer architecture (entity, dao, service). + * <p> + * The example application demonstrates interactions between a client ({@link App}) and a service + * ({@link MagicService}). The service is implemented with 3-layer architecture (entity, dao, service). * For persistence the example uses in-memory H2 database which is populated on each application * startup. * */ public class App { + /** + * Program entry point + * @param args command line args + */ public static void main( String[] args ) { // populate the in-memory database initData(); diff --git a/service-layer/src/main/java/com/iluwatar/servicelayer/hibernate/HibernateUtil.java b/service-layer/src/main/java/com/iluwatar/servicelayer/hibernate/HibernateUtil.java index 922fe9f21..70d586c08 100644 --- a/service-layer/src/main/java/com/iluwatar/servicelayer/hibernate/HibernateUtil.java +++ b/service-layer/src/main/java/com/iluwatar/servicelayer/hibernate/HibernateUtil.java @@ -9,7 +9,7 @@ import com.iluwatar.servicelayer.wizard.Wizard; /** * - * Produces the Hibernate SessionFactory. + * Produces the Hibernate {@link SessionFactory}. * */ public class HibernateUtil { diff --git a/service-layer/src/test/java/com/iluwatar/servicelayer/app/AppTest.java b/service-layer/src/test/java/com/iluwatar/servicelayer/app/AppTest.java index aabeb1a6c..bbf476c0b 100644 --- a/service-layer/src/test/java/com/iluwatar/servicelayer/app/AppTest.java +++ b/service-layer/src/test/java/com/iluwatar/servicelayer/app/AppTest.java @@ -4,6 +4,11 @@ import org.junit.Test; import com.iluwatar.servicelayer.app.App; +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/service-locator/src/main/java/com/iluwatar/servicelocator/App.java b/service-locator/src/main/java/com/iluwatar/servicelocator/App.java index 57f188731..f86e1cc32 100644 --- a/service-locator/src/main/java/com/iluwatar/servicelocator/App.java +++ b/service-locator/src/main/java/com/iluwatar/servicelocator/App.java @@ -1,12 +1,18 @@ package com.iluwatar.servicelocator; /** - * Service locator pattern, used to lookup jndi services + * Service locator pattern, used to lookup JNDI-services * and cache them for subsequent requests. * * @author saifasif + * */ public class App { + + /** + * Program entry point + * @param args command line args + */ public static void main(String[] args) { Service service = ServiceLocator.getService("jndi/serviceA"); service.execute(); diff --git a/service-locator/src/main/java/com/iluwatar/servicelocator/Service.java b/service-locator/src/main/java/com/iluwatar/servicelocator/Service.java index dbb268159..4831add95 100644 --- a/service-locator/src/main/java/com/iluwatar/servicelocator/Service.java +++ b/service-locator/src/main/java/com/iluwatar/servicelocator/Service.java @@ -6,6 +6,7 @@ package com.iluwatar.servicelocator; * <li>service name</li> * <li>unique id</li> * <li>execution work flow</li> + * * @author saifasif * */ diff --git a/service-locator/src/test/java/com/iluwatar/servicelocator/AppTest.java b/service-locator/src/test/java/com/iluwatar/servicelocator/AppTest.java index d6af23f2d..90e091905 100644 --- a/service-locator/src/test/java/com/iluwatar/servicelocator/AppTest.java +++ b/service-locator/src/test/java/com/iluwatar/servicelocator/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.servicelocator; - -import org.junit.Test; - -import com.iluwatar.servicelocator.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.servicelocator; + +import org.junit.Test; + +import com.iluwatar.servicelocator.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/singleton/src/main/java/com/iluwatar/singleton/App.java b/singleton/src/main/java/com/iluwatar/singleton/App.java index d14088ca2..67cb6fd00 100644 --- a/singleton/src/main/java/com/iluwatar/singleton/App.java +++ b/singleton/src/main/java/com/iluwatar/singleton/App.java @@ -1,51 +1,55 @@ -package com.iluwatar.singleton; - -/** - * - * Singleton pattern ensures that the class (IvoryTower) can have only one - * existing instance per java classloader instance and provides global access to it. - * - * http://stackoverflow.com/questions/70689/what-is-an-efficient-way-to-implement-a-singleton-pattern-in-java - * - * The risk of this pattern is that bugs resulting from setting a singleton up in a distributed environment can - * be tricky to debug, since it will work fine if you debug with a single classloader. Additionally, these - * problems can crop up a while after the implementation of a singleton, since they may start out synchronous and - * only become async with time, so you it may not be clear why you are seeing certain changes in behaviour. - * - * http://stackoverflow.com/questions/17721263/singleton-across-jvm-or-application-instance-or-tomcat-instance - */ -public class App { - - public static void main(String[] args) { - - // eagerly initialized singleton - IvoryTower ivoryTower1 = IvoryTower.getInstance(); - IvoryTower ivoryTower2 = IvoryTower.getInstance(); - System.out.println("ivoryTower1=" + ivoryTower1); - System.out.println("ivoryTower2=" + ivoryTower2); - - // lazily initialized singleton - ThreadSafeLazyLoadedIvoryTower threadSafeIvoryTower1 = ThreadSafeLazyLoadedIvoryTower - .getInstance(); - ThreadSafeLazyLoadedIvoryTower threadSafeIvoryTower2 = ThreadSafeLazyLoadedIvoryTower - .getInstance(); - System.out.println("threadSafeIvoryTower1=" + threadSafeIvoryTower1); - System.out.println("threadSafeIvoryTower2=" + threadSafeIvoryTower2); - - // enum singleton - EnumIvoryTower enumIvoryTower1 = EnumIvoryTower.INSTANCE; - EnumIvoryTower enumIvoryTower2 = EnumIvoryTower.INSTANCE; - System.out.println("enumIvoryTower1=" + enumIvoryTower1); - System.out.println("enumIvoryTower2=" + enumIvoryTower2); - - InitializingOnDemandHolderIdiom demandHolderIdiom = InitializingOnDemandHolderIdiom.getInstance(); - System.out.println(demandHolderIdiom); - InitializingOnDemandHolderIdiom demandHolderIdiom2 = InitializingOnDemandHolderIdiom.getInstance(); - System.out.println(demandHolderIdiom2); - - ThreadSafeDoubleCheckLocking dcl1 = ThreadSafeDoubleCheckLocking.getInstance(); - System.out.println(dcl1); - ThreadSafeDoubleCheckLocking dcl2 = ThreadSafeDoubleCheckLocking.getInstance(); - System.out.println(dcl2); - } -} +package com.iluwatar.singleton; + +/** + * + * Singleton pattern ensures that the class ({@link IvoryTower}) can have only one + * existing instance per Java classloader instance and provides global access to it. + * <p> + * http://stackoverflow.com/questions/70689/what-is-an-efficient-way-to-implement-a-singleton-pattern-in-java + *<p> + * The risk of this pattern is that bugs resulting from setting a singleton up in a distributed environment can + * be tricky to debug, since it will work fine if you debug with a single classloader. Additionally, these + * problems can crop up a while after the implementation of a singleton, since they may start out synchronous and + * only become async with time, so you it may not be clear why you are seeing certain changes in behaviour. + * <p> + * http://stackoverflow.com/questions/17721263/singleton-across-jvm-or-application-instance-or-tomcat-instance + */ +public class App { + + /** + * Program entry point + * @param args command line args + */ + public static void main(String[] args) { + + // eagerly initialized singleton + IvoryTower ivoryTower1 = IvoryTower.getInstance(); + IvoryTower ivoryTower2 = IvoryTower.getInstance(); + System.out.println("ivoryTower1=" + ivoryTower1); + System.out.println("ivoryTower2=" + ivoryTower2); + + // lazily initialized singleton + ThreadSafeLazyLoadedIvoryTower threadSafeIvoryTower1 = ThreadSafeLazyLoadedIvoryTower + .getInstance(); + ThreadSafeLazyLoadedIvoryTower threadSafeIvoryTower2 = ThreadSafeLazyLoadedIvoryTower + .getInstance(); + System.out.println("threadSafeIvoryTower1=" + threadSafeIvoryTower1); + System.out.println("threadSafeIvoryTower2=" + threadSafeIvoryTower2); + + // enum singleton + EnumIvoryTower enumIvoryTower1 = EnumIvoryTower.INSTANCE; + EnumIvoryTower enumIvoryTower2 = EnumIvoryTower.INSTANCE; + System.out.println("enumIvoryTower1=" + enumIvoryTower1); + System.out.println("enumIvoryTower2=" + enumIvoryTower2); + + InitializingOnDemandHolderIdiom demandHolderIdiom = InitializingOnDemandHolderIdiom.getInstance(); + System.out.println(demandHolderIdiom); + InitializingOnDemandHolderIdiom demandHolderIdiom2 = InitializingOnDemandHolderIdiom.getInstance(); + System.out.println(demandHolderIdiom2); + + ThreadSafeDoubleCheckLocking dcl1 = ThreadSafeDoubleCheckLocking.getInstance(); + System.out.println(dcl1); + ThreadSafeDoubleCheckLocking dcl2 = ThreadSafeDoubleCheckLocking.getInstance(); + System.out.println(dcl2); + } +} diff --git a/singleton/src/main/java/com/iluwatar/singleton/InitializingOnDemandHolderIdiom.java b/singleton/src/main/java/com/iluwatar/singleton/InitializingOnDemandHolderIdiom.java index 329cd6a7e..4fd4c8163 100644 --- a/singleton/src/main/java/com/iluwatar/singleton/InitializingOnDemandHolderIdiom.java +++ b/singleton/src/main/java/com/iluwatar/singleton/InitializingOnDemandHolderIdiom.java @@ -4,12 +4,12 @@ import java.io.Serializable; /** * The Initialize-on-demand-holder idiom is a secure way of - * creating lazy initialize singleton Object in Java. + * creating lazy initialized singleton object in Java. * refer to "The CERT Oracle Secure Coding Standard for Java" * By Dhruv Mohindra, Robert C. Seacord p.378 - * + * <p> * Singleton objects usually are heavy to create and sometimes need to serialize them. - * This class also shows how to preserve singleton in Serialized version of singleton. + * This class also shows how to preserve singleton in serialized version of singleton. * * @author mortezaadi@gmail.com * diff --git a/singleton/src/main/java/com/iluwatar/singleton/ThreadSafeDoubleCheckLocking.java b/singleton/src/main/java/com/iluwatar/singleton/ThreadSafeDoubleCheckLocking.java index 352cac2e9..d15509236 100644 --- a/singleton/src/main/java/com/iluwatar/singleton/ThreadSafeDoubleCheckLocking.java +++ b/singleton/src/main/java/com/iluwatar/singleton/ThreadSafeDoubleCheckLocking.java @@ -2,10 +2,11 @@ package com.iluwatar.singleton; /** * Double check locking - * + * <p> * http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html - * + * <p> * Broken under Java 1.4. + * * @author mortezaadi@gmail.com * */ diff --git a/singleton/src/test/java/com/iluwatar/singleton/AppTest.java b/singleton/src/test/java/com/iluwatar/singleton/AppTest.java index abe0440fd..c83232037 100644 --- a/singleton/src/test/java/com/iluwatar/singleton/AppTest.java +++ b/singleton/src/test/java/com/iluwatar/singleton/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.singleton; - -import org.junit.Test; - -import com.iluwatar.singleton.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.singleton; + +import org.junit.Test; + +import com.iluwatar.singleton.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/singleton/src/test/java/com/iluwatar/singleton/LazyLoadedSingletonThreadSafetyTest.java b/singleton/src/test/java/com/iluwatar/singleton/LazyLoadedSingletonThreadSafetyTest.java index f40d8a319..ca88f4169 100644 --- a/singleton/src/test/java/com/iluwatar/singleton/LazyLoadedSingletonThreadSafetyTest.java +++ b/singleton/src/test/java/com/iluwatar/singleton/LazyLoadedSingletonThreadSafetyTest.java @@ -5,9 +5,9 @@ import org.junit.Test; /** * * This test case demonstrates thread safety issues of lazy loaded Singleton implementation. - * + * <p> * Out of the box you should see the test output something like the following: - * + * <p> * Thread=Thread-4 got instance=com.iluwatar.singleton.LazyLoadedSingletonThreadSafetyTest$LazyLoadedIvoryTower@6fde356e * Thread=Thread-2 creating instance=com.iluwatar.singleton.LazyLoadedSingletonThreadSafetyTest$LazyLoadedIvoryTower@6fde356e * Thread=Thread-0 creating instance=com.iluwatar.singleton.LazyLoadedSingletonThreadSafetyTest$LazyLoadedIvoryTower@6fde356e @@ -15,13 +15,17 @@ import org.junit.Test; * Thread=Thread-3 got instance=com.iluwatar.singleton.LazyLoadedSingletonThreadSafetyTest$LazyLoadedIvoryTower@6fde356e * Thread=Thread-1 got instance=com.iluwatar.singleton.LazyLoadedSingletonThreadSafetyTest$LazyLoadedIvoryTower@60f330b0 * Thread=Thread-2 got instance=com.iluwatar.singleton.LazyLoadedSingletonThreadSafetyTest$LazyLoadedIvoryTower@6fde356e - * + * <p> * By changing the method signature of LazyLoadedIvoryTower#getInstance from + * <p><blockquote><pre> * public static LazyLoadedIvoryTower getInstance() + * </pre></blockquote><p> * into + * <p><blockquote><pre> * public synchronized static LazyLoadedIvoryTower getInstance() + * </pre></blockquote><p> * you should see the test output change to something like the following: - * + * <p> * Thread=Thread-4 creating instance=com.iluwatar.singleton.LazyLoadedSingletonThreadSafetyTest$LazyLoadedIvoryTower@3c688490 * Thread=Thread-4 got instance=com.iluwatar.singleton.LazyLoadedSingletonThreadSafetyTest$LazyLoadedIvoryTower@3c688490 * Thread=Thread-0 got instance=com.iluwatar.singleton.LazyLoadedSingletonThreadSafetyTest$LazyLoadedIvoryTower@3c688490 diff --git a/specification/src/main/java/com/iluwatar/specification/app/App.java b/specification/src/main/java/com/iluwatar/specification/app/App.java index 7a5f00a5c..642278f16 100644 --- a/specification/src/main/java/com/iluwatar/specification/app/App.java +++ b/specification/src/main/java/com/iluwatar/specification/app/App.java @@ -18,14 +18,14 @@ import com.iluwatar.specification.selector.MovementSelector; /** * - * The central idea of Specification pattern is to separate the statement of how to match a candidate, from the + * The central idea of the Specification pattern is to separate the statement of how to match a candidate, from the * candidate object that it is matched against. As well as its usefulness in selection, it is also valuable for * validation and for building to order. - * + * <p> * In this example we have a pool of creatures with different properties. We then have defined separate selection * rules (Specifications) that we apply to the collection and as output receive only the creatures that match * the selection criteria. - * + * <p> * http://martinfowler.com/apsupp/spec.pdf * */ diff --git a/specification/src/test/java/com/iluwatar/specification/app/AppTest.java b/specification/src/test/java/com/iluwatar/specification/app/AppTest.java index 8e27167dc..31965336c 100644 --- a/specification/src/test/java/com/iluwatar/specification/app/AppTest.java +++ b/specification/src/test/java/com/iluwatar/specification/app/AppTest.java @@ -4,6 +4,11 @@ import org.junit.Test; import com.iluwatar.specification.app.App; +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/state/src/main/java/com/iluwatar/state/App.java b/state/src/main/java/com/iluwatar/state/App.java index eefa8f766..5b39d02f7 100644 --- a/state/src/main/java/com/iluwatar/state/App.java +++ b/state/src/main/java/com/iluwatar/state/App.java @@ -1,24 +1,24 @@ -package com.iluwatar.state; - -/** - * - * In State pattern the container object (Mammoth) has an internal state object (State) that - * defines the current behavior. The state object can be changed to alter the - * behavior. - * - * In this example the mammoth changes its behavior as time passes by. - * - */ -public class App { - - public static void main(String[] args) { - - Mammoth mammoth = new Mammoth(); - mammoth.observe(); - mammoth.timePasses(); - mammoth.observe(); - mammoth.timePasses(); - mammoth.observe(); - - } -} +package com.iluwatar.state; + +/** + * + * In State pattern the container object ({@link Mammoth}) has an internal state object ({@link State}) that + * defines the current behavior. The state object can be changed to alter the + * behavior. + * <p> + * In this example the {@link Mammoth} changes its behavior as time passes by. + * + */ +public class App { + + public static void main(String[] args) { + + Mammoth mammoth = new Mammoth(); + mammoth.observe(); + mammoth.timePasses(); + mammoth.observe(); + mammoth.timePasses(); + mammoth.observe(); + + } +} diff --git a/state/src/test/java/com/iluwatar/state/AppTest.java b/state/src/test/java/com/iluwatar/state/AppTest.java index fae8412fc..556cbc01c 100644 --- a/state/src/test/java/com/iluwatar/state/AppTest.java +++ b/state/src/test/java/com/iluwatar/state/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.state; - -import org.junit.Test; - -import com.iluwatar.state.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.state; + +import org.junit.Test; + +import com.iluwatar.state.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/step-builder/src/main/java/com/iluwatar/stepbuilder/App.java b/step-builder/src/main/java/com/iluwatar/stepbuilder/App.java index 439c5bd11..533394acb 100644 --- a/step-builder/src/main/java/com/iluwatar/stepbuilder/App.java +++ b/step-builder/src/main/java/com/iluwatar/stepbuilder/App.java @@ -32,10 +32,15 @@ package com.iluwatar.stepbuilder; * the object and how they're assembled the construction process must * allow different representations for the object that's constructed * when in the process of constructing the order is important. - * + * <p> * http://rdafbn.blogspot.co.uk/2012/07/step-builder-pattern_28.html */ public class App { + + /** + * Program entry point + * @param args command line args + */ public static void main(String[] args) { Character warrior = CharacterStepBuilder.newBuilder() diff --git a/step-builder/src/main/java/com/iluwatar/stepbuilder/CharacterStepBuilder.java b/step-builder/src/main/java/com/iluwatar/stepbuilder/CharacterStepBuilder.java index e042758d9..b1ef3b5af 100644 --- a/step-builder/src/main/java/com/iluwatar/stepbuilder/CharacterStepBuilder.java +++ b/step-builder/src/main/java/com/iluwatar/stepbuilder/CharacterStepBuilder.java @@ -6,7 +6,6 @@ import java.util.List; /** * The Step Builder class. */ - public class CharacterStepBuilder { private CharacterStepBuilder() { diff --git a/step-builder/src/test/java/com/iluwatar/stepbuilder/AppTest.java b/step-builder/src/test/java/com/iluwatar/stepbuilder/AppTest.java index 61fe82aaf..fbed6798e 100644 --- a/step-builder/src/test/java/com/iluwatar/stepbuilder/AppTest.java +++ b/step-builder/src/test/java/com/iluwatar/stepbuilder/AppTest.java @@ -2,6 +2,11 @@ package com.iluwatar.stepbuilder; import org.junit.Test; +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/strategy/src/main/java/com/iluwatar/strategy/App.java b/strategy/src/main/java/com/iluwatar/strategy/App.java index fc9a31327..992514801 100644 --- a/strategy/src/main/java/com/iluwatar/strategy/App.java +++ b/strategy/src/main/java/com/iluwatar/strategy/App.java @@ -1,22 +1,26 @@ -package com.iluwatar.strategy; - -/** - * - * Strategy (DragonSlayingStrategy) encapsulates an algorithm. The containing - * object (DragonSlayer) can alter its behavior by changing its strategy. - * - */ -public class App { - - public static void main(String[] args) { - System.out.println("Green dragon spotted ahead!"); - DragonSlayer dragonSlayer = new DragonSlayer(new MeleeStrategy()); - dragonSlayer.goToBattle(); - System.out.println("Red dragon emerges."); - dragonSlayer.changeStrategy(new ProjectileStrategy()); - dragonSlayer.goToBattle(); - System.out.println("Black dragon lands before you."); - dragonSlayer.changeStrategy(new SpellStrategy()); - dragonSlayer.goToBattle(); - } -} +package com.iluwatar.strategy; + +/** + * + * Strategy ({@link DragonSlayingStrategy}) encapsulates an algorithm. The containing + * object ({@link DragonSlayer}) can alter its behavior by changing its strategy. + * + */ +public class App { + + /** + * Program entry point + * @param args command line args + */ + public static void main(String[] args) { + System.out.println("Green dragon spotted ahead!"); + DragonSlayer dragonSlayer = new DragonSlayer(new MeleeStrategy()); + dragonSlayer.goToBattle(); + System.out.println("Red dragon emerges."); + dragonSlayer.changeStrategy(new ProjectileStrategy()); + dragonSlayer.goToBattle(); + System.out.println("Black dragon lands before you."); + dragonSlayer.changeStrategy(new SpellStrategy()); + dragonSlayer.goToBattle(); + } +} diff --git a/strategy/src/test/java/com/iluwatar/strategy/AppTest.java b/strategy/src/test/java/com/iluwatar/strategy/AppTest.java index e46708c0a..e6748d30d 100644 --- a/strategy/src/test/java/com/iluwatar/strategy/AppTest.java +++ b/strategy/src/test/java/com/iluwatar/strategy/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.strategy; - -import org.junit.Test; - -import com.iluwatar.strategy.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.strategy; + +import org.junit.Test; + +import com.iluwatar.strategy.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/template-method/src/main/java/com/iluwatar/templatemethod/App.java b/template-method/src/main/java/com/iluwatar/templatemethod/App.java index 9797474cf..c9927e91b 100644 --- a/template-method/src/main/java/com/iluwatar/templatemethod/App.java +++ b/template-method/src/main/java/com/iluwatar/templatemethod/App.java @@ -1,20 +1,24 @@ -package com.iluwatar.templatemethod; - -/** - * - * Template Method defines a skeleton for an algorithm. The algorithm subclasses - * provide implementation for the blank parts. - * - * In this example HalflingThief contains StealingMethod that can be changed. - * First the thief hits with HitAndRunMethod and then with SubtleMethod. - * - */ -public class App { - - public static void main(String[] args) { - HalflingThief thief = new HalflingThief(new HitAndRunMethod()); - thief.steal(); - thief.changeMethod(new SubtleMethod()); - thief.steal(); - } -} +package com.iluwatar.templatemethod; + +/** + * + * Template Method defines a skeleton for an algorithm. The algorithm subclasses + * provide implementation for the blank parts. + * <p> + * In this example {@link HalflingThief} contains {@link StealingMethod} that can be changed. + * First the thief hits with {@link HitAndRunMethod} and then with {@link SubtleMethod}. + * + */ +public class App { + + /** + * Program entry point + * @param args command line args + */ + public static void main(String[] args) { + HalflingThief thief = new HalflingThief(new HitAndRunMethod()); + thief.steal(); + thief.changeMethod(new SubtleMethod()); + thief.steal(); + } +} diff --git a/template-method/src/main/java/com/iluwatar/templatemethod/HalflingThief.java b/template-method/src/main/java/com/iluwatar/templatemethod/HalflingThief.java index 3cdb2f1b1..4d6cecb9f 100644 --- a/template-method/src/main/java/com/iluwatar/templatemethod/HalflingThief.java +++ b/template-method/src/main/java/com/iluwatar/templatemethod/HalflingThief.java @@ -1,23 +1,23 @@ -package com.iluwatar.templatemethod; - -/** - * - * Halfling thief uses StealingMethod to steal. - * - */ -public class HalflingThief { - - private StealingMethod method; - - public HalflingThief(StealingMethod method) { - this.method = method; - } - - public void steal() { - method.steal(); - } - - public void changeMethod(StealingMethod method) { - this.method = method; - } -} +package com.iluwatar.templatemethod; + +/** + * + * Halfling thief uses {@link StealingMethod} to steal. + * + */ +public class HalflingThief { + + private StealingMethod method; + + public HalflingThief(StealingMethod method) { + this.method = method; + } + + public void steal() { + method.steal(); + } + + public void changeMethod(StealingMethod method) { + this.method = method; + } +} diff --git a/template-method/src/main/java/com/iluwatar/templatemethod/HitAndRunMethod.java b/template-method/src/main/java/com/iluwatar/templatemethod/HitAndRunMethod.java index 78ee2031b..633e52895 100644 --- a/template-method/src/main/java/com/iluwatar/templatemethod/HitAndRunMethod.java +++ b/template-method/src/main/java/com/iluwatar/templatemethod/HitAndRunMethod.java @@ -1,25 +1,25 @@ -package com.iluwatar.templatemethod; - -/** - * - * HitAndRunMethod implementation of StealingMethod. - * - */ -public class HitAndRunMethod extends StealingMethod { - - @Override - protected String pickTarget() { - return "old goblin woman"; - } - - @Override - protected void confuseTarget(String target) { - System.out.println("Approach the " + target + " from behind."); - } - - @Override - protected void stealTheItem(String target) { - System.out.println("Grab the handbag and run away fast!"); - } - -} +package com.iluwatar.templatemethod; + +/** + * + * HitAndRunMethod implementation of {@link StealingMethod}. + * + */ +public class HitAndRunMethod extends StealingMethod { + + @Override + protected String pickTarget() { + return "old goblin woman"; + } + + @Override + protected void confuseTarget(String target) { + System.out.println("Approach the " + target + " from behind."); + } + + @Override + protected void stealTheItem(String target) { + System.out.println("Grab the handbag and run away fast!"); + } + +} diff --git a/template-method/src/main/java/com/iluwatar/templatemethod/SubtleMethod.java b/template-method/src/main/java/com/iluwatar/templatemethod/SubtleMethod.java index c5bd1cfaf..f506d682b 100644 --- a/template-method/src/main/java/com/iluwatar/templatemethod/SubtleMethod.java +++ b/template-method/src/main/java/com/iluwatar/templatemethod/SubtleMethod.java @@ -1,27 +1,27 @@ -package com.iluwatar.templatemethod; - -/** - * - * SubtleMethod implementation of StealingMethod. - * - */ -public class SubtleMethod extends StealingMethod { - - @Override - protected String pickTarget() { - return "shop keeper"; - } - - @Override - protected void confuseTarget(String target) { - System.out.println("Approach the " + target - + " with tears running and hug him!"); - } - - @Override - protected void stealTheItem(String target) { - System.out.println("While in close contact grab the " + target - + "'s wallet."); - } - -} +package com.iluwatar.templatemethod; + +/** + * + * SubtleMethod implementation of {@link StealingMethod}. + * + */ +public class SubtleMethod extends StealingMethod { + + @Override + protected String pickTarget() { + return "shop keeper"; + } + + @Override + protected void confuseTarget(String target) { + System.out.println("Approach the " + target + + " with tears running and hug him!"); + } + + @Override + protected void stealTheItem(String target) { + System.out.println("While in close contact grab the " + target + + "'s wallet."); + } + +} diff --git a/template-method/src/test/java/com/iluwatar/templatemethod/AppTest.java b/template-method/src/test/java/com/iluwatar/templatemethod/AppTest.java index fce07bef1..bd4e2d332 100644 --- a/template-method/src/test/java/com/iluwatar/templatemethod/AppTest.java +++ b/template-method/src/test/java/com/iluwatar/templatemethod/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.templatemethod; - -import org.junit.Test; - -import com.iluwatar.templatemethod.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.templatemethod; + +import org.junit.Test; + +import com.iluwatar.templatemethod.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/thread-pool/src/main/java/com/iluwatar/threadpool/App.java b/thread-pool/src/main/java/com/iluwatar/threadpool/App.java index 0a7bed3a0..bfaaead31 100644 --- a/thread-pool/src/main/java/com/iluwatar/threadpool/App.java +++ b/thread-pool/src/main/java/com/iluwatar/threadpool/App.java @@ -13,14 +13,19 @@ import java.util.concurrent.Executors; * more tasks than threads. As soon as a thread completes its task, it will request the next * task from the queue until all tasks have been completed. The thread can then terminate, or * sleep until there are new tasks available. - * + * <p> * In this example we create a list of tasks presenting work to be done. Each task is then - * wrapped into a Worker object that implements Runnable. We create an ExecutorService with - * fixed number of threads (Thread Pool) and use them to execute the Workers. + * wrapped into a {@link Worker} object that implements {@link Runnable}. We create an + * {@link ExecutorService} with fixed number of threads (Thread Pool) and use them to execute + * the {@link Worker}s. * */ public class App { + /** + * Program entry point + * @param args command line args + */ public static void main( String[] args ) { System.out.println("Program started"); diff --git a/thread-pool/src/main/java/com/iluwatar/threadpool/Worker.java b/thread-pool/src/main/java/com/iluwatar/threadpool/Worker.java index b6ee5e665..92da4b5dd 100644 --- a/thread-pool/src/main/java/com/iluwatar/threadpool/Worker.java +++ b/thread-pool/src/main/java/com/iluwatar/threadpool/Worker.java @@ -2,7 +2,7 @@ package com.iluwatar.threadpool; /** * - * Worker implements Runnable and thus can be executed by ExecutorService + * Worker implements {@link Runnable} and thus can be executed by {@link ExecutorService} * */ public class Worker implements Runnable { diff --git a/thread-pool/src/test/java/com/iluwatar/threadpool/AppTest.java b/thread-pool/src/test/java/com/iluwatar/threadpool/AppTest.java index ec5c031ff..71cfea5f7 100644 --- a/thread-pool/src/test/java/com/iluwatar/threadpool/AppTest.java +++ b/thread-pool/src/test/java/com/iluwatar/threadpool/AppTest.java @@ -4,6 +4,11 @@ import org.junit.Test; import com.iluwatar.threadpool.App; +/** + * Application test + * @author ilkka + * + */ public class AppTest { @Test diff --git a/tolerant-reader/src/main/java/com/iluwatar/tolerantreader/App.java b/tolerant-reader/src/main/java/com/iluwatar/tolerantreader/App.java index ab4a8bfad..d4ff933d7 100644 --- a/tolerant-reader/src/main/java/com/iluwatar/tolerantreader/App.java +++ b/tolerant-reader/src/main/java/com/iluwatar/tolerantreader/App.java @@ -7,14 +7,14 @@ import java.io.IOException; * Tolerant Reader is an integration pattern that helps creating robust communication * systems. The idea is to be as tolerant as possible when reading data from another * service. This way, when the communication schema changes, the readers must not break. - * - * In this example we use Java serialization to write representations of RainbowFish - * objects to file. RainbowFish is the initial version which we can easily read and - * write using RainbowFishSerializer methods. RainbowFish then evolves to RainbowFishV2 + * <p> + * In this example we use Java serialization to write representations of {@link RainbowFish} + * objects to file. {@link RainbowFish} is the initial version which we can easily read and + * write using {@link RainbowFishSerializer} methods. {@link RainbowFish} then evolves to {@link RainbowFishV2} * and we again write it to file with a method designed to do just that. However, the reader * client does not know about the new format and still reads with the method designed for * V1 schema. Fortunately the reading method has been designed with the Tolerant Reader - * pattern and does not break even though RainbowFishV2 has new fields that are serialized. + * pattern and does not break even though {@link RainbowFishV2} has new fields that are serialized. * */ public class App { diff --git a/tolerant-reader/src/main/java/com/iluwatar/tolerantreader/RainbowFishSerializer.java b/tolerant-reader/src/main/java/com/iluwatar/tolerantreader/RainbowFishSerializer.java index ec482a34a..e788bcad4 100644 --- a/tolerant-reader/src/main/java/com/iluwatar/tolerantreader/RainbowFishSerializer.java +++ b/tolerant-reader/src/main/java/com/iluwatar/tolerantreader/RainbowFishSerializer.java @@ -10,8 +10,8 @@ import java.util.Map; /** * - * RainbowFishSerializer provides methods for reading and writing RainbowFish objects to file. - * Tolerant Reader pattern is implemented here by serializing maps instead of RainbowFish objects. + * RainbowFishSerializer provides methods for reading and writing {@link RainbowFish} objects to file. + * Tolerant Reader pattern is implemented here by serializing maps instead of {@link RainbowFish} objects. * This way the reader does not break even though new properties are added to the schema. * */ diff --git a/tolerant-reader/src/test/java/com/iluwatar/tolerantreader/AppTest.java b/tolerant-reader/src/test/java/com/iluwatar/tolerantreader/AppTest.java index cba24ada9..bc5066866 100644 --- a/tolerant-reader/src/test/java/com/iluwatar/tolerantreader/AppTest.java +++ b/tolerant-reader/src/test/java/com/iluwatar/tolerantreader/AppTest.java @@ -9,7 +9,11 @@ import org.junit.Test; import com.iluwatar.tolerantreader.App; - +/** + * + * Application test + * + */ public class AppTest { @Test diff --git a/visitor/src/main/java/com/iluwatar/visitor/App.java b/visitor/src/main/java/com/iluwatar/visitor/App.java index d9338777c..dfdd4fcb6 100644 --- a/visitor/src/main/java/com/iluwatar/visitor/App.java +++ b/visitor/src/main/java/com/iluwatar/visitor/App.java @@ -1,27 +1,31 @@ -package com.iluwatar.visitor; - -/** - * - * Visitor pattern defines mechanism to apply operations on nodes - * in hierarchy. New operations can be added without altering the node - * interface. - * - * In this example there is a unit hierarchy beginning from Commander. - * This hierarchy is traversed by visitors. SoldierVisitor applies - * its operation on Soldiers, SergeantVisitor on Sergeants and so - * on. - * - */ -public class App { - - public static void main(String[] args) { - - Commander commander = new Commander(new Sergeant(new Soldier(), - new Soldier(), new Soldier()), new Sergeant(new Soldier(), - new Soldier(), new Soldier())); - commander.accept(new SoldierVisitor()); - commander.accept(new SergeantVisitor()); - commander.accept(new CommanderVisitor()); - - } -} +package com.iluwatar.visitor; + +/** + * + * Visitor pattern defines mechanism to apply operations on nodes + * in hierarchy. New operations can be added without altering the node + * interface. + * <p> + * In this example there is a unit hierarchy beginning from {@link Commander}. + * This hierarchy is traversed by visitors. {@link SoldierVisitor} applies + * its operation on {@link Soldier}s, {@link SergeantVisitor} on {@link Sergeant}s and so + * on. + * + */ +public class App { + + /** + * Program entry point + * @param args command line args + */ + public static void main(String[] args) { + + Commander commander = new Commander(new Sergeant(new Soldier(), + new Soldier(), new Soldier()), new Sergeant(new Soldier(), + new Soldier(), new Soldier())); + commander.accept(new SoldierVisitor()); + commander.accept(new SergeantVisitor()); + commander.accept(new CommanderVisitor()); + + } +} diff --git a/visitor/src/test/java/com/iluwatar/visitor/AppTest.java b/visitor/src/test/java/com/iluwatar/visitor/AppTest.java index 5ba48c6c9..66db8c2e3 100644 --- a/visitor/src/test/java/com/iluwatar/visitor/AppTest.java +++ b/visitor/src/test/java/com/iluwatar/visitor/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.visitor; - -import org.junit.Test; - -import com.iluwatar.visitor.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.visitor; + +import org.junit.Test; + +import com.iluwatar.visitor.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +}