diff --git a/dao/src/main/java/com/iluwatar/dao/App.java b/dao/src/main/java/com/iluwatar/dao/App.java index 78406208a..9faa8577a 100644 --- a/dao/src/main/java/com/iluwatar/dao/App.java +++ b/dao/src/main/java/com/iluwatar/dao/App.java @@ -26,12 +26,9 @@ package com.iluwatar.dao; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; -import java.util.ArrayList; import java.util.List; import java.util.stream.Stream; - import javax.sql.DataSource; - import org.h2.jdbcx.JdbcDataSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,27 +41,25 @@ import org.slf4j.LoggerFactory; * application needs, in terms of domain-specific objects and data types (the public interface of * the DAO), from how these needs can be satisfied with a specific DBMS. * - *

With the DAO pattern, we can use various method calls to retrieve/add/delete/update data - * without directly interacting with the data source. The below example demonstrates basic CRUD + *

With the DAO pattern, we can use various method calls to retrieve/add/delete/update data + * without directly interacting with the data source. The below example demonstrates basic CRUD * operations: select, add, update, and delete. - * - * */ public class App { private static final String DB_URL = "jdbc:h2:~/dao"; private static Logger log = LoggerFactory.getLogger(App.class); private static final String ALL_CUSTOMERS = "customerDao.getAllCustomers(): "; - + /** * Program entry point. - * + * * @param args command line args. - * @throws Exception if any error occurs. + * @throws Exception if any error occurs. */ public static void main(final String[] args) throws Exception { final CustomerDao inMemoryDao = new InMemoryCustomerDao(); performOperationsUsing(inMemoryDao); - + final DataSource dataSource = createDataSource(); createSchema(dataSource); final CustomerDao dbDao = new DbCustomerDao(dataSource); @@ -74,14 +69,14 @@ public class App { private static void deleteSchema(DataSource dataSource) throws SQLException { try (Connection connection = dataSource.getConnection(); - Statement statement = connection.createStatement()) { + Statement statement = connection.createStatement()) { statement.execute(CustomerSchemaSql.DELETE_SCHEMA_SQL); } } private static void createSchema(DataSource dataSource) throws SQLException { try (Connection connection = dataSource.getConnection(); - Statement statement = connection.createStatement()) { + Statement statement = connection.createStatement()) { statement.execute(CustomerSchemaSql.CREATE_SCHEMA_SQL); } } @@ -121,7 +116,7 @@ public class App { /** * Generate customers. - * + * * @return list of customers. */ public static List generateSampleCustomers() { diff --git a/dao/src/main/java/com/iluwatar/dao/CustomException.java b/dao/src/main/java/com/iluwatar/dao/CustomException.java index 3c1ec7373..3da6ab20e 100644 --- a/dao/src/main/java/com/iluwatar/dao/CustomException.java +++ b/dao/src/main/java/com/iluwatar/dao/CustomException.java @@ -24,20 +24,19 @@ package com.iluwatar.dao; /** - * - * Custom exception - * + * Custom exception. */ public class CustomException extends Exception { private static final long serialVersionUID = 1L; - public CustomException() {} + public CustomException() { + } public CustomException(String message) { super(message); } - + public CustomException(String message, Throwable cause) { super(message, cause); } diff --git a/dao/src/main/java/com/iluwatar/dao/Customer.java b/dao/src/main/java/com/iluwatar/dao/Customer.java index 593aacaf3..dd84426eb 100644 --- a/dao/src/main/java/com/iluwatar/dao/Customer.java +++ b/dao/src/main/java/com/iluwatar/dao/Customer.java @@ -25,7 +25,6 @@ package com.iluwatar.dao; /** * A customer POJO that represents the data that will be read from the data source. - * */ public class Customer { diff --git a/dao/src/main/java/com/iluwatar/dao/CustomerDao.java b/dao/src/main/java/com/iluwatar/dao/CustomerDao.java index 7ff9a8e4e..f5dc573ba 100644 --- a/dao/src/main/java/com/iluwatar/dao/CustomerDao.java +++ b/dao/src/main/java/com/iluwatar/dao/CustomerDao.java @@ -28,37 +28,43 @@ import java.util.stream.Stream; /** * In an application the Data Access Object (DAO) is a part of Data access layer. It is an object - * that provides an interface to some type of persistence mechanism. By mapping application calls - * to the persistence layer, DAO provides some specific data operations without exposing details - * of the database. This isolation supports the Single responsibility principle. It separates what - * data accesses the application needs, in terms of domain-specific objects and data types - * (the public interface of the DAO), from how these needs can be satisfied with a specific DBMS, - * database schema, etc. - * - *

Any change in the way data is stored and retrieved will not change the client code as the + * that provides an interface to some type of persistence mechanism. By mapping application calls to + * the persistence layer, DAO provides some specific data operations without exposing details of the + * database. This isolation supports the Single responsibility principle. It separates what data + * accesses the application needs, in terms of domain-specific objects and data types (the public + * interface of the DAO), from how these needs can be satisfied with a specific DBMS, database + * schema, etc. + * + *

Any change in the way data is stored and retrieved will not change the client code as the * client will be using interface and need not worry about exact source. - * + * * @see InMemoryCustomerDao * @see DbCustomerDao */ public interface CustomerDao { /** - * @return all the customers as a stream. The stream may be lazily or eagerly evaluated based - * on the implementation. The stream must be closed after use. + * Get all customers. + * + * @return all the customers as a stream. The stream may be lazily or eagerly evaluated based on + * the implementation. The stream must be closed after use. * @throws Exception if any error occurs. */ Stream getAll() throws Exception; - + /** + * Get customer as Optional by id. + * * @param id unique identifier of the customer. - * @return an optional with customer if a customer with unique identifier id - * exists, empty optional otherwise. + * @return an optional with customer if a customer with unique identifier id exists, + * empty optional otherwise. * @throws Exception if any error occurs. */ Optional getById(int id) throws Exception; /** + * Add a customer. + * * @param customer the customer to be added. * @return true if customer is successfully added, false if customer already exists. * @throws Exception if any error occurs. @@ -66,6 +72,8 @@ public interface CustomerDao { boolean add(Customer customer) throws Exception; /** + * Update a customer. + * * @param customer the customer to be updated. * @return true if customer exists and is successfully updated, false otherwise. * @throws Exception if any error occurs. @@ -73,6 +81,8 @@ public interface CustomerDao { boolean update(Customer customer) throws Exception; /** + * Delete a customer. + * * @param customer the customer to be deleted. * @return true if customer exists and is successfully deleted, false otherwise. * @throws Exception if any error occurs. diff --git a/dao/src/main/java/com/iluwatar/dao/CustomerSchemaSql.java b/dao/src/main/java/com/iluwatar/dao/CustomerSchemaSql.java index f05b9de21..633a65860 100644 --- a/dao/src/main/java/com/iluwatar/dao/CustomerSchemaSql.java +++ b/dao/src/main/java/com/iluwatar/dao/CustomerSchemaSql.java @@ -24,14 +24,16 @@ package com.iluwatar.dao; /** - * Customer Schema SQL Class + * Customer Schema SQL Class. */ public final class CustomerSchemaSql { - private CustomerSchemaSql() {} + private CustomerSchemaSql() { + } - public static final String CREATE_SCHEMA_SQL = "CREATE TABLE CUSTOMERS (ID NUMBER, FNAME VARCHAR(100), " - + "LNAME VARCHAR(100))"; + public static final String CREATE_SCHEMA_SQL = + "CREATE TABLE CUSTOMERS (ID NUMBER, FNAME VARCHAR(100), " + + "LNAME VARCHAR(100))"; public static final String DELETE_SCHEMA_SQL = "DROP TABLE CUSTOMERS"; diff --git a/dao/src/main/java/com/iluwatar/dao/DbCustomerDao.java b/dao/src/main/java/com/iluwatar/dao/DbCustomerDao.java index 12e3acb20..689a889fd 100644 --- a/dao/src/main/java/com/iluwatar/dao/DbCustomerDao.java +++ b/dao/src/main/java/com/iluwatar/dao/DbCustomerDao.java @@ -23,9 +23,6 @@ package com.iluwatar.dao; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -36,12 +33,12 @@ import java.util.Spliterators; import java.util.function.Consumer; import java.util.stream.Stream; import java.util.stream.StreamSupport; - import javax.sql.DataSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * An implementation of {@link CustomerDao} that persists customers in RDBMS. - * */ public class DbCustomerDao implements CustomerDao { @@ -50,9 +47,9 @@ public class DbCustomerDao implements CustomerDao { private final DataSource dataSource; /** - * Creates an instance of {@link DbCustomerDao} which uses provided dataSource - * to store and retrieve customer information. - * + * Creates an instance of {@link DbCustomerDao} which uses provided dataSource to + * store and retrieve customer information. + * * @param dataSource a non-null dataSource. */ public DbCustomerDao(DataSource dataSource) { @@ -60,9 +57,11 @@ public class DbCustomerDao implements CustomerDao { } /** - * @return a lazily populated stream of customers. Note the stream returned must be closed to - * free all the acquired resources. The stream keeps an open connection to the database till - * it is complete or is closed manually. + * Get all customers as Java Stream. + * + * @return a lazily populated stream of customers. Note the stream returned must be closed to free + * all the acquired resources. The stream keeps an open connection to the database till it is + * complete or is closed manually. */ @Override public Stream getAll() throws Exception { @@ -70,9 +69,10 @@ public class DbCustomerDao implements CustomerDao { Connection connection; try { connection = getConnection(); - PreparedStatement statement = connection.prepareStatement("SELECT * FROM CUSTOMERS"); // NOSONAR + PreparedStatement statement = + connection.prepareStatement("SELECT * FROM CUSTOMERS"); // NOSONAR ResultSet resultSet = statement.executeQuery(); // NOSONAR - return StreamSupport.stream(new Spliterators.AbstractSpliterator(Long.MAX_VALUE, + return StreamSupport.stream(new Spliterators.AbstractSpliterator(Long.MAX_VALUE, Spliterator.ORDERED) { @Override @@ -108,8 +108,8 @@ public class DbCustomerDao implements CustomerDao { } private Customer createCustomer(ResultSet resultSet) throws SQLException { - return new Customer(resultSet.getInt("ID"), - resultSet.getString("FNAME"), + return new Customer(resultSet.getInt("ID"), + resultSet.getString("FNAME"), resultSet.getString("LNAME")); } @@ -122,8 +122,8 @@ public class DbCustomerDao implements CustomerDao { ResultSet resultSet = null; try (Connection connection = getConnection(); - PreparedStatement statement = - connection.prepareStatement("SELECT * FROM CUSTOMERS WHERE ID = ?")) { + PreparedStatement statement = + connection.prepareStatement("SELECT * FROM CUSTOMERS WHERE ID = ?")) { statement.setInt(1, id); resultSet = statement.executeQuery(); @@ -151,8 +151,8 @@ public class DbCustomerDao implements CustomerDao { } try (Connection connection = getConnection(); - PreparedStatement statement = - connection.prepareStatement("INSERT INTO CUSTOMERS VALUES (?,?,?)")) { + PreparedStatement statement = + connection.prepareStatement("INSERT INTO CUSTOMERS VALUES (?,?,?)")) { statement.setInt(1, customer.getId()); statement.setString(2, customer.getFirstName()); statement.setString(3, customer.getLastName()); @@ -169,8 +169,9 @@ public class DbCustomerDao implements CustomerDao { @Override public boolean update(Customer customer) throws Exception { try (Connection connection = getConnection(); - PreparedStatement statement = - connection.prepareStatement("UPDATE CUSTOMERS SET FNAME = ?, LNAME = ? WHERE ID = ?")) { + PreparedStatement statement = + connection + .prepareStatement("UPDATE CUSTOMERS SET FNAME = ?, LNAME = ? WHERE ID = ?")) { statement.setString(1, customer.getFirstName()); statement.setString(2, customer.getLastName()); statement.setInt(3, customer.getId()); @@ -186,8 +187,8 @@ public class DbCustomerDao implements CustomerDao { @Override public boolean delete(Customer customer) throws Exception { try (Connection connection = getConnection(); - PreparedStatement statement = - connection.prepareStatement("DELETE FROM CUSTOMERS WHERE ID = ?")) { + PreparedStatement statement = + connection.prepareStatement("DELETE FROM CUSTOMERS WHERE ID = ?")) { statement.setInt(1, customer.getId()); return statement.executeUpdate() > 0; } catch (SQLException ex) { diff --git a/dao/src/main/java/com/iluwatar/dao/InMemoryCustomerDao.java b/dao/src/main/java/com/iluwatar/dao/InMemoryCustomerDao.java index b6621ba39..6dbfa367a 100644 --- a/dao/src/main/java/com/iluwatar/dao/InMemoryCustomerDao.java +++ b/dao/src/main/java/com/iluwatar/dao/InMemoryCustomerDao.java @@ -29,8 +29,8 @@ import java.util.Optional; import java.util.stream.Stream; /** - * An in memory implementation of {@link CustomerDao}, which stores the customers in JVM memory - * and data is lost when the application exits. + * An in memory implementation of {@link CustomerDao}, which stores the customers in JVM memory and + * data is lost when the application exits. *
* This implementation is useful as temporary database or for testing. */ @@ -56,7 +56,7 @@ public class InMemoryCustomerDao implements CustomerDao { if (getById(customer.getId()).isPresent()) { return false; } - + idToCustomer.put(customer.getId(), customer); return true; } diff --git a/data-bus/src/main/java/com/iluwatar/databus/App.java b/data-bus/src/main/java/com/iluwatar/databus/App.java index b645dbd34..da4c6f07e 100644 --- a/data-bus/src/main/java/com/iluwatar/databus/App.java +++ b/data-bus/src/main/java/com/iluwatar/databus/App.java @@ -28,35 +28,33 @@ import com.iluwatar.databus.data.StartingData; import com.iluwatar.databus.data.StoppingData; import com.iluwatar.databus.members.MessageCollectorMember; import com.iluwatar.databus.members.StatusMember; - import java.time.LocalDateTime; /** - * The Data Bus pattern - *

- * @see http://wiki.c2.com/?DataBusPattern - *

The Data-Bus pattern provides a method where different parts of an application may - * pass messages between each other without needing to be aware of the other's existence.

- *

Similar to the {@code ObserverPattern}, members register themselves with the {@link DataBus} - * and may then receive each piece of data that is published to the Data-Bus. The member - * may react to any given message or not.

- *

It allows for Many-to-Many distribution of data, as there may be any number of - * publishers to a Data-Bus, and any number of members receiving the data. All members - * will receive the same data, the order each receives a given piece of data, is an - * implementation detail.

- *

Members may unsubscribe from the Data-Bus to stop receiving data.

- *

This example of the pattern implements a Synchronous Data-Bus, meaning that - * when data is published to the Data-Bus, the publish method will not return until - * all members have received the data and returned.

- *

The {@link DataBus} class is a Singleton.

- *

Members of the Data-Bus must implement the {@link Member} interface.

- *

Data to be published via the Data-Bus must implement the {@link DataType} interface.

- *

The {@code data} package contains example {@link DataType} implementations.

- *

The {@code members} package contains example {@link Member} implementations.

- *

The {@link StatusMember} demonstrates using the DataBus to publish a message - * to the Data-Bus when it receives a message.

+ * The Data Bus pattern. * * @author Paul Campbell (pcampbell@kemitix.net) + * @see http://wiki.c2.com/?DataBusPattern + *

The Data-Bus pattern provides a method where different parts of an application may + * pass messages between each other without needing to be aware of the other's existence.

+ *

Similar to the {@code ObserverPattern}, members register themselves with the {@link + * DataBus} and may then receive each piece of data that is published to the Data-Bus. The + * member may react to any given message or not.

+ *

It allows for Many-to-Many distribution of data, as there may be any number of + * publishers to a Data-Bus, and any number of members receiving the data. All members will + * receive the same data, the order each receives a given piece of data, is an implementation + * detail.

+ *

Members may unsubscribe from the Data-Bus to stop receiving data.

+ *

This example of the pattern implements a Synchronous Data-Bus, meaning that + * when data is published to the Data-Bus, the publish method will not return until all members + * have received the data and returned.

+ *

The {@link DataBus} class is a Singleton.

+ *

Members of the Data-Bus must implement the {@link Member} interface.

+ *

Data to be published via the Data-Bus must implement the {@link DataType} interface.

+ *

The {@code data} package contains example {@link DataType} implementations.

+ *

The {@code members} package contains example {@link Member} implementations.

+ *

The {@link StatusMember} demonstrates using the DataBus to publish a message + * to the Data-Bus when it receives a message.

*/ class App { diff --git a/data-bus/src/main/java/com/iluwatar/databus/data/StartingData.java b/data-bus/src/main/java/com/iluwatar/databus/data/StartingData.java index 52de8b1f2..bd1f4c20f 100644 --- a/data-bus/src/main/java/com/iluwatar/databus/data/StartingData.java +++ b/data-bus/src/main/java/com/iluwatar/databus/data/StartingData.java @@ -25,7 +25,6 @@ package com.iluwatar.databus.data; import com.iluwatar.databus.AbstractDataType; import com.iluwatar.databus.DataType; - import java.time.LocalDateTime; /** diff --git a/data-bus/src/main/java/com/iluwatar/databus/data/StoppingData.java b/data-bus/src/main/java/com/iluwatar/databus/data/StoppingData.java index 5ca66743b..41bb67482 100644 --- a/data-bus/src/main/java/com/iluwatar/databus/data/StoppingData.java +++ b/data-bus/src/main/java/com/iluwatar/databus/data/StoppingData.java @@ -25,7 +25,6 @@ package com.iluwatar.databus.data; import com.iluwatar.databus.AbstractDataType; import com.iluwatar.databus.DataType; - import java.time.LocalDateTime; /** diff --git a/data-bus/src/main/java/com/iluwatar/databus/members/MessageCollectorMember.java b/data-bus/src/main/java/com/iluwatar/databus/members/MessageCollectorMember.java index d242eedb8..332f6f935 100644 --- a/data-bus/src/main/java/com/iluwatar/databus/members/MessageCollectorMember.java +++ b/data-bus/src/main/java/com/iluwatar/databus/members/MessageCollectorMember.java @@ -26,7 +26,6 @@ package com.iluwatar.databus.members; import com.iluwatar.databus.DataType; import com.iluwatar.databus.Member; import com.iluwatar.databus.data.MessageData; - import java.util.ArrayList; import java.util.Collections; import java.util.List; diff --git a/data-bus/src/main/java/com/iluwatar/databus/members/StatusMember.java b/data-bus/src/main/java/com/iluwatar/databus/members/StatusMember.java index cc0f6851b..fffcde9c6 100644 --- a/data-bus/src/main/java/com/iluwatar/databus/members/StatusMember.java +++ b/data-bus/src/main/java/com/iluwatar/databus/members/StatusMember.java @@ -28,7 +28,6 @@ import com.iluwatar.databus.Member; import com.iluwatar.databus.data.MessageData; import com.iluwatar.databus.data.StartingData; import com.iluwatar.databus.data.StoppingData; - import java.time.LocalDateTime; import java.util.logging.Logger; diff --git a/data-locality/src/main/java/com/iluwatar/data/locality/Application.java b/data-locality/src/main/java/com/iluwatar/data/locality/Application.java index 53abb0f4b..064465fc7 100644 --- a/data-locality/src/main/java/com/iluwatar/data/locality/Application.java +++ b/data-locality/src/main/java/com/iluwatar/data/locality/Application.java @@ -28,22 +28,21 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Use the Data Locality pattern is when you have a performance problem. - * Take advantage of that to improve performance by increasing data locality — keeping data in - * contiguous memory in the order that you process it. - * - * Example: Game loop that processes a bunch of game entities. - * Those entities are decomposed into different domains  - * — AI, physics, and rendering — using the Component pattern. + * Use the Data Locality pattern is when you have a performance problem. Take advantage of that to + * improve performance by increasing data locality — keeping data in contiguous memory in the order + * that you process it. * + *

Example: Game loop that processes a bunch of game entities. Those entities are decomposed + * into different domains  — AI, physics, and rendering — using the Component pattern. */ public class Application { private static final Logger LOGGER = LoggerFactory.getLogger(Application.class); private static final int NUM_ENTITIES = 5; + /** - * Start game loop with each component have NUM_ENTITIES instance + * Start game loop with each component have NUM_ENTITIES instance. */ public static void main(String[] args) { LOGGER.info("Start Game Application using Data-Locality pattern"); diff --git a/data-locality/src/main/java/com/iluwatar/data/locality/game/GameEntity.java b/data-locality/src/main/java/com/iluwatar/data/locality/game/GameEntity.java index 33f139948..337532175 100644 --- a/data-locality/src/main/java/com/iluwatar/data/locality/game/GameEntity.java +++ b/data-locality/src/main/java/com/iluwatar/data/locality/game/GameEntity.java @@ -30,14 +30,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * The game Entity maintains a big array of pointers . - * Each spin of the game loop, we need to run the following: + * The game Entity maintains a big array of pointers . Each spin of the game loop, we need to run + * the following: * - * Update the AI components . + *

Update the AI components. * - * Update the physics components for them. + *

Update the physics components for them. * - * Render them using their render components. + *

Render them using their render components. */ public class GameEntity { private static final Logger LOGGER = LoggerFactory.getLogger(GameEntity.class); @@ -47,7 +47,7 @@ public class GameEntity { private final RenderComponentManager renderComponentManager; /** - * Init components + * Init components. */ public GameEntity(int numEntities) { LOGGER.info("Init Game with #Entity : {}", numEntities); @@ -57,7 +57,7 @@ public class GameEntity { } /** - * start all component + * start all component. */ public void start() { LOGGER.info("Start Game"); @@ -67,7 +67,7 @@ public class GameEntity { } /** - * update all component + * update all component. */ public void update() { LOGGER.info("Update Game Component"); @@ -80,5 +80,5 @@ public class GameEntity { // Draw to screen. renderComponentManager.render(); } - + } diff --git a/data-locality/src/main/java/com/iluwatar/data/locality/game/component/AiComponent.java b/data-locality/src/main/java/com/iluwatar/data/locality/game/component/AiComponent.java index c31f2ce66..5b1be9e35 100644 --- a/data-locality/src/main/java/com/iluwatar/data/locality/game/component/AiComponent.java +++ b/data-locality/src/main/java/com/iluwatar/data/locality/game/component/AiComponent.java @@ -27,14 +27,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Implementation of AI component for Game + * Implementation of AI component for Game. */ public class AiComponent implements Component { - + private static final Logger LOGGER = LoggerFactory.getLogger(AiComponent.class); /** - * Update ai component + * Update ai component. */ @Override public void update() { diff --git a/data-locality/src/main/java/com/iluwatar/data/locality/game/component/Component.java b/data-locality/src/main/java/com/iluwatar/data/locality/game/component/Component.java index c877fbe01..f159df4f6 100644 --- a/data-locality/src/main/java/com/iluwatar/data/locality/game/component/Component.java +++ b/data-locality/src/main/java/com/iluwatar/data/locality/game/component/Component.java @@ -24,7 +24,7 @@ package com.iluwatar.data.locality.game.component; /** - * Implement different Game component update and render process + * Implement different Game component update and render process. */ public interface Component { diff --git a/data-locality/src/main/java/com/iluwatar/data/locality/game/component/PhysicsComponent.java b/data-locality/src/main/java/com/iluwatar/data/locality/game/component/PhysicsComponent.java index 3c5f0950e..89c6f1503 100644 --- a/data-locality/src/main/java/com/iluwatar/data/locality/game/component/PhysicsComponent.java +++ b/data-locality/src/main/java/com/iluwatar/data/locality/game/component/PhysicsComponent.java @@ -27,13 +27,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Implementation of Physics Component of Game + * Implementation of Physics Component of Game. */ public class PhysicsComponent implements Component { private static final Logger LOGGER = LoggerFactory.getLogger(PhysicsComponent.class); + /** - * update physics component of game + * update physics component of game. */ @Override public void update() { diff --git a/data-locality/src/main/java/com/iluwatar/data/locality/game/component/RenderComponent.java b/data-locality/src/main/java/com/iluwatar/data/locality/game/component/RenderComponent.java index 0f3e0ca1a..0b49da056 100644 --- a/data-locality/src/main/java/com/iluwatar/data/locality/game/component/RenderComponent.java +++ b/data-locality/src/main/java/com/iluwatar/data/locality/game/component/RenderComponent.java @@ -27,7 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Implementation of Render Component of Game + * Implementation of Render Component of Game. */ public class RenderComponent implements Component { @@ -39,7 +39,7 @@ public class RenderComponent implements Component { } /** - * render + * render. */ @Override public void render() { diff --git a/data-locality/src/main/java/com/iluwatar/data/locality/game/component/manager/AiComponentManager.java b/data-locality/src/main/java/com/iluwatar/data/locality/game/component/manager/AiComponentManager.java index 1fc5419cc..20fac0107 100644 --- a/data-locality/src/main/java/com/iluwatar/data/locality/game/component/manager/AiComponentManager.java +++ b/data-locality/src/main/java/com/iluwatar/data/locality/game/component/manager/AiComponentManager.java @@ -29,7 +29,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * AI component manager for Game + * AI component manager for Game. */ public class AiComponentManager { @@ -46,7 +46,7 @@ public class AiComponentManager { } /** - * start AI component of Game + * start AI component of Game. */ public void start() { LOGGER.info("Start AI Game Component"); @@ -56,7 +56,7 @@ public class AiComponentManager { } /** - * Update AI component of Game + * Update AI component of Game. */ public void update() { LOGGER.info("Update AI Game Component"); diff --git a/data-locality/src/main/java/com/iluwatar/data/locality/game/component/manager/PhysicsComponentManager.java b/data-locality/src/main/java/com/iluwatar/data/locality/game/component/manager/PhysicsComponentManager.java index 6ac6f5c09..36f762587 100644 --- a/data-locality/src/main/java/com/iluwatar/data/locality/game/component/manager/PhysicsComponentManager.java +++ b/data-locality/src/main/java/com/iluwatar/data/locality/game/component/manager/PhysicsComponentManager.java @@ -46,7 +46,7 @@ public class PhysicsComponentManager { } /** - * Start physics component of Game + * Start physics component of Game. */ public void start() { LOGGER.info("Start Physics Game Component "); @@ -57,7 +57,7 @@ public class PhysicsComponentManager { /** - * Update physics component of Game + * Update physics component of Game. */ public void update() { LOGGER.info("Update Physics Game Component "); diff --git a/data-locality/src/main/java/com/iluwatar/data/locality/game/component/manager/RenderComponentManager.java b/data-locality/src/main/java/com/iluwatar/data/locality/game/component/manager/RenderComponentManager.java index 7360f208b..fd6ef9640 100644 --- a/data-locality/src/main/java/com/iluwatar/data/locality/game/component/manager/RenderComponentManager.java +++ b/data-locality/src/main/java/com/iluwatar/data/locality/game/component/manager/RenderComponentManager.java @@ -29,7 +29,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Render component manager for Game + * Render component manager for Game. */ public class RenderComponentManager { @@ -46,7 +46,7 @@ public class RenderComponentManager { } /** - * Start render component + * Start render component. */ public void start() { LOGGER.info("Start Render Game Component "); @@ -57,7 +57,7 @@ public class RenderComponentManager { /** - * render component + * render component. */ public void render() { LOGGER.info("Update Render Game Component "); diff --git a/data-mapper/src/main/java/com/iluwatar/datamapper/App.java b/data-mapper/src/main/java/com/iluwatar/datamapper/App.java index 50857729a..49d6c63d3 100644 --- a/data-mapper/src/main/java/com/iluwatar/datamapper/App.java +++ b/data-mapper/src/main/java/com/iluwatar/datamapper/App.java @@ -23,11 +23,10 @@ package com.iluwatar.datamapper; +import java.util.Optional; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Optional; - /** * The Data Mapper (DM) is a layer of software that separates the in-memory objects from the * database. Its responsibility is to transfer data between the two and also to isolate them from @@ -35,19 +34,18 @@ import java.util.Optional; * present; they need no SQL interface code, and certainly no knowledge of the database schema. (The * database schema is always ignorant of the objects that use it.) Since it's a form of Mapper , * Data Mapper itself is even unknown to the domain layer. - *

- * The below example demonstrates basic CRUD operations: Create, Read, Update, and Delete. - * + * + *

The below example demonstrates basic CRUD operations: Create, Read, Update, and Delete. */ public final class App { private static Logger log = LoggerFactory.getLogger(App.class); private static final String STUDENT_STRING = "App.main(), student : "; - + /** * Program entry point. - * + * * @param args command line args. */ public static void main(final String... args) { @@ -81,5 +79,6 @@ public final class App { mapper.delete(student); } - private App() {} + private App() { + } } diff --git a/data-mapper/src/main/java/com/iluwatar/datamapper/DataMapperException.java b/data-mapper/src/main/java/com/iluwatar/datamapper/DataMapperException.java index 57aec04a8..4f354c7eb 100644 --- a/data-mapper/src/main/java/com/iluwatar/datamapper/DataMapperException.java +++ b/data-mapper/src/main/java/com/iluwatar/datamapper/DataMapperException.java @@ -26,9 +26,8 @@ package com.iluwatar.datamapper; /** * Using Runtime Exception for avoiding dependancy on implementation exceptions. This helps in * decoupling. - * - * @author amit.dixit * + * @author amit.dixit */ public final class DataMapperException extends RuntimeException { @@ -39,7 +38,7 @@ public final class DataMapperException extends RuntimeException { * initialized, and may subsequently be initialized by a call to {@link #initCause}. * * @param message the detail message. The detail message is saved for later retrieval by the - * {@link #getMessage()} method. + * {@link #getMessage()} method. */ public DataMapperException(final String message) { super(message); diff --git a/data-mapper/src/main/java/com/iluwatar/datamapper/Student.java b/data-mapper/src/main/java/com/iluwatar/datamapper/Student.java index e52d293ce..5a368f9ce 100644 --- a/data-mapper/src/main/java/com/iluwatar/datamapper/Student.java +++ b/data-mapper/src/main/java/com/iluwatar/datamapper/Student.java @@ -23,11 +23,10 @@ package com.iluwatar.datamapper; - import java.io.Serializable; /** - * Class defining Student + * Class defining Student. */ public final class Student implements Serializable { @@ -39,11 +38,11 @@ public final class Student implements Serializable { /** - * Use this constructor to create a Student with all details + * Use this constructor to create a Student with all details. * * @param studentId as unique student id - * @param name as student name - * @param grade as respective grade of student + * @param name as student name + * @param grade as respective grade of student */ public Student(final int studentId, final String name, final char grade) { this.studentId = studentId; @@ -51,57 +50,30 @@ public final class Student implements Serializable { this.grade = grade; } - /** - * - * @return the student id - */ public int getStudentId() { return studentId; } - /** - * - * @param studentId as unique student id - */ public void setStudentId(final int studentId) { this.studentId = studentId; } - /** - * - * @return name of student - */ public String getName() { return name; } - /** - * - * @param name as 'name' of student - */ public void setName(final String name) { this.name = name; } - /** - * - * @return grade of student - */ public char getGrade() { return grade; } - /** - * - * @param grade as 'grade of student' - */ public void setGrade(final char grade) { this.grade = grade; } - /** - * - */ @Override public boolean equals(final Object inputObject) { @@ -125,9 +97,6 @@ public final class Student implements Serializable { return isEqual; } - /** - * - */ @Override public int hashCode() { @@ -135,9 +104,6 @@ public final class Student implements Serializable { return this.getStudentId(); } - /** - * - */ @Override public String toString() { return "Student [studentId=" + studentId + ", name=" + name + ", grade=" + grade + "]"; diff --git a/data-mapper/src/main/java/com/iluwatar/datamapper/StudentDataMapper.java b/data-mapper/src/main/java/com/iluwatar/datamapper/StudentDataMapper.java index 18ce1685c..3dfe4787f 100644 --- a/data-mapper/src/main/java/com/iluwatar/datamapper/StudentDataMapper.java +++ b/data-mapper/src/main/java/com/iluwatar/datamapper/StudentDataMapper.java @@ -26,7 +26,7 @@ package com.iluwatar.datamapper; import java.util.Optional; /** - * Interface lists out the possible behaviour for all possible student mappers + * Interface lists out the possible behaviour for all possible student mappers. */ public interface StudentDataMapper { diff --git a/data-mapper/src/main/java/com/iluwatar/datamapper/StudentDataMapperImpl.java b/data-mapper/src/main/java/com/iluwatar/datamapper/StudentDataMapperImpl.java index 117015f00..cc92ab81e 100644 --- a/data-mapper/src/main/java/com/iluwatar/datamapper/StudentDataMapperImpl.java +++ b/data-mapper/src/main/java/com/iluwatar/datamapper/StudentDataMapperImpl.java @@ -28,7 +28,7 @@ import java.util.List; import java.util.Optional; /** - * Implementation of Actions on Students Data + * Implementation of Actions on Students Data. */ public final class StudentDataMapperImpl implements StudentDataMapper { @@ -84,7 +84,8 @@ public final class StudentDataMapperImpl implements StudentDataMapper { } else { /* Throw user error after wrapping in a runtime exception */ - throw new DataMapperException("Student already [" + studentToBeInserted.getName() + "] exists"); + throw new DataMapperException("Student already [" + studentToBeInserted + .getName() + "] exists"); } } diff --git a/data-transfer-object/src/main/java/com/iluwatar/datatransfer/CustomerClientApp.java b/data-transfer-object/src/main/java/com/iluwatar/datatransfer/CustomerClientApp.java index 7a660705a..860faf478 100644 --- a/data-transfer-object/src/main/java/com/iluwatar/datatransfer/CustomerClientApp.java +++ b/data-transfer-object/src/main/java/com/iluwatar/datatransfer/CustomerClientApp.java @@ -23,21 +23,20 @@ package com.iluwatar.datatransfer; +import java.util.ArrayList; +import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.List; - /** - * The Data Transfer Object pattern is a design pattern in which an data transfer object is used to serve related - * information together to avoid multiple call for each piece of information. - *

- * In this example, ({@link CustomerClientApp}) as as customer details consumer i.e. client to request for - * customer details to server. - *

- * CustomerResource ({@link CustomerResource}) act as server to serve customer information. - * And The CustomerDto ({@link CustomerDto} is data transfer object to share customer information. + * The Data Transfer Object pattern is a design pattern in which an data transfer object is used to + * serve related information together to avoid multiple call for each piece of information. + * + *

In this example, ({@link CustomerClientApp}) as as customer details consumer i.e. client to + * request for customer details to server. + * + *

CustomerResource ({@link CustomerResource}) act as server to serve customer information. And + * The CustomerDto ({@link CustomerDto} is data transfer object to share customer information. */ public class CustomerClientApp { diff --git a/data-transfer-object/src/main/java/com/iluwatar/datatransfer/CustomerDto.java b/data-transfer-object/src/main/java/com/iluwatar/datatransfer/CustomerDto.java index d05d970d2..a77eb8702 100644 --- a/data-transfer-object/src/main/java/com/iluwatar/datatransfer/CustomerDto.java +++ b/data-transfer-object/src/main/java/com/iluwatar/datatransfer/CustomerDto.java @@ -24,10 +24,10 @@ package com.iluwatar.datatransfer; /** - * {@link CustomerDto} is a data transfer object POJO. Instead of sending individual information to client - * We can send related information together in POJO. - *

- * Dto will not have any business logic in it. + * {@link CustomerDto} is a data transfer object POJO. Instead of sending individual information to + * client We can send related information together in POJO. + * + *

Dto will not have any business logic in it. */ public class CustomerDto { private final String id; @@ -35,6 +35,8 @@ public class CustomerDto { private final String lastName; /** + * Constructor. + * * @param id customer id * @param firstName customer first name * @param lastName customer last name diff --git a/data-transfer-object/src/main/java/com/iluwatar/datatransfer/CustomerResource.java b/data-transfer-object/src/main/java/com/iluwatar/datatransfer/CustomerResource.java index 5dee3c8f8..7e4b8340d 100644 --- a/data-transfer-object/src/main/java/com/iluwatar/datatransfer/CustomerResource.java +++ b/data-transfer-object/src/main/java/com/iluwatar/datatransfer/CustomerResource.java @@ -26,13 +26,15 @@ package com.iluwatar.datatransfer; import java.util.List; /** - * The resource class which serves customer information. - * This class act as server in the demo. Which has all customer details. + * The resource class which serves customer information. This class act as server in the demo. Which + * has all customer details. */ public class CustomerResource { private List customers; /** + * Initialise resource with existing customers. + * * @param customers initialize resource with existing customers. Act as database. */ public CustomerResource(List customers) { @@ -40,6 +42,8 @@ public class CustomerResource { } /** + * Get all customers. + * * @return : all customers in list. */ public List getAllCustomers() { @@ -47,6 +51,8 @@ public class CustomerResource { } /** + * Save new customer. + * * @param customer save new customer to list. */ public void save(CustomerDto customer) { @@ -54,6 +60,8 @@ public class CustomerResource { } /** + * Delete customer with given id. + * * @param customerId delete customer with id {@code customerId} */ public void delete(String customerId) { diff --git a/decorator/src/main/java/com/iluwatar/decorator/App.java b/decorator/src/main/java/com/iluwatar/decorator/App.java index 82a44bc11..348e5623d 100644 --- a/decorator/src/main/java/com/iluwatar/decorator/App.java +++ b/decorator/src/main/java/com/iluwatar/decorator/App.java @@ -27,24 +27,22 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * * The Decorator pattern is a more flexible alternative to subclassing. The Decorator class * implements the same interface as the target and uses aggregation to "decorate" calls to the * target. Using the Decorator pattern it is possible to change the behavior of the class during * runtime. - *

- * In this example we show how the simple {@link SimpleTroll} first attacks and then flees the battle. - * Then we decorate the {@link SimpleTroll} with a {@link ClubbedTroll} and perform the attack again. You - * can see how the behavior changes after the decoration. - * + * + *

In this example we show how the simple {@link SimpleTroll} first attacks and then flees the + * battle. Then we decorate the {@link SimpleTroll} with a {@link ClubbedTroll} and perform the + * attack again. You can see how the behavior changes after the decoration. */ 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/decorator/src/main/java/com/iluwatar/decorator/ClubbedTroll.java b/decorator/src/main/java/com/iluwatar/decorator/ClubbedTroll.java index 90eb893a7..70fd15489 100644 --- a/decorator/src/main/java/com/iluwatar/decorator/ClubbedTroll.java +++ b/decorator/src/main/java/com/iluwatar/decorator/ClubbedTroll.java @@ -27,7 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Decorator that adds a club for the troll + * Decorator that adds a club for the troll. */ public class ClubbedTroll implements Troll { diff --git a/decorator/src/main/java/com/iluwatar/decorator/SimpleTroll.java b/decorator/src/main/java/com/iluwatar/decorator/SimpleTroll.java index e2095a2ad..08eed94fc 100644 --- a/decorator/src/main/java/com/iluwatar/decorator/SimpleTroll.java +++ b/decorator/src/main/java/com/iluwatar/decorator/SimpleTroll.java @@ -27,9 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * * SimpleTroll implements {@link Troll} interface directly. - * */ public class SimpleTroll implements Troll { diff --git a/decorator/src/main/java/com/iluwatar/decorator/Troll.java b/decorator/src/main/java/com/iluwatar/decorator/Troll.java index faeca11c9..43f9ac916 100644 --- a/decorator/src/main/java/com/iluwatar/decorator/Troll.java +++ b/decorator/src/main/java/com/iluwatar/decorator/Troll.java @@ -24,9 +24,7 @@ package com.iluwatar.decorator; /** - * - * Interface for trolls - * + * Interface for trolls. */ public interface Troll {