diff --git a/trampoline/src/main/java/com/iluwatar/trampoline/Trampoline.java b/trampoline/src/main/java/com/iluwatar/trampoline/Trampoline.java index 65c5f8a5b..862300ea3 100644 --- a/trampoline/src/main/java/com/iluwatar/trampoline/Trampoline.java +++ b/trampoline/src/main/java/com/iluwatar/trampoline/Trampoline.java @@ -26,12 +26,14 @@ package com.iluwatar.trampoline; import java.util.stream.Stream; /** - *
Trampoline pattern allows to define recursive algorithms by iterative loop
+ * Trampoline pattern allows to define recursive algorithms by iterative loop. + * *When get is called on the returned Trampoline, internally it will iterate calling ‘jump’ - * on the returned Trampoline as long as the concrete instance returned is {@link #more(Trampoline)}, - * stopping once the returned instance is {@link #done(Object)}.
+ * on the returned Trampoline as long as the concrete instance returned is {@link + * #more(Trampoline)}, stopping once the returned instance is {@link #done(Object)}. + * *Essential we convert looping via recursion into iteration, - * the key enabling mechanism is the fact that {@link #more(Trampoline)} is a lazy operation.
+ * the key enabling mechanism is the fact that {@link #more(Trampoline)} is a lazy operation. * * @paramTrampoline pattern allows to define recursive algorithms by iterative loop
- *it is possible to implement algorithms recursively in Java without blowing the stack - * and to interleave the execution of functions without hard coding them together or even using threads.
+ * Trampoline pattern allows to define recursive algorithms by iterative loop. + * + *It is possible to implement algorithms recursively in Java without blowing the stack + * and to interleave the execution of functions without hard coding them together or even using + * threads. */ @Slf4j public class TrampolineApp { /** * Main program for showing pattern. It does loop with factorial function. - * */ + */ public static void main(String[] args) { log.info("start pattern"); Integer result = loop(10, 1).result(); diff --git a/twin/src/main/java/com/iluwatar/twin/App.java b/twin/src/main/java/com/iluwatar/twin/App.java index 6e6ce6ab7..5789d163a 100644 --- a/twin/src/main/java/com/iluwatar/twin/App.java +++ b/twin/src/main/java/com/iluwatar/twin/App.java @@ -26,17 +26,17 @@ package com.iluwatar.twin; /** * Twin pattern is a design pattern which provides a standard solution to simulate multiple * inheritance in java. - *
- * In this example, the essence of the Twin pattern is the {@link BallItem} class and - * {@link BallThread} class represent the twin objects to coordinate with each other(via the twin + * + *
In this example, the essence of the Twin pattern is the {@link BallItem} class and {@link + * BallThread} class represent the twin objects to coordinate with each other(via the twin * reference) like a single class inheriting from {@link GameItem} and {@link Thread}. */ public class App { /** - * Program entry point - * + * Program entry point. + * * @param args command line args */ public static void main(String[] args) throws Exception { diff --git a/twin/src/main/java/com/iluwatar/twin/BallThread.java b/twin/src/main/java/com/iluwatar/twin/BallThread.java index 7567465ba..f302016c8 100644 --- a/twin/src/main/java/com/iluwatar/twin/BallThread.java +++ b/twin/src/main/java/com/iluwatar/twin/BallThread.java @@ -29,7 +29,6 @@ import org.slf4j.LoggerFactory; /** * This class is a UI thread for drawing the {@link BallItem}, and provide the method for suspend * and resume. It hold the reference of {@link BallItem} to delegate the draw task. - * */ public class BallThread extends Thread { @@ -47,7 +46,7 @@ public class BallThread extends Thread { } /** - * Run the thread + * Run the thread. */ public void run() { diff --git a/twin/src/main/java/com/iluwatar/twin/GameItem.java b/twin/src/main/java/com/iluwatar/twin/GameItem.java index dbe7e4024..cc9fb0808 100644 --- a/twin/src/main/java/com/iluwatar/twin/GameItem.java +++ b/twin/src/main/java/com/iluwatar/twin/GameItem.java @@ -34,7 +34,7 @@ public abstract class GameItem { private static final Logger LOGGER = LoggerFactory.getLogger(GameItem.class); /** - * Template method, do some common logic before draw + * Template method, do some common logic before draw. */ public void draw() { LOGGER.info("draw"); diff --git a/typeobjectpattern/src/main/java/com/iluwatar/typeobject/App.java b/typeobjectpattern/src/main/java/com/iluwatar/typeobject/App.java index 75c2a768e..e70acbf9e 100644 --- a/typeobjectpattern/src/main/java/com/iluwatar/typeobject/App.java +++ b/typeobjectpattern/src/main/java/com/iluwatar/typeobject/App.java @@ -29,8 +29,9 @@ import org.json.simple.parser.ParseException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/**
Type object pattern is the pattern we use when the OOP concept of creating a base class and - * inheriting from it just doesn't work for the case in hand. This happens when we either don't know +/** + *
Type object pattern is the pattern we use when the OOP concept of creating a base class and + * inheriting from it just doesn't work for the case in hand. This happens when we either don't know * what types we will need upfront, or want to be able to modify or add new types conveniently w/o * recompiling repeatedly. The pattern provides a solution by allowing flexible creation of required * objects by creating one class, which has a field which represents the 'type' of the object.
@@ -40,17 +41,19 @@ import org.slf4j.LoggerFactory; * Type. We have a json file {@link candy} which contains the details about the candies, and this is * parsed to get all the different candies in {@link JsonParser}. The {@link Cell} class is what the * game matrix is made of, which has the candies that are to be crushed, and contains information on - * how crushing can be done, how the matrix is to be reconfigured and how points are to be gained. + * how crushing can be done, how the matrix is to be reconfigured and how points are to be gained. * The {@link CellPool} class is a pool which reuses the candy cells that have been crushed instead * of making new ones repeatedly. The {@link CandyGame} class has the rules for the continuation of - * the game and the {@link App} class has the game itself. + * the game and the {@link App} class has the game itself. */ public class App { private static final Logger LOGGER = LoggerFactory.getLogger(App.class); + /** * Program entry point. + * * @param args command line args */ public static void main(String[] args) throws FileNotFoundException, IOException, ParseException { @@ -61,7 +64,7 @@ public class App { var start = System.currentTimeMillis(); var end = System.currentTimeMillis(); var round = 0; - while (pointsWon < toWin && end - start < givenTime) { + while (pointsWon < toWin && end - start < givenTime) { round++; var pool = new CellPool(numOfRows * numOfRows + 5); var cg = new CandyGame(numOfRows, pool); @@ -72,7 +75,7 @@ public class App { } cg.printGameStatus(); end = System.currentTimeMillis(); - cg.round((int)(end - start), givenTime); + cg.round((int) (end - start), givenTime); pointsWon += cg.totalPoints; end = System.currentTimeMillis(); } diff --git a/typeobjectpattern/src/main/java/com/iluwatar/typeobject/Candy.java b/typeobjectpattern/src/main/java/com/iluwatar/typeobject/Candy.java index 3803dab55..ec41dc6cd 100644 --- a/typeobjectpattern/src/main/java/com/iluwatar/typeobject/Candy.java +++ b/typeobjectpattern/src/main/java/com/iluwatar/typeobject/Candy.java @@ -24,20 +24,22 @@ package com.iluwatar.typeobject; /** - * The Candy class has a field type, which represents the 'type' of candy. The objects - * are created by parsing the candy.json file. + * The Candy class has a field type, which represents the 'type' of candy. The objects are created + * by parsing the candy.json file. */ - public class Candy { - - enum Type { crushableCandy, rewardFruit }; - + + enum Type { + crushableCandy, + rewardFruit + } + String name; Candy parent; String parentName; private int points; private Type type; - + Candy(String name, String parentName, Type type, int points) { this.name = name; this.parent = null; @@ -45,15 +47,15 @@ public class Candy { this.points = points; this.parentName = parentName; } - + int getPoints() { return this.points; } - + void setPoints(int a) { this.points = a; } - + Type getType() { return this.type; } diff --git a/typeobjectpattern/src/main/java/com/iluwatar/typeobject/CandyGame.java b/typeobjectpattern/src/main/java/com/iluwatar/typeobject/CandyGame.java index c8d29d65e..6b3b138d8 100644 --- a/typeobjectpattern/src/main/java/com/iluwatar/typeobject/CandyGame.java +++ b/typeobjectpattern/src/main/java/com/iluwatar/typeobject/CandyGame.java @@ -23,24 +23,24 @@ package com.iluwatar.typeobject; -import java.util.ArrayList; import com.iluwatar.typeobject.Candy.Type; +import java.util.ArrayList; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * The CandyGame class contains the rules for the continuation of the game and has - * the game matrix (field 'cells') and totalPoints gained during the game. + * The CandyGame class contains the rules for the continuation of the game and has the game matrix + * (field 'cells') and totalPoints gained during the game. */ public class CandyGame { private static final Logger LOGGER = LoggerFactory.getLogger(CandyGame.class); - + Cell[][] cells; CellPool pool; int totalPoints; - + CandyGame(int num, CellPool pool) { this.cells = new Cell[num][num]; this.pool = pool; @@ -48,12 +48,12 @@ public class CandyGame { for (var i = 0; i < num; i++) { for (var j = 0; j < num; j++) { this.cells[i][j] = this.pool.getNewCell(); - this.cells[i][j].xIndex = j; - this.cells[i][j].yIndex = i; + this.cells[i][j].positionX = j; + this.cells[i][j].positionY = i; } } } - + static String numOfSpaces(int num) { String result = ""; for (var i = 0; i < num; i++) { @@ -61,7 +61,7 @@ public class CandyGame { } return result; } - + void printGameStatus() { LOGGER.info(""); for (var i = 0; i < cells.length; i++) { @@ -79,32 +79,32 @@ public class CandyGame { } LOGGER.info(""); } - - ArrayListValue Objects must override equals(), hashCode() to check the equality with values. Value + * Objects should be immutable so declare members final. Obtain instances by static factory methods. + * The elements of the state must be other values, including primitive types. Provide methods, + * typically simple getters, to get the elements of the state. A Value Object must check equality + * with equals() not == + * + *
For more specific and strict rules to implement value objects check the rules from Stephen + * Colebourne's term VALJO : http://blog.joda.org/2014/03/valjos-value-java-objects.html */ public class App { private static final Logger LOGGER = LoggerFactory.getLogger(App.class); - + /** * This practice creates three HeroStats(Value object) and checks equality between those. */ diff --git a/value-object/src/main/java/com/iluwatar/value/object/HeroStat.java b/value-object/src/main/java/com/iluwatar/value/object/HeroStat.java index 46cd2fb33..740be76b1 100644 --- a/value-object/src/main/java/com/iluwatar/value/object/HeroStat.java +++ b/value-object/src/main/java/com/iluwatar/value/object/HeroStat.java @@ -24,11 +24,11 @@ package com.iluwatar.value.object; /** - * HeroStat is a value object - * + * HeroStat is a value object. + * * @see - * http://docs.oracle.com/javase/8/docs/api/java/lang/doc-files/ValueBased.html - * + * http://docs.oracle.com/javase/8/docs/api/java/lang/doc-files/ValueBased.html + * */ public class HeroStat {