diff --git a/ambassador/src/main/java/com/iluwatar/ambassador/App.java b/ambassador/src/main/java/com/iluwatar/ambassador/App.java index 6b0b048c8..c61ef4935 100644 --- a/ambassador/src/main/java/com/iluwatar/ambassador/App.java +++ b/ambassador/src/main/java/com/iluwatar/ambassador/App.java @@ -24,27 +24,26 @@ package com.iluwatar.ambassador; /** - * * The ambassador pattern creates a helper service that sends network requests on behalf of a * client. It is often used in cloud-based applications to offload features of a remote service. * - * An ambassador service can be thought of as an out-of-process proxy that is co-located with - * the client. Similar to the proxy design pattern, the ambassador service provides an interface - * for another remote service. In addition to the interface, the ambassador provides extra - * functionality and features, specifically offloaded common connectivity tasks. This usually - * consists of monitoring, logging, routing, security etc. This is extremely useful in - * legacy applications where the codebase is difficult to modify and allows for improvements - * in the application's networking capabilities. + *
An ambassador service can be thought of as an out-of-process proxy that is co-located with + * the client. Similar to the proxy design pattern, the ambassador service provides an interface for + * another remote service. In addition to the interface, the ambassador provides extra functionality + * and features, specifically offloaded common connectivity tasks. This usually consists of + * monitoring, logging, routing, security etc. This is extremely useful in legacy applications where + * the codebase is difficult to modify and allows for improvements in the application's networking + * capabilities. * - * In this example, we will the ({@link ServiceAmbassador}) class represents the ambassador while the + *
In this example, we will the ({@link ServiceAmbassador}) class represents the ambassador while
+ * the
* ({@link RemoteService}) class represents a remote application.
- *
*/
public class App {
/**
- * Entry point
- */
+ * Entry point.
+ */
public static void main(String[] args) {
Client host1 = new Client();
Client host2 = new Client();
diff --git a/ambassador/src/main/java/com/iluwatar/ambassador/Client.java b/ambassador/src/main/java/com/iluwatar/ambassador/Client.java
index fdadd71d2..60d0e164d 100644
--- a/ambassador/src/main/java/com/iluwatar/ambassador/Client.java
+++ b/ambassador/src/main/java/com/iluwatar/ambassador/Client.java
@@ -23,12 +23,11 @@
package com.iluwatar.ambassador;
+import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.slf4j.Logger;
-
/**
- * A simple Client
+ * A simple Client.
*/
public class Client {
diff --git a/ambassador/src/main/java/com/iluwatar/ambassador/RemoteService.java b/ambassador/src/main/java/com/iluwatar/ambassador/RemoteService.java
index 10da79d0b..349931595 100644
--- a/ambassador/src/main/java/com/iluwatar/ambassador/RemoteService.java
+++ b/ambassador/src/main/java/com/iluwatar/ambassador/RemoteService.java
@@ -23,12 +23,12 @@
package com.iluwatar.ambassador;
+import static java.lang.Thread.sleep;
+
import com.iluwatar.ambassador.util.RandomProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static java.lang.Thread.sleep;
-
/**
* A remote legacy application represented by a Singleton implementation.
*/
@@ -55,9 +55,11 @@ public class RemoteService implements RemoteServiceInterface {
RemoteService(RandomProvider randomProvider) {
this.randomProvider = randomProvider;
}
+
/**
- * Remote function takes a value and multiplies it by 10 taking a random amount of time.
- * Will sometimes return -1. This imitates connectivity issues a client might have to account for.
+ * Remote function takes a value and multiplies it by 10 taking a random amount of time. Will
+ * sometimes return -1. This imitates connectivity issues a client might have to account for.
+ *
* @param value integer value to be multiplied.
* @return if waitTime is less than {@link RemoteService#THRESHOLD}, it returns value * 10,
* otherwise {@link RemoteServiceInterface#FAILURE}.
diff --git a/ambassador/src/main/java/com/iluwatar/ambassador/ServiceAmbassador.java b/ambassador/src/main/java/com/iluwatar/ambassador/ServiceAmbassador.java
index 37b6970b4..4f191977c 100644
--- a/ambassador/src/main/java/com/iluwatar/ambassador/ServiceAmbassador.java
+++ b/ambassador/src/main/java/com/iluwatar/ambassador/ServiceAmbassador.java
@@ -23,17 +23,15 @@
package com.iluwatar.ambassador;
+import static java.lang.Thread.sleep;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static java.lang.Thread.sleep;
-
/**
- *
* ServiceAmbassador provides an interface for a ({@link Client}) to access ({@link RemoteService}).
* The interface adds logging, latency testing and usage of the service in a safe way that will not
* add stress to the remote service when connectivity issues occur.
- *
*/
public class ServiceAmbassador implements RemoteServiceInterface {
@@ -41,7 +39,8 @@ public class ServiceAmbassador implements RemoteServiceInterface {
private static final int RETRIES = 3;
private static final int DELAY_MS = 3000;
- ServiceAmbassador() {}
+ ServiceAmbassador() {
+ }
@Override
public long doRemoteFunction(int value) {
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 bc33494f7..a85a51ab8 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
@@ -23,35 +23,34 @@
package com.iluwatar.async.method.invocation;
+import java.util.concurrent.Callable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.concurrent.Callable;
-
/**
* This application demonstrates the async method invocation pattern. Key parts of the pattern are
- * AsyncResult
which is an intermediate container for an asynchronously evaluated value,
- * AsyncCallback
which can be provided to be executed on task completion and AsyncExecutor
- * that manages the execution of the async tasks.
- *
- * 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. - *
- * 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. - *
- * 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.
+ * AsyncResult
which is an intermediate container for an asynchronously evaluated
+ * value, AsyncCallback
which can be provided to be executed on task completion and
+ * AsyncExecutor
that manages the execution of the async tasks.
+ *
+ *
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. + * + *
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. + * + *
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.
*
* @see AsyncResult
* @see AsyncCallback
* @see AsyncExecutor
- *
* @see java.util.concurrent.FutureTask
* @see java.util.concurrent.CompletableFuture
* @see java.util.concurrent.ExecutorService
@@ -61,27 +60,29 @@ public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
- * Program entry point
+ * Program entry point.
*/
public static void main(String[] args) throws Exception {
// construct a new executor that will run async tasks
AsyncExecutor executor = new ThreadAsyncExecutor();
// start few async tasks with varying processing times, two last with callback handlers
- AsyncResult In this example implementation WashingMachine is an object that has two states in which it
+ * can be: ENABLED and WASHING. If the machine is ENABLED the state is changed into WASHING that any
+ * other thread can't invoke this action on this and then do the job. On the other hand if it have
+ * been already washing and any other thread execute wash() it can't do that once again and returns
+ * doing nothing.
*/
public class App {
@@ -47,6 +46,8 @@ public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
+ * Entry Point.
+ *
* @param args the command line arguments - not used
*/
public static void main(String... args) {
diff --git a/balking/src/main/java/com/iluwatar/balking/WashingMachine.java b/balking/src/main/java/com/iluwatar/balking/WashingMachine.java
index 044b1b6e9..c47c96c3a 100644
--- a/balking/src/main/java/com/iluwatar/balking/WashingMachine.java
+++ b/balking/src/main/java/com/iluwatar/balking/WashingMachine.java
@@ -23,13 +23,12 @@
package com.iluwatar.balking;
+import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.concurrent.TimeUnit;
-
/**
- * Washing machine class
+ * Washing machine class.
*/
public class WashingMachine {
@@ -38,7 +37,7 @@ public class WashingMachine {
private WashingMachineState washingMachineState;
/**
- * Creates a new instance of WashingMachine
+ * Creates a new instance of WashingMachine.
*/
public WashingMachine() {
this((interval, timeUnit, task) -> {
@@ -52,8 +51,8 @@ public class WashingMachine {
}
/**
- * Creates a new instance of WashingMachine using provided delayProvider. This constructor is used only for
- * unit testing purposes.
+ * Creates a new instance of WashingMachine using provided delayProvider. This constructor is used
+ * only for unit testing purposes.
*/
public WashingMachine(DelayProvider delayProvider) {
this.delayProvider = delayProvider;
@@ -65,17 +64,17 @@ public class WashingMachine {
}
/**
- * Method responsible for washing
- * if the object is in appropriate state
+ * Method responsible for washing if the object is in appropriate state.
*/
public void wash() {
synchronized (this) {
- LOGGER.info("{}: Actual machine state: {}", Thread.currentThread().getName(), getWashingMachineState());
- if (washingMachineState == WashingMachineState.WASHING) {
+ WashingMachineState machineState = getWashingMachineState();
+ LOGGER.info("{}: Actual machine state: {}", Thread.currentThread().getName(), machineState);
+ if (this.washingMachineState == WashingMachineState.WASHING) {
LOGGER.error("ERROR: Cannot wash if the machine has been already washing!");
return;
}
- washingMachineState = WashingMachineState.WASHING;
+ this.washingMachineState = WashingMachineState.WASHING;
}
LOGGER.info("{}: Doing the washing", Thread.currentThread().getName());
@@ -83,8 +82,7 @@ public class WashingMachine {
}
/**
- * Method responsible of ending the washing
- * by changing machine state
+ * Method responsible of ending the washing by changing machine state.
*/
public synchronized void endOfWashing() {
washingMachineState = WashingMachineState.ENABLED;
diff --git a/balking/src/main/java/com/iluwatar/balking/WashingMachineState.java b/balking/src/main/java/com/iluwatar/balking/WashingMachineState.java
index 0799d3fd8..664a4c0c9 100644
--- a/balking/src/main/java/com/iluwatar/balking/WashingMachineState.java
+++ b/balking/src/main/java/com/iluwatar/balking/WashingMachineState.java
@@ -24,10 +24,9 @@
package com.iluwatar.balking;
/**
- * WashingMachineState enum describes in which state machine is,
- * it can be enabled and ready to work as well as during washing
+ * WashingMachineState enum describes in which state machine is, it can be enabled and ready to work
+ * as well as during washing.
*/
-
public enum WashingMachineState {
ENABLED, WASHING
}
diff --git a/balking/src/test/java/com/iluwatar/balking/WashingMachineTest.java b/balking/src/test/java/com/iluwatar/balking/WashingMachineTest.java
index 8348f9256..7c6bd73ec 100644
--- a/balking/src/test/java/com/iluwatar/balking/WashingMachineTest.java
+++ b/balking/src/test/java/com/iluwatar/balking/WashingMachineTest.java
@@ -23,11 +23,10 @@
package com.iluwatar.balking;
-import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.concurrent.TimeUnit;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link WashingMachine}
diff --git a/bridge/src/main/java/com/iluwatar/bridge/App.java b/bridge/src/main/java/com/iluwatar/bridge/App.java
index 195f463cf..74104257e 100644
--- a/bridge/src/main/java/com/iluwatar/bridge/App.java
+++ b/bridge/src/main/java/com/iluwatar/bridge/App.java
@@ -27,25 +27,25 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- *
- * Composition over inheritance. The Bridge pattern can also be thought of as two layers of abstraction.
- * With Bridge, you can decouple an abstraction from its implementation so that the two can vary independently.
- *
- * In Bridge pattern both abstraction ({@link Weapon}) and implementation (
- * {@link Enchantment}) have their own class hierarchies. The interface of the implementations
- * can be changed without affecting the clients.
- *
- * In this example we have two class hierarchies. One of weapons and another one of enchantments. We can easily
- * combine any weapon with any enchantment using composition instead of creating deep class hierarchy.
- *
+ * Composition over inheritance. The Bridge pattern can also be thought of as two layers of
+ * abstraction. With Bridge, you can decouple an abstraction from its implementation so that the two
+ * can vary independently.
+ *
+ * In Bridge pattern both abstraction ({@link Weapon}) and implementation ( {@link Enchantment})
+ * have their own class hierarchies. The interface of the implementations can be changed without
+ * affecting the clients.
+ *
+ * In this example we have two class hierarchies. One of weapons and another one of
+ * enchantments. We can easily combine any weapon with any enchantment using composition instead of
+ * creating deep class hierarchy.
*/
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) {
diff --git a/bridge/src/main/java/com/iluwatar/bridge/Enchantment.java b/bridge/src/main/java/com/iluwatar/bridge/Enchantment.java
index 22acac8f9..8388fe91e 100644
--- a/bridge/src/main/java/com/iluwatar/bridge/Enchantment.java
+++ b/bridge/src/main/java/com/iluwatar/bridge/Enchantment.java
@@ -24,9 +24,7 @@
package com.iluwatar.bridge;
/**
- *
- * Enchantment
- *
+ * Enchantment.
*/
public interface Enchantment {
diff --git a/bridge/src/main/java/com/iluwatar/bridge/FlyingEnchantment.java b/bridge/src/main/java/com/iluwatar/bridge/FlyingEnchantment.java
index 14abe4c63..772456b88 100644
--- a/bridge/src/main/java/com/iluwatar/bridge/FlyingEnchantment.java
+++ b/bridge/src/main/java/com/iluwatar/bridge/FlyingEnchantment.java
@@ -27,9 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- *
- * FlyingEnchantment
- *
+ * FlyingEnchantment.
*/
public class FlyingEnchantment implements Enchantment {
diff --git a/bridge/src/main/java/com/iluwatar/bridge/Hammer.java b/bridge/src/main/java/com/iluwatar/bridge/Hammer.java
index 47f60613d..ffab542cb 100644
--- a/bridge/src/main/java/com/iluwatar/bridge/Hammer.java
+++ b/bridge/src/main/java/com/iluwatar/bridge/Hammer.java
@@ -27,9 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- *
- * Hammer
- *
+ * Hammer.
*/
public class Hammer implements Weapon {
diff --git a/bridge/src/main/java/com/iluwatar/bridge/SoulEatingEnchantment.java b/bridge/src/main/java/com/iluwatar/bridge/SoulEatingEnchantment.java
index 3655c7e97..ede98d2cb 100644
--- a/bridge/src/main/java/com/iluwatar/bridge/SoulEatingEnchantment.java
+++ b/bridge/src/main/java/com/iluwatar/bridge/SoulEatingEnchantment.java
@@ -27,9 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- *
- * SoulEatingEnchantment
- *
+ * SoulEatingEnchantment.
*/
public class SoulEatingEnchantment implements Enchantment {
diff --git a/bridge/src/main/java/com/iluwatar/bridge/Sword.java b/bridge/src/main/java/com/iluwatar/bridge/Sword.java
index ab6f4ab7f..71f87a55d 100644
--- a/bridge/src/main/java/com/iluwatar/bridge/Sword.java
+++ b/bridge/src/main/java/com/iluwatar/bridge/Sword.java
@@ -27,9 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- *
- * Sword
- *
+ * Sword.
*/
public class Sword implements Weapon {
diff --git a/bridge/src/main/java/com/iluwatar/bridge/Weapon.java b/bridge/src/main/java/com/iluwatar/bridge/Weapon.java
index b264dddca..76272332e 100644
--- a/bridge/src/main/java/com/iluwatar/bridge/Weapon.java
+++ b/bridge/src/main/java/com/iluwatar/bridge/Weapon.java
@@ -24,9 +24,7 @@
package com.iluwatar.bridge;
/**
- *
- * Weapon
- *
+ * Weapon.
*/
public interface Weapon {
diff --git a/builder/src/main/java/com/iluwatar/builder/App.java b/builder/src/main/java/com/iluwatar/builder/App.java
index f57e4d42f..ae29ee367 100644
--- a/builder/src/main/java/com/iluwatar/builder/App.java
+++ b/builder/src/main/java/com/iluwatar/builder/App.java
@@ -28,36 +28,33 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- *
* The intention of the Builder pattern is to find a solution to the telescoping constructor
* anti-pattern. The telescoping constructor anti-pattern occurs when the increase of object
* constructor parameter combination leads to an exponential list of constructors. Instead of using
* numerous constructors, the builder pattern uses another object, a builder, that receives each
* initialization parameter step by step and then returns the resulting constructed object at once.
- *
- * The Builder pattern has another benefit. It can be used for objects that contain flat data (html
- * code, SQL query, X.509 certificate...), that is to say, data that can't be easily edited. This
- * type of data cannot be edited step by step and must be edited at once. The best way to construct
- * such an object is to use a builder class.
- *
- * In this example we have the Builder pattern variation as described by Joshua Bloch in Effective
- * Java 2nd Edition.
- *
- * 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 Builder} class. {@link Hero.Builder}
- * 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 Builder} interface. When configuration is ready the build method is called to receive
- * the final {@link Hero} object.
- *
+ *
+ * The Builder pattern has another benefit. It can be used for objects that contain flat data
+ * (html code, SQL query, X.509 certificate...), that is to say, data that can't be easily edited.
+ * This type of data cannot be edited step by step and must be edited at once. The best way to
+ * construct such an object is to use a builder class.
+ *
+ * In this example we have the Builder pattern variation as described by Joshua Bloch in
+ * Effective Java 2nd Edition.
+ *
+ * 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 Builder} class. {@link Hero.Builder} 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 Builder} interface.
+ * When configuration is ready the build method is called to receive the final {@link Hero} object.
*/
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) {
diff --git a/builder/src/main/java/com/iluwatar/builder/Armor.java b/builder/src/main/java/com/iluwatar/builder/Armor.java
index 8cf57a361..2ab9bf831 100644
--- a/builder/src/main/java/com/iluwatar/builder/Armor.java
+++ b/builder/src/main/java/com/iluwatar/builder/Armor.java
@@ -24,9 +24,7 @@
package com.iluwatar.builder;
/**
- *
- * Armor enumeration
- *
+ * Armor enumeration.
*/
public enum Armor {
diff --git a/builder/src/main/java/com/iluwatar/builder/HairColor.java b/builder/src/main/java/com/iluwatar/builder/HairColor.java
index f94de3556..1beccff5e 100644
--- a/builder/src/main/java/com/iluwatar/builder/HairColor.java
+++ b/builder/src/main/java/com/iluwatar/builder/HairColor.java
@@ -24,9 +24,7 @@
package com.iluwatar.builder;
/**
- *
- * HairColor enumeration
- *
+ * HairColor enumeration.
*/
public enum HairColor {
diff --git a/builder/src/main/java/com/iluwatar/builder/HairType.java b/builder/src/main/java/com/iluwatar/builder/HairType.java
index 6eece1e37..3d16eb4d7 100644
--- a/builder/src/main/java/com/iluwatar/builder/HairType.java
+++ b/builder/src/main/java/com/iluwatar/builder/HairType.java
@@ -24,9 +24,7 @@
package com.iluwatar.builder;
/**
- *
- * HairType enumeration
- *
+ * HairType enumeration.
*/
public enum HairType {
diff --git a/builder/src/main/java/com/iluwatar/builder/Hero.java b/builder/src/main/java/com/iluwatar/builder/Hero.java
index a8f285b66..b33ce1007 100644
--- a/builder/src/main/java/com/iluwatar/builder/Hero.java
+++ b/builder/src/main/java/com/iluwatar/builder/Hero.java
@@ -24,9 +24,7 @@
package com.iluwatar.builder;
/**
- *
* Hero, the class with many parameters.
- *
*/
public final class Hero {
@@ -75,9 +73,9 @@ public final class Hero {
StringBuilder sb = new StringBuilder();
sb.append("This is a ")
- .append(profession)
- .append(" named ")
- .append(name);
+ .append(profession)
+ .append(" named ")
+ .append(name);
if (hairColor != null || hairType != null) {
sb.append(" with ");
if (hairColor != null) {
@@ -99,9 +97,7 @@ public final class Hero {
}
/**
- *
* The builder class.
- *
*/
public static class Builder {
@@ -113,7 +109,7 @@ public final class Hero {
private Weapon weapon;
/**
- * Constructor
+ * Constructor.
*/
public Builder(Profession profession, String name) {
if (profession == null || name == null) {
diff --git a/builder/src/main/java/com/iluwatar/builder/Profession.java b/builder/src/main/java/com/iluwatar/builder/Profession.java
index 1e22a1c67..23b1ac220 100644
--- a/builder/src/main/java/com/iluwatar/builder/Profession.java
+++ b/builder/src/main/java/com/iluwatar/builder/Profession.java
@@ -24,9 +24,7 @@
package com.iluwatar.builder;
/**
- *
- * Profession enumeration
- *
+ * Profession enumeration.
*/
public enum Profession {
diff --git a/builder/src/main/java/com/iluwatar/builder/Weapon.java b/builder/src/main/java/com/iluwatar/builder/Weapon.java
index 51ddeafbc..4ca78b95f 100644
--- a/builder/src/main/java/com/iluwatar/builder/Weapon.java
+++ b/builder/src/main/java/com/iluwatar/builder/Weapon.java
@@ -24,9 +24,7 @@
package com.iluwatar.builder;
/**
- *
- * Weapon enumeration
- *
+ * Weapon enumeration.
*/
public enum Weapon {