diff --git a/business-delegate/src/main/java/com/iluwatar/business/delegate/App.java b/business-delegate/src/main/java/com/iluwatar/business/delegate/App.java index 68e382c0f..fcb1acd1b 100644 --- a/business-delegate/src/main/java/com/iluwatar/business/delegate/App.java +++ b/business-delegate/src/main/java/com/iluwatar/business/delegate/App.java @@ -28,11 +28,11 @@ package com.iluwatar.business.delegate; * tiers. By using the pattern we gain loose coupling between the tiers. The Business Delegate * encapsulates knowledge about how to locate, connect to, and interact with the business objects * that make up the application. - * + * *
Some of the services the Business Delegate uses are instantiated directly, and some can be * retrieved through service lookups. The Business Delegate itself may contain business logic too * potentially tying together multiple service calls, exception handling, retrying etc. - * + * *
In this example the client ({@link Client}) utilizes a business delegate ( * {@link BusinessDelegate}) to execute a task. The Business Delegate then selects the appropriate * service and makes the service call. diff --git a/business-delegate/src/main/java/com/iluwatar/business/delegate/BusinessDelegate.java b/business-delegate/src/main/java/com/iluwatar/business/delegate/BusinessDelegate.java index cf2b25129..c39a2ad39 100644 --- a/business-delegate/src/main/java/com/iluwatar/business/delegate/BusinessDelegate.java +++ b/business-delegate/src/main/java/com/iluwatar/business/delegate/BusinessDelegate.java @@ -24,7 +24,7 @@ package com.iluwatar.business.delegate; /** - * BusinessDelegate separates the presentation and business tiers + * BusinessDelegate separates the presentation and business tiers. */ public class BusinessDelegate { diff --git a/business-delegate/src/main/java/com/iluwatar/business/delegate/BusinessLookup.java b/business-delegate/src/main/java/com/iluwatar/business/delegate/BusinessLookup.java index e7d8400d3..489caa23c 100644 --- a/business-delegate/src/main/java/com/iluwatar/business/delegate/BusinessLookup.java +++ b/business-delegate/src/main/java/com/iluwatar/business/delegate/BusinessLookup.java @@ -33,6 +33,8 @@ public class BusinessLookup { private JmsService jmsService; /** + * Gets service instance based on service type. + * * @param serviceType Type of service instance to be returned. * @return Service instance. */ diff --git a/business-delegate/src/main/java/com/iluwatar/business/delegate/BusinessService.java b/business-delegate/src/main/java/com/iluwatar/business/delegate/BusinessService.java index 6e08aca1f..3094d3f6e 100644 --- a/business-delegate/src/main/java/com/iluwatar/business/delegate/BusinessService.java +++ b/business-delegate/src/main/java/com/iluwatar/business/delegate/BusinessService.java @@ -24,9 +24,7 @@ package com.iluwatar.business.delegate; /** - * - * Interface for service implementations - * + * Interface for service implementations. */ public interface BusinessService { diff --git a/business-delegate/src/main/java/com/iluwatar/business/delegate/Client.java b/business-delegate/src/main/java/com/iluwatar/business/delegate/Client.java index c9c8950db..dcf4ce6b2 100644 --- a/business-delegate/src/main/java/com/iluwatar/business/delegate/Client.java +++ b/business-delegate/src/main/java/com/iluwatar/business/delegate/Client.java @@ -24,9 +24,7 @@ package com.iluwatar.business.delegate; /** - * - * Client utilizes BusinessDelegate to call the business tier - * + * Client utilizes BusinessDelegate to call the business tier. */ public class Client { diff --git a/business-delegate/src/main/java/com/iluwatar/business/delegate/EjbService.java b/business-delegate/src/main/java/com/iluwatar/business/delegate/EjbService.java index aa9457abf..6f39abb1a 100644 --- a/business-delegate/src/main/java/com/iluwatar/business/delegate/EjbService.java +++ b/business-delegate/src/main/java/com/iluwatar/business/delegate/EjbService.java @@ -27,9 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * - * Service EJB implementation - * + * Service EJB implementation. */ public class EjbService implements BusinessService { diff --git a/business-delegate/src/main/java/com/iluwatar/business/delegate/JmsService.java b/business-delegate/src/main/java/com/iluwatar/business/delegate/JmsService.java index 83abd9762..2317d783a 100644 --- a/business-delegate/src/main/java/com/iluwatar/business/delegate/JmsService.java +++ b/business-delegate/src/main/java/com/iluwatar/business/delegate/JmsService.java @@ -27,9 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * - * Service JMS implementation - * + * Service JMS implementation. */ public class JmsService implements BusinessService { diff --git a/business-delegate/src/main/java/com/iluwatar/business/delegate/ServiceType.java b/business-delegate/src/main/java/com/iluwatar/business/delegate/ServiceType.java index a09dde59c..87fd1562d 100644 --- a/business-delegate/src/main/java/com/iluwatar/business/delegate/ServiceType.java +++ b/business-delegate/src/main/java/com/iluwatar/business/delegate/ServiceType.java @@ -24,9 +24,7 @@ package com.iluwatar.business.delegate; /** - * - * Enumeration for service types - * + * Enumeration for service types. */ public enum ServiceType { diff --git a/bytecode/src/main/java/com/iluwatar/bytecode/App.java b/bytecode/src/main/java/com/iluwatar/bytecode/App.java index 9a5f66d88..165043c70 100644 --- a/bytecode/src/main/java/com/iluwatar/bytecode/App.java +++ b/bytecode/src/main/java/com/iluwatar/bytecode/App.java @@ -24,57 +24,59 @@ package com.iluwatar.bytecode; import com.iluwatar.bytecode.util.InstructionConverterUtil; +import java.util.Stack; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * The intention of Bytecode pattern is to give behavior the flexibility of data by encoding it as instructions - * for a virtual machine. - * An instruction set defines the low-level operations that can be performed. A series of instructions is encoded as - * a sequence of bytes. A virtual machine executes these instructions one at a time, - * using a stack for intermediate values. By combining instructions, complex high-level behavior can be defined. - * - * This pattern should be used when there is a need to define high number of behaviours and implementation engine - * is not a good choice because - * It is too lowe level - * Iterating on it takes too long due to slow compile times or other tooling issues. - * It has too much trust. If you want to ensure the behavior being defined can’t break the game, - * you need to sandbox it from the rest of the codebase. + * The intention of Bytecode pattern is to give behavior the flexibility of data by encoding it as + * instructions for a virtual machine. An instruction set defines the low-level operations that can + * be performed. A series of instructions is encoded as a sequence of bytes. A virtual machine + * executes these instructions one at a time, using a stack for intermediate values. By combining + * instructions, complex high-level behavior can be defined. * + *
This pattern should be used when there is a need to define high number of behaviours and
+ * implementation engine is not a good choice because It is too lowe level Iterating on it takes too
+ * long due to slow compile times or other tooling issues. It has too much trust. If you want to
+ * ensure the behavior being defined can’t break the game, you need to sandbox it from the rest of
+ * the codebase.
*/
public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
- * Main app method
+ * Main app method.
+ *
* @param args command line args
*/
public static void main(String[] args) {
- VirtualMachine vm = new VirtualMachine();
Wizard wizard = new Wizard();
wizard.setHealth(45);
wizard.setAgility(7);
wizard.setWisdom(11);
+
+ VirtualMachine vm = new VirtualMachine();
vm.getWizards()[0] = wizard;
interpretInstruction("LITERAL 0", vm);
- interpretInstruction( "LITERAL 0", vm);
- interpretInstruction( "GET_HEALTH", vm);
- interpretInstruction( "LITERAL 0", vm);
- interpretInstruction( "GET_AGILITY", vm);
- interpretInstruction( "LITERAL 0", vm);
- interpretInstruction( "GET_WISDOM ", vm);
- interpretInstruction( "ADD", vm);
- interpretInstruction( "LITERAL 2", vm);
- interpretInstruction( "DIVIDE", vm);
- interpretInstruction( "ADD", vm);
- interpretInstruction( "SET_HEALTH", vm);
+ interpretInstruction("LITERAL 0", vm);
+ interpretInstruction("GET_HEALTH", vm);
+ interpretInstruction("LITERAL 0", vm);
+ interpretInstruction("GET_AGILITY", vm);
+ interpretInstruction("LITERAL 0", vm);
+ interpretInstruction("GET_WISDOM ", vm);
+ interpretInstruction("ADD", vm);
+ interpretInstruction("LITERAL 2", vm);
+ interpretInstruction("DIVIDE", vm);
+ interpretInstruction("ADD", vm);
+ interpretInstruction("SET_HEALTH", vm);
}
private static void interpretInstruction(String instruction, VirtualMachine vm) {
InstructionConverterUtil converter = new InstructionConverterUtil();
vm.execute(converter.convertToByteCode(instruction));
- LOGGER.info(instruction + String.format("%" + (12 - instruction.length()) + "s", "" ) + vm.getStack());
+ Stack
- * In this example, the user account ({@link UserAccount}) entity is used as the underlying
+ *
+ * In this example, the user account ({@link UserAccount}) entity is used as the underlying
* application data. The cache itself is implemented as an internal (Java) data structure. It adopts
* a Least-Recently-Used (LRU) strategy for evicting data from itself when its full. The four
* strategies are individually tested. The testing of the cache is restricted towards saving and
@@ -60,7 +59,6 @@ import org.slf4j.LoggerFactory;
* @see CacheStore
* @see LruCache
* @see CachingPolicy
- *
*/
public class App {
@@ -68,15 +66,15 @@ public class App {
/**
- * Program entry point
+ * Program entry point.
*
* @param args command line args
*/
public static void main(String[] args) {
AppManager.initDb(false); // VirtualDB (instead of MongoDB) was used in running the JUnit tests
- // and the App class to avoid Maven compilation errors. Set flag to
- // true to run the tests with MongoDB (provided that MongoDB is
- // installed and socket connection is open).
+ // and the App class to avoid Maven compilation errors. Set flag to
+ // true to run the tests with MongoDB (provided that MongoDB is
+ // installed and socket connection is open).
AppManager.initCacheCapacity(3);
App app = new App();
app.useReadAndWriteThroughStrategy();
@@ -86,7 +84,7 @@ public class App {
}
/**
- * Read-through and write-through
+ * Read-through and write-through.
*/
public void useReadAndWriteThroughStrategy() {
LOGGER.info("# CachingPolicy.THROUGH");
@@ -101,7 +99,7 @@ public class App {
}
/**
- * Read-through and write-around
+ * Read-through and write-around.
*/
public void useReadThroughAndWriteAroundStrategy() {
LOGGER.info("# CachingPolicy.AROUND");
@@ -123,7 +121,7 @@ public class App {
}
/**
- * Read-through and write-behind
+ * Read-through and write-behind.
*/
public void useReadThroughAndWriteBehindStrategy() {
LOGGER.info("# CachingPolicy.BEHIND");
@@ -147,7 +145,7 @@ public class App {
}
/**
- * Cache-Aside
+ * Cache-Aside.
*/
public void useCacheAsideStategy() {
LOGGER.info("# CachingPolicy.ASIDE");
diff --git a/caching/src/main/java/com/iluwatar/caching/AppManager.java b/caching/src/main/java/com/iluwatar/caching/AppManager.java
index 6939c6b80..ec7f0df69 100644
--- a/caching/src/main/java/com/iluwatar/caching/AppManager.java
+++ b/caching/src/main/java/com/iluwatar/caching/AppManager.java
@@ -26,13 +26,11 @@ package com.iluwatar.caching;
import java.text.ParseException;
/**
- *
* AppManager helps to bridge the gap in communication between the main class and the application's
* back-end. DB connection is initialized through this class. The chosen caching strategy/policy is
* also initialized here. Before the cache can be used, the size of the cache has to be set.
* Depending on the chosen caching policy, AppManager will call the appropriate function in the
* CacheStore class.
- *
*/
public final class AppManager {
@@ -42,7 +40,6 @@ public final class AppManager {
}
/**
- *
* Developer/Tester is able to choose whether the application should use MongoDB as its underlying
* data storage or a simple Java data structure to (temporarily) store the data/objects during
* runtime.
@@ -60,7 +57,7 @@ public final class AppManager {
}
/**
- * Initialize caching policy
+ * Initialize caching policy.
*/
public static void initCachingPolicy(CachingPolicy policy) {
cachingPolicy = policy;
@@ -75,7 +72,7 @@ public final class AppManager {
}
/**
- * Find user account
+ * Find user account.
*/
public static UserAccount find(String userId) {
if (cachingPolicy == CachingPolicy.THROUGH || cachingPolicy == CachingPolicy.AROUND) {
@@ -89,7 +86,7 @@ public final class AppManager {
}
/**
- * Save user account
+ * Save user account.
*/
public static void save(UserAccount userAccount) {
if (cachingPolicy == CachingPolicy.THROUGH) {
@@ -108,7 +105,7 @@ public final class AppManager {
}
/**
- * Cache-Aside save user account helper
+ * Cache-Aside save user account helper.
*/
private static void saveAside(UserAccount userAccount) {
DbManager.updateDb(userAccount);
@@ -116,7 +113,7 @@ public final class AppManager {
}
/**
- * Cache-Aside find user account helper
+ * Cache-Aside find user account helper.
*/
private static UserAccount findAside(String userId) {
UserAccount userAccount = CacheStore.get(userId);
diff --git a/caching/src/main/java/com/iluwatar/caching/CacheStore.java b/caching/src/main/java/com/iluwatar/caching/CacheStore.java
index e221f16e7..17a733188 100644
--- a/caching/src/main/java/com/iluwatar/caching/CacheStore.java
+++ b/caching/src/main/java/com/iluwatar/caching/CacheStore.java
@@ -23,15 +23,12 @@
package com.iluwatar.caching;
+import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.List;
-
/**
- *
* The caching strategies are implemented in this class.
- *
*/
public class CacheStore {
@@ -43,7 +40,7 @@ public class CacheStore {
}
/**
- * Init cache capacity
+ * Init cache capacity.
*/
public static void initCapacity(int capacity) {
if (cache == null) {
@@ -54,7 +51,7 @@ public class CacheStore {
}
/**
- * Get user account using read-through cache
+ * Get user account using read-through cache.
*/
public static UserAccount readThrough(String userId) {
if (cache.contains(userId)) {
@@ -68,7 +65,7 @@ public class CacheStore {
}
/**
- * Get user account using write-through cache
+ * Get user account using write-through cache.
*/
public static void writeThrough(UserAccount userAccount) {
if (cache.contains(userAccount.getUserId())) {
@@ -80,20 +77,20 @@ public class CacheStore {
}
/**
- * Get user account using write-around cache
+ * Get user account using write-around cache.
*/
public static void writeAround(UserAccount userAccount) {
if (cache.contains(userAccount.getUserId())) {
DbManager.updateDb(userAccount);
cache.invalidate(userAccount.getUserId()); // Cache data has been updated -- remove older
- // version from cache.
+ // version from cache.
} else {
DbManager.writeToDb(userAccount);
}
}
/**
- * Get user account using read-through cache with write-back policy
+ * Get user account using read-through cache with write-back policy.
*/
public static UserAccount readThroughWithWriteBackPolicy(String userId) {
if (cache.contains(userId)) {
@@ -112,7 +109,7 @@ public class CacheStore {
}
/**
- * Set user account
+ * Set user account.
*/
public static void writeBehind(UserAccount userAccount) {
if (cache.isFull() && !cache.contains(userAccount.getUserId())) {
@@ -124,7 +121,7 @@ public class CacheStore {
}
/**
- * Clears cache
+ * Clears cache.
*/
public static void clearCache() {
if (cache != null) {
@@ -147,7 +144,7 @@ public class CacheStore {
}
/**
- * Print user accounts
+ * Print user accounts.
*/
public static String print() {
List DBManager handles the communication with the underlying data store i.e. Database. It contains
+ * the implemented methods for querying, inserting, and updating data. MongoDB was used as the
+ * database for the application. DBManager handles the communication with the underlying data store i.e. Database. It contains the
- * implemented methods for querying, inserting, and updating data. MongoDB was used as the database
- * for the application. Developer/Tester is able to choose whether the application should use MongoDB as its underlying
- * data storage (connect()) or a simple Java data structure to (temporarily) store the data/objects
- * during runtime (createVirtualDB()). Developer/Tester is able to choose whether the application should use MongoDB as its
+ * underlying data storage (connect()) or a simple Java data structure to (temporarily) store the
+ * data/objects during runtime (createVirtualDB()).