Resolves checkstyle errors for dao data-bus data-locality data-mapper data-transfer-object decorator (#1067)
* Reduces checkstyle errors in dao * Reduces checkstyle errors in data-bus * Reduces checkstyle errors in data-locality * Reduces checkstyle errors in data-mapper * Reduces checkstyle errors in data-transfer-object * Reduces checkstyle errors in decorator
This commit is contained in:
parent
eae09fc07e
commit
01e489c77b
@ -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.
|
||||
*
|
||||
* <p>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
|
||||
* <p>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<Customer> generateSampleCustomers() {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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.
|
||||
*
|
||||
* <p>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.
|
||||
*
|
||||
* <p>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<Customer> 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 <code>id</code>
|
||||
* exists, empty optional otherwise.
|
||||
* @return an optional with customer if a customer with unique identifier <code>id</code> exists,
|
||||
* empty optional otherwise.
|
||||
* @throws Exception if any error occurs.
|
||||
*/
|
||||
Optional<Customer> 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.
|
||||
|
@ -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";
|
||||
|
||||
|
@ -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 <code>dataSource</code>
|
||||
* to store and retrieve customer information.
|
||||
*
|
||||
* Creates an instance of {@link DbCustomerDao} which uses provided <code>dataSource</code> 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<Customer> 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<Customer>(Long.MAX_VALUE,
|
||||
return StreamSupport.stream(new Spliterators.AbstractSpliterator<Customer>(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) {
|
||||
|
@ -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.
|
||||
* <br>
|
||||
* 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;
|
||||
}
|
||||
|
@ -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
|
||||
* <p>
|
||||
* @see <a href="http://wiki.c2.com/?DataBusPattern">http://wiki.c2.com/?DataBusPattern</a>
|
||||
* <p>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.</p>
|
||||
* <p>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.</p>
|
||||
* <p>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.</p>
|
||||
* <p>Members may unsubscribe from the Data-Bus to stop receiving data.</p>
|
||||
* <p>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.</p>
|
||||
* <p>The {@link DataBus} class is a Singleton.</p>
|
||||
* <p>Members of the Data-Bus must implement the {@link Member} interface.</p>
|
||||
* <p>Data to be published via the Data-Bus must implement the {@link DataType} interface.</p>
|
||||
* <p>The {@code data} package contains example {@link DataType} implementations.</p>
|
||||
* <p>The {@code members} package contains example {@link Member} implementations.</p>
|
||||
* <p>The {@link StatusMember} demonstrates using the DataBus to publish a message
|
||||
* to the Data-Bus when it receives a message.</p>
|
||||
* The Data Bus pattern.
|
||||
*
|
||||
* @author Paul Campbell (pcampbell@kemitix.net)
|
||||
* @see <a href="http://wiki.c2.com/?DataBusPattern">http://wiki.c2.com/?DataBusPattern</a>
|
||||
* <p>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.</p>
|
||||
* <p>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.</p>
|
||||
* <p>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.</p>
|
||||
* <p>Members may unsubscribe from the Data-Bus to stop receiving data.</p>
|
||||
* <p>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.</p>
|
||||
* <p>The {@link DataBus} class is a Singleton.</p>
|
||||
* <p>Members of the Data-Bus must implement the {@link Member} interface.</p>
|
||||
* <p>Data to be published via the Data-Bus must implement the {@link DataType} interface.</p>
|
||||
* <p>The {@code data} package contains example {@link DataType} implementations.</p>
|
||||
* <p>The {@code members} package contains example {@link Member} implementations.</p>
|
||||
* <p>The {@link StatusMember} demonstrates using the DataBus to publish a message
|
||||
* to the Data-Bus when it receives a message.</p>
|
||||
*/
|
||||
class App {
|
||||
|
||||
|
@ -25,7 +25,6 @@ package com.iluwatar.databus.data;
|
||||
|
||||
import com.iluwatar.databus.AbstractDataType;
|
||||
import com.iluwatar.databus.DataType;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
|
@ -25,7 +25,6 @@ package com.iluwatar.databus.data;
|
||||
|
||||
import com.iluwatar.databus.AbstractDataType;
|
||||
import com.iluwatar.databus.DataType;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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.
|
||||
*
|
||||
* <p>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");
|
||||
|
@ -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 .
|
||||
* <p>Update the AI components.
|
||||
*
|
||||
* Update the physics components for them.
|
||||
* <p>Update the physics components for them.
|
||||
*
|
||||
* Render them using their render components.
|
||||
* <p>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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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() {
|
||||
|
@ -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");
|
||||
|
@ -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 ");
|
||||
|
@ -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 ");
|
||||
|
@ -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.
|
||||
* <p>
|
||||
* The below example demonstrates basic CRUD operations: Create, Read, Update, and Delete.
|
||||
*
|
||||
*
|
||||
* <p>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() {
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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 + "]";
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
* <p>
|
||||
* In this example, ({@link CustomerClientApp}) as as customer details consumer i.e. client to request for
|
||||
* customer details to server.
|
||||
* <p>
|
||||
* 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.
|
||||
*
|
||||
* <p>In this example, ({@link CustomerClientApp}) as as customer details consumer i.e. client to
|
||||
* request for customer details to server.
|
||||
*
|
||||
* <p>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 {
|
||||
|
||||
|
@ -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.
|
||||
* <p>
|
||||
* 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.
|
||||
*
|
||||
* <p>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
|
||||
|
@ -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<CustomerDto> customers;
|
||||
|
||||
/**
|
||||
* Initialise resource with existing customers.
|
||||
*
|
||||
* @param customers initialize resource with existing customers. Act as database.
|
||||
*/
|
||||
public CustomerResource(List<CustomerDto> customers) {
|
||||
@ -40,6 +42,8 @@ public class CustomerResource {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all customers.
|
||||
*
|
||||
* @return : all customers in list.
|
||||
*/
|
||||
public List<CustomerDto> 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) {
|
||||
|
@ -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.
|
||||
* <p>
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* <p>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) {
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -27,9 +27,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* SimpleTroll implements {@link Troll} interface directly.
|
||||
*
|
||||
*/
|
||||
public class SimpleTroll implements Troll {
|
||||
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.decorator;
|
||||
|
||||
/**
|
||||
*
|
||||
* Interface for trolls
|
||||
*
|
||||
* Interface for trolls.
|
||||
*/
|
||||
public interface Troll {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user