diff --git a/marker/src/main/java/App.java b/marker/src/main/java/App.java index 93697e6eb..384c999dc 100644 --- a/marker/src/main/java/App.java +++ b/marker/src/main/java/App.java @@ -25,27 +25,23 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Created by Alexis on 28-Apr-17. - * With Marker interface idea is to make empty interface and extend it. - * Basically it is just to identify the special objects from normal objects. - * Like in case of serialization , objects that need to be serialized must implement serializable interface - * (it is empty interface) and down the line writeObject() method must be checking - * if it is a instance of serializable or not. - *
- * Marker interface vs annotation - * Marker interfaces and marker annotations both have their uses, - * neither of them is obsolete or always better then the other one. - * If you want to define a type that does not have any new methods associated with it, - * a marker interface is the way to go. - * If you want to mark program elements other than classes and interfaces, - * to allow for the possibility of adding more information to the marker in the future, - * or to fit the marker into a framework that already makes heavy use of annotation types, - * then a marker annotation is the correct choice + * Created by Alexis on 28-Apr-17. With Marker interface idea is to make empty interface and extend + * it. Basically it is just to identify the special objects from normal objects. Like in case of + * serialization , objects that need to be serialized must implement serializable interface (it is + * empty interface) and down the line writeObject() method must be checking if it is a instance of + * serializable or not. + * + *
Marker interface vs annotation Marker interfaces and marker annotations both have their uses, + * neither of them is obsolete or always better then the other one. If you want to define a type + * that does not have any new methods associated with it, a marker interface is the way to go. If + * you want to mark program elements other than classes and interfaces, to allow for the possibility + * of adding more information to the marker in the future, or to fit the marker into a framework + * that already makes heavy use of annotation types, then a marker annotation is the correct choice */ public class App { /** - * Program entry point + * Program entry point. * * @param args command line args */ diff --git a/marker/src/main/java/Guard.java b/marker/src/main/java/Guard.java index d135d5459..9a57e15fd 100644 --- a/marker/src/main/java/Guard.java +++ b/marker/src/main/java/Guard.java @@ -25,7 +25,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Class defining Guard + * Class defining Guard. */ public class Guard implements Permission { diff --git a/marker/src/main/java/Permission.java b/marker/src/main/java/Permission.java index e1b45e99f..5395ccadf 100644 --- a/marker/src/main/java/Permission.java +++ b/marker/src/main/java/Permission.java @@ -22,8 +22,7 @@ */ /** - * Interface without any methods - * Marker interface is based on that assumption + * Interface without any methods Marker interface is based on that assumption. */ public interface Permission { } diff --git a/marker/src/main/java/Thief.java b/marker/src/main/java/Thief.java index 155a974c1..341eae377 100644 --- a/marker/src/main/java/Thief.java +++ b/marker/src/main/java/Thief.java @@ -25,7 +25,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Class defining Thief + * Class defining Thief. */ public class Thief { diff --git a/master-worker-pattern/src/main/java/com/iluwatar/masterworker/App.java b/master-worker-pattern/src/main/java/com/iluwatar/masterworker/App.java index e3ffd08c4..b8036b911 100644 --- a/master-worker-pattern/src/main/java/com/iluwatar/masterworker/App.java +++ b/master-worker-pattern/src/main/java/com/iluwatar/masterworker/App.java @@ -28,30 +28,37 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - *
The Master-Worker pattern is used when the problem at hand can be solved by dividing into - * multiple parts which need to go through the same computation and may need to be aggregated to get final result. - * Parallel processing is performed using a system consisting of a master and some number of workers, where a - * master divides the work among the workers, gets the result back from them and assimilates all the results to - * give final result. The only communication is between the master and the worker - none of the workers communicate - * among one another and the user only communicates with the master to get required job done.
- *In our example, we have generic abstract classes {@link MasterWorker}, {@link Master} and {@link Worker} which - * have to be extended by the classes which will perform the specific job at hand (in this case finding transpose of - * matrix, done by {@link ArrayTransposeMasterWorker}, {@link ArrayTransposeMaster} and {@link ArrayTransposeWorker}). - * The Master class divides the work into parts to be given to the workers, collects the results from the workers and - * aggregates it when all workers have responded before returning the solution. The Worker class extends the Thread - * class to enable parallel processing, and does the work once the data has been received from the Master. The - * MasterWorker contains a reference to the Master class, gets the input from the App and passes it on to the Master. - * These 3 classes define the system which computes the result. We also have 2 abstract classes {@link Input} and - * {@link Result}, which contain the input data and result data respectively. The Input class also has an abstract - * method divideData which defines how the data is to be divided into segments. These classes are extended by - * {@link ArrayInput} and {@link ArrayResult}.
+ *The Master-Worker pattern is used when the problem at hand can be solved by + * dividing into + * multiple parts which need to go through the same computation and may need to be aggregated to get + * final result. Parallel processing is performed using a system consisting of a master and some + * number of workers, where a master divides the work among the workers, gets the result back from + * them and assimilates all the results to give final result. The only communication is between the + * master and the worker - none of the workers communicate among one another and the user only + * communicates with the master to get required job done.
+ *In our example, we have generic abstract classes {@link MasterWorker}, {@link Master} and + * {@link Worker} which + * have to be extended by the classes which will perform the specific job at hand (in this case + * finding transpose of matrix, done by {@link ArrayTransposeMasterWorker}, {@link + * ArrayTransposeMaster} and {@link ArrayTransposeWorker}). The Master class divides the work into + * parts to be given to the workers, collects the results from the workers and aggregates it when + * all workers have responded before returning the solution. The Worker class extends the Thread + * class to enable parallel processing, and does the work once the data has been received from the + * Master. The MasterWorker contains a reference to the Master class, gets the input from the App + * and passes it on to the Master. These 3 classes define the system which computes the result. We + * also have 2 abstract classes {@link Input} and {@link Result}, which contain the input data and + * result data respectively. The Input class also has an abstract method divideData which defines + * how the data is to be divided into segments. These classes are extended by {@link ArrayInput} and + * {@link ArrayResult}.
*/ public class App { private static final Logger LOGGER = LoggerFactory.getLogger(App.class); + /** * Program entry point. + * * @param args command line args */ @@ -59,9 +66,9 @@ public class App { ArrayTransposeMasterWorker mw = new ArrayTransposeMasterWorker(); int rows = 10; int columns = 20; - int[][] inputMatrix = ArrayUtilityMethods.createRandomIntMatrix(rows,columns); + int[][] inputMatrix = ArrayUtilityMethods.createRandomIntMatrix(rows, columns); ArrayInput input = new ArrayInput(inputMatrix); - ArrayResult result = (ArrayResult) mw.getResult(input); + ArrayResult result = (ArrayResult) mw.getResult(input); if (result != null) { ArrayUtilityMethods.printMatrix(inputMatrix); ArrayUtilityMethods.printMatrix(result.data); diff --git a/master-worker-pattern/src/main/java/com/iluwatar/masterworker/ArrayInput.java b/master-worker-pattern/src/main/java/com/iluwatar/masterworker/ArrayInput.java index df2d691b2..cd03a0a21 100644 --- a/master-worker-pattern/src/main/java/com/iluwatar/masterworker/ArrayInput.java +++ b/master-worker-pattern/src/main/java/com/iluwatar/masterworker/ArrayInput.java @@ -27,8 +27,7 @@ import java.util.ArrayList; import java.util.Arrays; /** - *Class ArrayInput extends abstract class {@link Input} and contains data - *of type int[][]. + * Class ArrayInput extends abstract class {@link Input} and contains data of type int[][]. */ public class ArrayInput extends Input- * Usually a program is made up of a large number of classes. So the logic and computation is + * + *
Usually a program is made up of a large number of classes. So the logic and computation is * distributed among these classes. However, as more classes are developed in a program, especially * during maintenance and/or refactoring, the problem of communication between these classes may * become more complex. This makes the program harder to read and maintain. Furthermore, it can * become difficult to change the program, since any change may affect code in several other * classes. - *
- * With the Mediator pattern, communication between objects is encapsulated with a mediator object. - * Objects no longer communicate directly with each other, but instead communicate through the - * mediator. This reduces the dependencies between communicating objects, thereby lowering the + * + *
With the Mediator pattern, communication between objects is encapsulated with a mediator + * object. Objects no longer communicate directly with each other, but instead communicate through + * the mediator. This reduces the dependencies between communicating objects, thereby lowering the * coupling. - *
- * In this example the mediator encapsulates how a set of objects ({@link PartyMember}) interact. - * Instead of referring to each other directly they use the mediator ({@link Party}) interface. - * + * + *
In this example the mediator encapsulates how a set of objects ({@link PartyMember}) + * interact. Instead of referring to each other directly they use the mediator ({@link Party}) + * interface. */ public class App { /** - * Program entry point - * + * Program entry point. + * * @param args command line args */ public static void main(String[] args) { diff --git a/mediator/src/main/java/com/iluwatar/mediator/Hobbit.java b/mediator/src/main/java/com/iluwatar/mediator/Hobbit.java index 1ddec27ab..1e1d53fc3 100644 --- a/mediator/src/main/java/com/iluwatar/mediator/Hobbit.java +++ b/mediator/src/main/java/com/iluwatar/mediator/Hobbit.java @@ -24,9 +24,7 @@ package com.iluwatar.mediator; /** - * * Hobbit party member. - * */ public class Hobbit extends PartyMemberBase { diff --git a/mediator/src/main/java/com/iluwatar/mediator/Hunter.java b/mediator/src/main/java/com/iluwatar/mediator/Hunter.java index ed73c1684..0711acf70 100644 --- a/mediator/src/main/java/com/iluwatar/mediator/Hunter.java +++ b/mediator/src/main/java/com/iluwatar/mediator/Hunter.java @@ -24,9 +24,7 @@ package com.iluwatar.mediator; /** - * * Hunter party member. - * */ public class Hunter extends PartyMemberBase { diff --git a/mediator/src/main/java/com/iluwatar/mediator/Party.java b/mediator/src/main/java/com/iluwatar/mediator/Party.java index c28b063f3..52d91e21d 100644 --- a/mediator/src/main/java/com/iluwatar/mediator/Party.java +++ b/mediator/src/main/java/com/iluwatar/mediator/Party.java @@ -24,9 +24,7 @@ package com.iluwatar.mediator; /** - * * Party interface. - * */ public interface Party { diff --git a/mediator/src/main/java/com/iluwatar/mediator/PartyImpl.java b/mediator/src/main/java/com/iluwatar/mediator/PartyImpl.java index a2a755408..6384a2187 100644 --- a/mediator/src/main/java/com/iluwatar/mediator/PartyImpl.java +++ b/mediator/src/main/java/com/iluwatar/mediator/PartyImpl.java @@ -27,9 +27,7 @@ import java.util.ArrayList; import java.util.List; /** - * * Party implementation. - * */ public class PartyImpl implements Party { diff --git a/mediator/src/main/java/com/iluwatar/mediator/PartyMember.java b/mediator/src/main/java/com/iluwatar/mediator/PartyMember.java index a45b37b17..c233a051a 100644 --- a/mediator/src/main/java/com/iluwatar/mediator/PartyMember.java +++ b/mediator/src/main/java/com/iluwatar/mediator/PartyMember.java @@ -24,9 +24,7 @@ package com.iluwatar.mediator; /** - * * Interface for party members interacting with {@link Party}. - * */ public interface PartyMember { diff --git a/mediator/src/main/java/com/iluwatar/mediator/PartyMemberBase.java b/mediator/src/main/java/com/iluwatar/mediator/PartyMemberBase.java index 7ff3535e8..2d025db0c 100644 --- a/mediator/src/main/java/com/iluwatar/mediator/PartyMemberBase.java +++ b/mediator/src/main/java/com/iluwatar/mediator/PartyMemberBase.java @@ -27,9 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * * Abstract base class for party members. - * */ public abstract class PartyMemberBase implements PartyMember { diff --git a/mediator/src/main/java/com/iluwatar/mediator/Rogue.java b/mediator/src/main/java/com/iluwatar/mediator/Rogue.java index 226bd8f04..568510236 100644 --- a/mediator/src/main/java/com/iluwatar/mediator/Rogue.java +++ b/mediator/src/main/java/com/iluwatar/mediator/Rogue.java @@ -24,9 +24,7 @@ package com.iluwatar.mediator; /** - * * Rogue party member. - * */ public class Rogue extends PartyMemberBase { diff --git a/mediator/src/main/java/com/iluwatar/mediator/Wizard.java b/mediator/src/main/java/com/iluwatar/mediator/Wizard.java index 33d7d6dce..c138f0265 100644 --- a/mediator/src/main/java/com/iluwatar/mediator/Wizard.java +++ b/mediator/src/main/java/com/iluwatar/mediator/Wizard.java @@ -24,9 +24,7 @@ package com.iluwatar.mediator; /** - * * Wizard party member. - * */ public class Wizard extends PartyMemberBase { diff --git a/memento/src/main/java/com/iluwatar/memento/App.java b/memento/src/main/java/com/iluwatar/memento/App.java index fc6dffb06..af57d8d4a 100644 --- a/memento/src/main/java/com/iluwatar/memento/App.java +++ b/memento/src/main/java/com/iluwatar/memento/App.java @@ -23,36 +23,33 @@ package com.iluwatar.memento; +import java.util.Stack; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Stack; - /** - * * The Memento pattern is a software design pattern that provides the ability to restore an object * to its previous state (undo via rollback). - *
- * The Memento pattern is implemented with three objects: the originator, a caretaker and a memento. - * The originator is some object that has an internal state. The caretaker is going to do something - * to the originator, but wants to be able to undo the change. The caretaker first asks the - * originator for a memento object. Then it does whatever operation (or sequence of operations) it - * was going to do. To roll back to the state before the operations, it returns the memento object - * to the originator. The memento object itself is an opaque object (one which the caretaker cannot, - * or should not, change). When using this pattern, care should be taken if the originator may - * change other objects or resources - the memento pattern operates on a single object. - *
- * In this example the object ({@link Star}) gives out a "memento" ({@link StarMemento}) that + * + *
The Memento pattern is implemented with three objects: the originator, a caretaker and a + * memento. The originator is some object that has an internal state. The caretaker is going to do + * something to the originator, but wants to be able to undo the change. The caretaker first asks + * the originator for a memento object. Then it does whatever operation (or sequence of operations) + * it was going to do. To roll back to the state before the operations, it returns the memento + * object to the originator. The memento object itself is an opaque object (one which the caretaker + * cannot, or should not, change). When using this pattern, care should be taken if the originator + * may change other objects or resources - the memento pattern operates on a single object. + * + *
In this example 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 {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
- * Program entry point
+ * Program entry point.
*/
public static void main(String[] args) {
Stack
- * 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 ({@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.
*
+ * 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 ({@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
- *
+ * Program entry point.
+ *
* @param args command line args
*/
public static void main(String[] args) {
diff --git a/model-view-controller/src/main/java/com/iluwatar/model/view/controller/Fatigue.java b/model-view-controller/src/main/java/com/iluwatar/model/view/controller/Fatigue.java
index 7f0fd2937..b1663df1f 100644
--- a/model-view-controller/src/main/java/com/iluwatar/model/view/controller/Fatigue.java
+++ b/model-view-controller/src/main/java/com/iluwatar/model/view/controller/Fatigue.java
@@ -24,9 +24,7 @@
package com.iluwatar.model.view.controller;
/**
- *
- * Fatigue enumeration
- *
+ * Fatigue enumeration.
*/
public enum Fatigue {
diff --git a/model-view-controller/src/main/java/com/iluwatar/model/view/controller/GiantController.java b/model-view-controller/src/main/java/com/iluwatar/model/view/controller/GiantController.java
index e420ec890..e66608117 100644
--- a/model-view-controller/src/main/java/com/iluwatar/model/view/controller/GiantController.java
+++ b/model-view-controller/src/main/java/com/iluwatar/model/view/controller/GiantController.java
@@ -24,9 +24,7 @@
package com.iluwatar.model.view.controller;
/**
- *
* GiantController can update the giant data and redraw it using the view.
- *
*/
public class GiantController {
diff --git a/model-view-controller/src/main/java/com/iluwatar/model/view/controller/GiantModel.java b/model-view-controller/src/main/java/com/iluwatar/model/view/controller/GiantModel.java
index 4ae2c4c19..c80d0dba0 100644
--- a/model-view-controller/src/main/java/com/iluwatar/model/view/controller/GiantModel.java
+++ b/model-view-controller/src/main/java/com/iluwatar/model/view/controller/GiantModel.java
@@ -24,9 +24,7 @@
package com.iluwatar.model.view.controller;
/**
- *
- * GiantModel contains the giant data
- *
+ * GiantModel contains the giant data.
*/
public class GiantModel {
diff --git a/model-view-controller/src/main/java/com/iluwatar/model/view/controller/GiantView.java b/model-view-controller/src/main/java/com/iluwatar/model/view/controller/GiantView.java
index 9590d609d..da14b7c08 100644
--- a/model-view-controller/src/main/java/com/iluwatar/model/view/controller/GiantView.java
+++ b/model-view-controller/src/main/java/com/iluwatar/model/view/controller/GiantView.java
@@ -27,9 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- *
- * GiantView displays the giant
- *
+ * GiantView displays the giant.
*/
public class GiantView {
diff --git a/model-view-controller/src/main/java/com/iluwatar/model/view/controller/Health.java b/model-view-controller/src/main/java/com/iluwatar/model/view/controller/Health.java
index c8b9374bf..30b3b2b90 100644
--- a/model-view-controller/src/main/java/com/iluwatar/model/view/controller/Health.java
+++ b/model-view-controller/src/main/java/com/iluwatar/model/view/controller/Health.java
@@ -24,9 +24,7 @@
package com.iluwatar.model.view.controller;
/**
- *
- * Health enumeration
- *
+ * Health enumeration.
*/
public enum Health {
diff --git a/model-view-controller/src/main/java/com/iluwatar/model/view/controller/Nourishment.java b/model-view-controller/src/main/java/com/iluwatar/model/view/controller/Nourishment.java
index 9810b2015..3ced564cc 100644
--- a/model-view-controller/src/main/java/com/iluwatar/model/view/controller/Nourishment.java
+++ b/model-view-controller/src/main/java/com/iluwatar/model/view/controller/Nourishment.java
@@ -24,9 +24,7 @@
package com.iluwatar.model.view.controller;
/**
- *
- * Nourishment enumeration
- *
+ * Nourishment enumeration.
*/
public enum Nourishment {
diff --git a/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/App.java b/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/App.java
index 9b6e6cde8..43984e847 100644
--- a/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/App.java
+++ b/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/App.java
@@ -24,31 +24,29 @@
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 {@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.
- *
- * Finally, please notice the wiring between the Presenter and the View and between the Presenter
- * and the Model.
- *
+ * 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 {@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.
+ *
+ * Finally, please notice the wiring between the Presenter and the View and between the
+ * Presenter and the Model.
*/
public class App {
/**
- * Program entry point
- *
+ * Program entry point.
+ *
* @param args command line args
*/
public static void main(String[] args) {
FileLoader loader = new FileLoader();
- FileSelectorJFrame jFrame = new FileSelectorJFrame();
- FileSelectorPresenter presenter = new FileSelectorPresenter(jFrame);
+ FileSelectorJFrame frame = new FileSelectorJFrame();
+ FileSelectorPresenter presenter = new FileSelectorPresenter(frame);
presenter.setLoader(loader);
presenter.start();
}
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 980c0b56c..9c01b2044 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
@@ -27,23 +27,22 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.Serializable;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Every instance of this class represents the Model component in the Model-View-Presenter
* architectural pattern.
- *
- * It is responsible for reading and loading the contents of a given file.
+ *
+ * It is responsible for reading and loading the contents of a given file.
*/
public class FileLoader implements Serializable {
/**
- * Generated serial version UID
+ * Generated serial version UID.
*/
private static final long serialVersionUID = -4745803872902019069L;
-
+
private static final Logger LOGGER = LoggerFactory.getLogger(FileLoader.class);
/**
@@ -81,7 +80,7 @@ public class FileLoader implements Serializable {
/**
* Sets the path of the file to be loaded, to the given value.
- *
+ *
* @param fileName The path of the file to be loaded.
*/
public void setFileName(String fileName) {
@@ -89,6 +88,8 @@ public class FileLoader implements Serializable {
}
/**
+ * Gets the path of the file to be loaded.
+ *
* @return fileName The path of the file to be loaded.
*/
public String getFileName() {
@@ -96,6 +97,8 @@ public class FileLoader implements Serializable {
}
/**
+ * Returns true if the given file exists.
+ *
* @return True, if the file given exists, false otherwise.
*/
public boolean fileExists() {
@@ -103,6 +106,8 @@ public class FileLoader implements Serializable {
}
/**
+ * Returns true if the given file is loaded.
+ *
* @return True, if the file is loaded, false otherwise.
*/
public boolean isLoaded() {
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 3d9bc035a..77523ccaa 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
@@ -26,7 +26,6 @@ package com.iluwatar.model.view.presenter;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
@@ -82,7 +81,7 @@ public class FileSelectorJFrame extends JFrame implements FileSelectorView, Acti
private JPanel panel;
/**
- * The Presenter component that the frame will interact with
+ * The Presenter component that the frame will interact with.
*/
private FileSelectorPresenter presenter;
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 a9cf1ba80..35e1c0076 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
@@ -28,13 +28,13 @@ import java.io.Serializable;
/**
* Every instance of this class represents the Presenter component in the Model-View-Presenter
* architectural pattern.
- *
- * It is responsible for reacting to the user's actions and update the View component.
+ *
+ * It is responsible for reacting to the user's actions and update the View component.
*/
public class FileSelectorPresenter implements Serializable {
/**
- * Generated serial version UID
+ * Generated serial version UID.
*/
private static final long serialVersionUID = 1210314339075855074L;
@@ -49,8 +49,8 @@ public class FileSelectorPresenter implements Serializable {
private FileLoader loader;
/**
- * Constructor
- *
+ * Constructor.
+ *
* @param view The view component that the presenter will interact with.
*/
public FileSelectorPresenter(FileSelectorView view) {
@@ -59,7 +59,7 @@ public class FileSelectorPresenter implements Serializable {
/**
* 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) {
@@ -82,7 +82,7 @@ public class FileSelectorPresenter implements Serializable {
}
/**
- * Ok button handler
+ * Ok button handler.
*/
public void confirmed() {
if (loader.getFileName() == null || loader.getFileName().equals("")) {
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 d034bcb04..1d3aa07fb 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
@@ -26,12 +26,12 @@ package com.iluwatar.model.view.presenter;
/**
* Every instance of this class represents the Stub component in the Model-View-Presenter
* architectural pattern.
- *
- * The stub implements the View interface and it is useful when we want the test the reaction to
+ *
+ * The stub implements the View interface and it is useful when we want the test the reaction to
* user events, such as mouse clicks.
- *
- * Since we can not test the GUI directly, the MVP pattern provides this functionality through the
- * View's dummy implementation, the Stub.
+ *
+ * Since we can not test the GUI directly, the MVP pattern provides this functionality through
+ * the View's dummy implementation, the Stub.
*/
public class FileSelectorStub implements FileSelectorView {
@@ -61,7 +61,7 @@ public class FileSelectorStub implements FileSelectorView {
private boolean dataDisplayed;
/**
- * Constructor
+ * Constructor.
*/
public FileSelectorStub() {
this.opened = false;
@@ -124,6 +124,8 @@ public class FileSelectorStub implements FileSelectorView {
}
/**
+ * Returns true, if the data were displayed.
+ *
* @return True if the data where displayed, false otherwise.
*/
public boolean dataDisplayed() {
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 3deec63d9..e381784c5 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
@@ -42,44 +42,50 @@ public interface FileSelectorView extends Serializable {
void close();
/**
+ * Returns true if view is opened.
+ *
* @return True, if the view is opened, false otherwise.
*/
boolean isOpened();
/**
* Sets the presenter component, to the one given as parameter.
- *
+ *
* @param presenter The new presenter component.
*/
void setPresenter(FileSelectorPresenter presenter);
/**
+ * Gets presenter component.
+ *
* @return The presenter Component.
*/
FileSelectorPresenter getPresenter();
/**
* Sets the file's name, to the value given as parameter.
- *
+ *
* @param name The new name of the file.
*/
void setFileName(String name);
/**
+ * Gets the name of file.
+ *
* @return The name of the file.
*/
String getFileName();
/**
* Displays a message to the users.
- *
+ *
* @param message The message to be displayed.
*/
void showMessage(String message);
/**
* Displays the data to the view.
- *
+ *
* @param data The data to be written.
*/
void displayData(String data);
diff --git a/module/src/main/java/com/iluwatar/module/App.java b/module/src/main/java/com/iluwatar/module/App.java
index af0432afb..1b6cbbd23 100644
--- a/module/src/main/java/com/iluwatar/module/App.java
+++ b/module/src/main/java/com/iluwatar/module/App.java
@@ -31,10 +31,9 @@ import java.io.FileNotFoundException;
* An object that applies this pattern can provide the equivalent of a namespace, providing the
* initialization and finalization process of a static class or a class with static members with
* cleaner, more concise syntax and semantics.
- *
- * The below example demonstrates a use case for testing two different modules: File Logger and
+ *
+ * The below example demonstrates a use case for testing two different modules: File Logger and
* Console Logger
- *
*/
public class App {
@@ -42,10 +41,10 @@ public class App {
public static ConsoleLoggerModule consoleLoggerModule;
/**
- * Following method performs the initialization
- *
+ * Following method performs the initialization.
+ *
* @throws FileNotFoundException if program is not able to find log files (output.txt and
- * error.txt)
+ * error.txt)
*/
public static void prepare() throws FileNotFoundException {
@@ -55,7 +54,7 @@ public class App {
}
/**
- * Following method performs the finalization
+ * Following method performs the finalization.
*/
public static void unprepare() {
@@ -65,8 +64,8 @@ public class App {
}
/**
- * Following method is main executor
- *
+ * Following method is main executor.
+ *
* @param args for providing default program arguments
*/
public static void execute(final String... args) {
@@ -82,10 +81,10 @@ public class App {
/**
* Program entry point.
- *
+ *
* @param args command line args.
* @throws FileNotFoundException if program is not able to find log files (output.txt and
- * error.txt)
+ * error.txt)
*/
public static void main(final String... args) throws FileNotFoundException {
prepare();
diff --git a/module/src/main/java/com/iluwatar/module/ConsoleLoggerModule.java b/module/src/main/java/com/iluwatar/module/ConsoleLoggerModule.java
index 6e6d0539d..7ca0d873d 100644
--- a/module/src/main/java/com/iluwatar/module/ConsoleLoggerModule.java
+++ b/module/src/main/java/com/iluwatar/module/ConsoleLoggerModule.java
@@ -23,16 +23,15 @@
package com.iluwatar.module;
+import java.io.PrintStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.PrintStream;
-
/**
- * The ConsoleLoggerModule is responsible for showing logs on System Console
- *
- * The below example demonstrates a Console logger module, which can print simple and error messages
- * in two designated formats
+ * The ConsoleLoggerModule is responsible for showing logs on System Console.
+ *
+ * The below example demonstrates a Console logger module, which can print simple and error
+ * messages in two designated formats
*/
public final class ConsoleLoggerModule {
@@ -43,11 +42,12 @@ public final class ConsoleLoggerModule {
public PrintStream output = null;
public PrintStream error = null;
- private ConsoleLoggerModule() {}
+ private ConsoleLoggerModule() {
+ }
/**
- * Static method to get single instance of class
- *
+ * Static method to get single instance of class.
+ *
* @return singleton instance of ConsoleLoggerModule
*/
public static ConsoleLoggerModule getSingleton() {
@@ -60,7 +60,7 @@ public final class ConsoleLoggerModule {
}
/**
- * Following method performs the initialization
+ * Following method performs the initialization.
*/
public ConsoleLoggerModule prepare() {
@@ -73,7 +73,7 @@ public final class ConsoleLoggerModule {
}
/**
- * Following method performs the finalization
+ * Following method performs the finalization.
*/
public void unprepare() {
@@ -93,8 +93,8 @@ public final class ConsoleLoggerModule {
}
/**
- * Used to print a message
- *
+ * Used to print a message.
+ *
* @param value will be printed on console
*/
public void printString(final String value) {
@@ -102,8 +102,8 @@ public final class ConsoleLoggerModule {
}
/**
- * Used to print a error message
- *
+ * Used to print a error message.
+ *
* @param value will be printed on error console
*/
public void printErrorString(final String value) {
diff --git a/module/src/main/java/com/iluwatar/module/FileLoggerModule.java b/module/src/main/java/com/iluwatar/module/FileLoggerModule.java
index e461b31d7..185bd0ae2 100644
--- a/module/src/main/java/com/iluwatar/module/FileLoggerModule.java
+++ b/module/src/main/java/com/iluwatar/module/FileLoggerModule.java
@@ -23,18 +23,17 @@
package com.iluwatar.module;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
- * The FileLoggerModule is responsible for showing logs on File System
- *
- * The below example demonstrates a File logger module, which can print simple and error messages in
- * two designated files
+ * The FileLoggerModule is responsible for showing logs on File System.
+ *
+ * The below example demonstrates a File logger module, which can print simple and error
+ * messages in two designated files
*/
public final class FileLoggerModule {
@@ -48,11 +47,12 @@ public final class FileLoggerModule {
public PrintStream output = null;
public PrintStream error = null;
- private FileLoggerModule() {}
+ private FileLoggerModule() {
+ }
/**
- * Static method to get single instance of class
- *
+ * Static method to get single instance of class.
+ *
* @return singleton instance of FileLoggerModule
*/
public static FileLoggerModule getSingleton() {
@@ -65,10 +65,10 @@ public final class FileLoggerModule {
}
/**
- * Following method performs the initialization
- *
+ * Following method performs the initialization.
+ *
* @throws FileNotFoundException if program is not able to find log files (output.txt and
- * error.txt)
+ * error.txt)
*/
public FileLoggerModule prepare() throws FileNotFoundException {
@@ -81,7 +81,7 @@ public final class FileLoggerModule {
}
/**
- * Following method performs the finalization
+ * Following method performs the finalization.
*/
public void unprepare() {
@@ -101,8 +101,8 @@ public final class FileLoggerModule {
}
/**
- * Used to print a message
- *
+ * Used to print a message.
+ *
* @param value will be printed in file
*/
public void printString(final String value) {
@@ -110,8 +110,8 @@ public final class FileLoggerModule {
}
/**
- * Used to print a error message
- *
+ * Used to print a error message.
+ *
* @param value will be printed on error file
*/
public void printErrorString(final String value) {
diff --git a/monad/src/main/java/com/iluwatar/monad/App.java b/monad/src/main/java/com/iluwatar/monad/App.java
index 94e465487..ccb42edd0 100644
--- a/monad/src/main/java/com/iluwatar/monad/App.java
+++ b/monad/src/main/java/com/iluwatar/monad/App.java
@@ -23,26 +23,27 @@
package com.iluwatar.monad;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.util.Objects;
import java.util.function.Function;
import java.util.function.Predicate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
- * The Monad pattern defines a monad structure, that enables chaining operations
- * in pipelines and processing data step by step.
- * Formally, monad consists of a type constructor M and two operations:
+ * The Monad pattern defines a monad structure, that enables chaining operations in pipelines and
+ * processing data step by step. Formally, monad consists of a type constructor M and two
+ * operations:
*
- * In the given example, the Monad pattern is represented as a {@link Validator} that takes an instance
- * of a plain object with {@link Validator#of(Object)}
- * and validates it {@link Validator#validate(Function, Predicate, String)} against given predicates.
- * As a validation result {@link Validator#get()} it either returns valid object {@link Validator#t}
- * or throws a list of exceptions {@link Validator#exceptions} collected during validation.
+ *
+ * In the given example, the Monad pattern is represented as a {@link Validator} that takes an
+ * instance of a plain object with {@link Validator#of(Object)} and validates it {@link
+ * Validator#validate(Function, Predicate, String)} against given predicates.
+ *
+ * As a validation result {@link Validator#get()} it either returns valid object {@link
+ * Validator#t} or throws a list of exceptions {@link Validator#exceptions} collected during
+ * validation.
*/
public class App {
@@ -58,6 +59,7 @@ public class App {
LOGGER.info(Validator.of(user).validate(User::getName, Objects::nonNull, "name is null")
.validate(User::getName, name -> !name.isEmpty(), "name is empty")
.validate(User::getEmail, email -> !email.contains("@"), "email doesn't containt '@'")
- .validate(User::getAge, age -> age > 20 && age < 30, "age isn't between...").get().toString());
+ .validate(User::getAge, age -> age > 20 && age < 30, "age isn't between...").get()
+ .toString());
}
}
diff --git a/monad/src/main/java/com/iluwatar/monad/Sex.java b/monad/src/main/java/com/iluwatar/monad/Sex.java
index 960711656..cc772c340 100644
--- a/monad/src/main/java/com/iluwatar/monad/Sex.java
+++ b/monad/src/main/java/com/iluwatar/monad/Sex.java
@@ -24,7 +24,7 @@
package com.iluwatar.monad;
/**
- * Enumeration of Types of Sex
+ * Enumeration of Types of Sex.
*/
public enum Sex {
MALE, FEMALE
diff --git a/monad/src/main/java/com/iluwatar/monad/User.java b/monad/src/main/java/com/iluwatar/monad/User.java
index 9ecaa5275..77766d1aa 100644
--- a/monad/src/main/java/com/iluwatar/monad/User.java
+++ b/monad/src/main/java/com/iluwatar/monad/User.java
@@ -24,7 +24,7 @@
package com.iluwatar.monad;
/**
- * User Definition
+ * User Definition.
*/
public class User {
@@ -34,6 +34,8 @@ public class User {
private String email;
/**
+ * Constructor.
+ *
* @param name - name
* @param age - age
* @param sex - sex
diff --git a/monad/src/main/java/com/iluwatar/monad/Validator.java b/monad/src/main/java/com/iluwatar/monad/Validator.java
index b5618f91c..2d1f1bdab 100644
--- a/monad/src/main/java/com/iluwatar/monad/Validator.java
+++ b/monad/src/main/java/com/iluwatar/monad/Validator.java
@@ -30,18 +30,18 @@ import java.util.function.Function;
import java.util.function.Predicate;
/**
- * Class representing Monad design pattern. Monad is a way of chaining operations on the
- * given object together step by step. In Validator each step results in either success or
- * failure indicator, giving a way of receiving each of them easily and finally getting
- * validated object or list of exceptions.
+ * Class representing Monad design pattern. Monad is a way of chaining operations on the given
+ * object together step by step. In Validator each step results in either success or failure
+ * indicator, giving a way of receiving each of them easily and finally getting validated object or
+ * list of exceptions.
*
* @param
- * In the following example, The {@link LoadBalancer} class represents the app's logic. It contains
- * a series of Servers, which can handle requests of type {@link Request}. Two instances of
+ *
+ * In the following example, The {@link LoadBalancer} class represents the app's logic. It
+ * contains a series of Servers, which can handle requests of type {@link Request}. Two instances of
* LoadBalacer are created. When a request is made to a server via the first LoadBalancer the state
* change in the first load balancer affects the second. So if the first LoadBalancer selects the
* Server 1, the second LoadBalancer on a new request will select the Second server. If a third
* LoadBalancer is created and a new request is made to it, then it will select the third server as
* the second load balancer has already selected the second server.
- *
- * .
- *
*/
public class App {
/**
- * Program entry point
- *
+ * Program entry point.
+ *
* @param args command line args
*/
public static void main(String[] args) {
diff --git a/monostate/src/main/java/com/iluwatar/monostate/LoadBalancer.java b/monostate/src/main/java/com/iluwatar/monostate/LoadBalancer.java
index ae590be5e..8546ae177 100644
--- a/monostate/src/main/java/com/iluwatar/monostate/LoadBalancer.java
+++ b/monostate/src/main/java/com/iluwatar/monostate/LoadBalancer.java
@@ -31,7 +31,6 @@ import java.util.List;
* receiving a new Request, it delegates the call to the servers in a Round Robin Fashion. Since all
* instances of the class share the same state, all instances will delegate to the same server on
* receiving a new Request.
- *
*/
public class LoadBalancer {
@@ -40,13 +39,13 @@ public class LoadBalancer {
static {
int id = 0;
- for (int port : new int[] {8080, 8081, 8082, 8083, 8084}) {
+ for (int port : new int[]{8080, 8081, 8082, 8083, 8084}) {
SERVERS.add(new Server("localhost", port, ++id));
}
}
/**
- * Add new server
+ * Add new server.
*/
public final void addServer(Server server) {
synchronized (SERVERS) {
@@ -64,7 +63,7 @@ public class LoadBalancer {
}
/**
- * Handle request
+ * Handle request.
*/
public synchronized void serverRequest(Request request) {
if (lastServedId >= SERVERS.size()) {
@@ -73,5 +72,5 @@ public class LoadBalancer {
Server server = SERVERS.get(lastServedId++);
server.serve(request);
}
-
+
}
diff --git a/monostate/src/main/java/com/iluwatar/monostate/Request.java b/monostate/src/main/java/com/iluwatar/monostate/Request.java
index 5a7429998..d7e4fcf8f 100644
--- a/monostate/src/main/java/com/iluwatar/monostate/Request.java
+++ b/monostate/src/main/java/com/iluwatar/monostate/Request.java
@@ -24,9 +24,7 @@
package com.iluwatar.monostate;
/**
- *
* The Request class. A {@link Server} can handle an instance of a Request.
- *
*/
public class Request {
diff --git a/monostate/src/main/java/com/iluwatar/monostate/Server.java b/monostate/src/main/java/com/iluwatar/monostate/Server.java
index fa809864c..cd08b2b29 100644
--- a/monostate/src/main/java/com/iluwatar/monostate/Server.java
+++ b/monostate/src/main/java/com/iluwatar/monostate/Server.java
@@ -27,10 +27,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- *
* The Server class. Each Server sits behind a LoadBalancer which delegates the call to the servers
* in a simplistic Round Robin fashion.
- *
*/
public class Server {
@@ -41,7 +39,7 @@ public class Server {
public final int id;
/**
- * Constructor
+ * Constructor.
*/
public Server(String host, int port, int id) {
this.host = host;
@@ -59,6 +57,6 @@ public class Server {
public void serve(Request request) {
LOGGER.info("Server ID {} associated to host : {} and port {}. Processed request with value {}",
- id, host, port, request.value);
+ id, host, port, request.value);
}
}
diff --git a/multiton/src/main/java/com/iluwatar/multiton/App.java b/multiton/src/main/java/com/iluwatar/multiton/App.java
index 8fb226625..eb3e0313f 100644
--- a/multiton/src/main/java/com/iluwatar/multiton/App.java
+++ b/multiton/src/main/java/com/iluwatar/multiton/App.java
@@ -27,26 +27,24 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- *
* Whereas Singleton design pattern introduces single globally 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.
- *
- * There is more than one way to implement the multiton design pattern. In the first 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.
- *
- * In the enum implementation {@link NazgulEnum} is the multiton. It is static and mutable because
- * of the way java supports enums.
*
+ * There is more than one way to implement the multiton design pattern. In the first 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.
+ *
+ * In the enum implementation {@link NazgulEnum} is the multiton. It is static and mutable
+ * because of the way java supports enums.
*/
public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
- * Program entry point
- *
+ * Program entry point.
+ *
* @param args command line args
*/
public static void main(String[] args) {
@@ -60,7 +58,7 @@ public class App {
LOGGER.info("ADUNAPHEL={}", Nazgul.getInstance(NazgulName.ADUNAPHEL));
LOGGER.info("REN={}", Nazgul.getInstance(NazgulName.REN));
LOGGER.info("UVATHA={}", Nazgul.getInstance(NazgulName.UVATHA));
-
+
// enum multiton
LOGGER.info("KHAMUL={}", NazgulEnum.KHAMUL);
LOGGER.info("MURAZOR={}", NazgulEnum.MURAZOR);
diff --git a/multiton/src/main/java/com/iluwatar/multiton/Nazgul.java b/multiton/src/main/java/com/iluwatar/multiton/Nazgul.java
index 52a25e00d..f55f85aca 100644
--- a/multiton/src/main/java/com/iluwatar/multiton/Nazgul.java
+++ b/multiton/src/main/java/com/iluwatar/multiton/Nazgul.java
@@ -27,9 +27,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
- *
* Nazgul is a Multiton class. Nazgul instances can be queried using {@link #getInstance} method.
- *
*/
public final class Nazgul {
diff --git a/multiton/src/main/java/com/iluwatar/multiton/NazgulEnum.java b/multiton/src/main/java/com/iluwatar/multiton/NazgulEnum.java
index f119ee68f..5b5c48d66 100644
--- a/multiton/src/main/java/com/iluwatar/multiton/NazgulEnum.java
+++ b/multiton/src/main/java/com/iluwatar/multiton/NazgulEnum.java
@@ -24,11 +24,10 @@
package com.iluwatar.multiton;
/**
- * enum based multiton implementation
- *
+ * enum based multiton implementation.
*/
public enum NazgulEnum {
-
+
KHAMUL, MURAZOR, DWAR, JI_INDUR, AKHORAHIL, HOARMURATH, ADUNAPHEL, REN, UVATHA;
}
diff --git a/multiton/src/main/java/com/iluwatar/multiton/NazgulName.java b/multiton/src/main/java/com/iluwatar/multiton/NazgulName.java
index 5fe2a5a0f..c7865dceb 100644
--- a/multiton/src/main/java/com/iluwatar/multiton/NazgulName.java
+++ b/multiton/src/main/java/com/iluwatar/multiton/NazgulName.java
@@ -24,9 +24,7 @@
package com.iluwatar.multiton;
/**
- *
* Each Nazgul has different {@link NazgulName}.
- *
*/
public enum NazgulName {
diff --git a/mute-idiom/src/main/java/com/iluwatar/mute/App.java b/mute-idiom/src/main/java/com/iluwatar/mute/App.java
index 28649e249..d4f140bf0 100644
--- a/mute-idiom/src/main/java/com/iluwatar/mute/App.java
+++ b/mute-idiom/src/main/java/com/iluwatar/mute/App.java
@@ -23,19 +23,17 @@
package com.iluwatar.mute;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.sql.SQLException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
- * Mute pattern is utilized when we need to suppress an exception due to an API flaw or in
- * situation when all we can do to handle the exception is to log it.
- * This pattern should not be used everywhere. It is very important to logically handle the
- * exceptions in a system, but some situations like the ones described above require this pattern,
- * so that we don't need to repeat
+ * Mute pattern is utilized when we need to suppress an exception due to an API flaw or in situation
+ * when all we can do to handle the exception is to log it. This pattern should not be used
+ * everywhere. It is very important to logically handle the exceptions in a system, but some
+ * situations like the ones described above require this pattern, so that we don't need to repeat
*
- * In this example we have two thieves who are taking beans from a jar.
- * Only one thief can take a bean at a time. This is ensured by a Mutex lock
- * which must be acquired in order to access the jar. Each thief attempts to
- * acquire the lock, take a bean and then release the lock. If the lock has
- * already been acquired, the thief will be prevented from continuing (blocked)
- * until the lock has been released. The thieves stop taking beans once there
- * are no beans left to take.
+ *
+ * In this example we have two thieves who are taking beans from a jar. Only one thief can take
+ * a bean at a time. This is ensured by a Mutex lock which must be acquired in order to access the
+ * jar. Each thief attempts to acquire the lock, take a bean and then release the lock. If the lock
+ * has already been acquired, the thief will be prevented from continuing (blocked) until the lock
+ * has been released. The thieves stop taking beans once there are no beans left to take.
*/
public class App {
/**
- * main method
+ * main method.
*/
public static void main(String[] args) {
Mutex mutex = new Mutex();
diff --git a/mutex/src/main/java/com/iluwatar/mutex/Jar.java b/mutex/src/main/java/com/iluwatar/mutex/Jar.java
index 427907f31..f68b266ad 100644
--- a/mutex/src/main/java/com/iluwatar/mutex/Jar.java
+++ b/mutex/src/main/java/com/iluwatar/mutex/Jar.java
@@ -24,9 +24,8 @@
package com.iluwatar.mutex;
/**
- * A Jar has a resource of beans which can only be accessed by a single Thief
- * (thread) at any one time. A Mutex lock is used to prevent more than one Thief
- * taking a bean simultaneously.
+ * A Jar has a resource of beans which can only be accessed by a single Thief (thread) at any one
+ * time. A Mutex lock is used to prevent more than one Thief taking a bean simultaneously.
*/
public class Jar {
diff --git a/mutex/src/main/java/com/iluwatar/mutex/Mutex.java b/mutex/src/main/java/com/iluwatar/mutex/Mutex.java
index a2ef71f11..6c62cc8ea 100644
--- a/mutex/src/main/java/com/iluwatar/mutex/Mutex.java
+++ b/mutex/src/main/java/com/iluwatar/mutex/Mutex.java
@@ -34,16 +34,15 @@ public class Mutex implements Lock {
private Object owner;
/**
- * Returns the current owner of the Mutex, or null if available
+ * Returns the current owner of the Mutex, or null if available.
*/
public Object getOwner() {
return owner;
}
-
+
/**
- * Method called by a thread to acquire the lock. If the lock has already
- * been acquired this will wait until the lock has been released to
- * re-attempt the acquire.
+ * Method called by a thread to acquire the lock. If the lock has already been acquired this will
+ * wait until the lock has been released to re-attempt the acquire.
*/
@Override
public synchronized void acquire() throws InterruptedException {
diff --git a/mutex/src/main/java/com/iluwatar/mutex/Thief.java b/mutex/src/main/java/com/iluwatar/mutex/Thief.java
index f88e46d96..29caba540 100644
--- a/mutex/src/main/java/com/iluwatar/mutex/Thief.java
+++ b/mutex/src/main/java/com/iluwatar/mutex/Thief.java
@@ -27,20 +27,20 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * Thief is a class which continually tries to acquire a jar and take a bean
- * from it. When the jar is empty the thief stops.
+ * Thief is a class which continually tries to acquire a jar and take a bean from it. When the jar
+ * is empty the thief stops.
*/
public class Thief extends Thread {
private static final Logger LOGGER = LoggerFactory.getLogger(Thief.class);
/**
- * The name of the thief.
+ * The name of the thief.
*/
private final String name;
-
+
/**
- * The jar
+ * The jar.
*/
private final Jar jar;
@@ -50,8 +50,7 @@ public class Thief extends Thread {
}
/**
- * In the run method the thief repeatedly tries to take a bean until none
- * are left.
+ * In the run method the thief repeatedly tries to take a bean until none are left.
*/
@Override
public void run() {
bind - that takes monadic object and a function from plain object to the
* monadic value and returns monadic value.
*
return - that takes plain type object and returns this object wrapped in a monadic value.
- *
*
every time we need to ignore an exception.
- *
*/
public class App {
@@ -53,7 +50,7 @@ public class App {
/**
* Program entry point.
- *
+ *
* @param args command line args.
* @throws Exception if any exception occurs
*/
@@ -65,7 +62,7 @@ public class App {
}
/*
- * Typically used when the API declares some exception but cannot do so. Usually a
+ * Typically used when the API declares some exception but cannot do so. Usually a
* signature mistake.In this example out is not supposed to throw exception as it is a
* ByteArrayOutputStream. So we utilize mute, which will throw AssertionError if unexpected
* exception occurs.
@@ -98,7 +95,7 @@ public class App {
private static Resource acquireResource() throws SQLException {
return new Resource() {
-
+
@Override
public void close() throws IOException {
throw new IOException("Error in closing resource: " + this);
diff --git a/mute-idiom/src/main/java/com/iluwatar/mute/CheckedRunnable.java b/mute-idiom/src/main/java/com/iluwatar/mute/CheckedRunnable.java
index d5fdaaec2..f15153d00 100644
--- a/mute-idiom/src/main/java/com/iluwatar/mute/CheckedRunnable.java
+++ b/mute-idiom/src/main/java/com/iluwatar/mute/CheckedRunnable.java
@@ -25,12 +25,12 @@ package com.iluwatar.mute;
/**
* A runnable which may throw exception on execution.
- *
*/
@FunctionalInterface
public interface CheckedRunnable {
/**
* Same as {@link Runnable#run()} with a possibility of exception in execution.
+ *
* @throws Exception if any exception occurs.
*/
void run() throws Exception;
diff --git a/mute-idiom/src/main/java/com/iluwatar/mute/Mute.java b/mute-idiom/src/main/java/com/iluwatar/mute/Mute.java
index 87a1f651e..30e1698d5 100644
--- a/mute-idiom/src/main/java/com/iluwatar/mute/Mute.java
+++ b/mute-idiom/src/main/java/com/iluwatar/mute/Mute.java
@@ -30,17 +30,18 @@ import java.io.IOException;
* A utility class that allows you to utilize mute idiom.
*/
public final class Mute {
-
+
// The constructor is never meant to be called.
- private Mute() {}
+ private Mute() {
+ }
/**
- * Executes the
* try {
@@ -45,7 +43,6 @@ import java.sql.SQLException;
* }
*
* runnable
and throws the exception occurred within a {@link AssertionError}.
- * This method should be utilized to mute the operations that are guaranteed not to throw an exception.
- * For instance {@link ByteArrayOutputStream#write(byte[])} declares in it's signature that it can throw
- * an {@link IOException}, but in reality it cannot. This is because the bulk write method is not overridden
- * in {@link ByteArrayOutputStream}.
- *
+ * Executes the runnable
and throws the exception occurred within a {@link
+ * AssertionError}. This method should be utilized to mute the operations that are guaranteed not
+ * to throw an exception. For instance {@link ByteArrayOutputStream#write(byte[])} declares in
+ * it's signature that it can throw an {@link IOException}, but in reality it cannot. This is
+ * because the bulk write method is not overridden in {@link ByteArrayOutputStream}.
+ *
* @param runnable a runnable that should never throw an exception on execution.
*/
public static void mute(CheckedRunnable runnable) {
@@ -52,11 +53,11 @@ public final class Mute {
}
/**
- * Executes the runnable
and logs the exception occurred on {@link System#err}.
- * This method should be utilized to mute the operations about which most you can do is log.
- * For instance while closing a connection to database, or cleaning up a resource,
- * all you can do is log the exception occurred.
- *
+ * Executes the runnable
and logs the exception occurred on {@link System#err}. This
+ * method should be utilized to mute the operations about which most you can do is log. For
+ * instance while closing a connection to database, or cleaning up a resource, all you can do is
+ * log the exception occurred.
+ *
* @param runnable a runnable that may throw an exception on execution.
*/
public static void loggedMute(CheckedRunnable runnable) {
diff --git a/mute-idiom/src/main/java/com/iluwatar/mute/Resource.java b/mute-idiom/src/main/java/com/iluwatar/mute/Resource.java
index a10fe4617..e56025ce4 100644
--- a/mute-idiom/src/main/java/com/iluwatar/mute/Resource.java
+++ b/mute-idiom/src/main/java/com/iluwatar/mute/Resource.java
@@ -26,9 +26,8 @@ package com.iluwatar.mute;
import java.io.Closeable;
/**
- * Represents any resource that the application might acquire and that must be closed
- * after it is utilized. Example of such resources can be a database connection, open
- * files, sockets.
+ * Represents any resource that the application might acquire and that must be closed after it is
+ * utilized. Example of such resources can be a database connection, open files, sockets.
*/
public interface Resource extends Closeable {
diff --git a/mutex/src/main/java/com/iluwatar/mutex/App.java b/mutex/src/main/java/com/iluwatar/mutex/App.java
index 827307d0f..e4a952ef9 100644
--- a/mutex/src/main/java/com/iluwatar/mutex/App.java
+++ b/mutex/src/main/java/com/iluwatar/mutex/App.java
@@ -25,19 +25,17 @@ package com.iluwatar.mutex;
/**
* A Mutex prevents multiple threads from accessing a resource simultaneously.
- *