mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-08-15 18:23:54 +00:00
* #2449 bump maven-checkstyle-plugin from 3.1.0 to 3.2.0 + resolve checkstyle issues * remove FileSelectorJFrame.java to resolve checkstyle issue * remove FileSelectorJFrame.java to resolve checkstyle issue * remove FileSelectorJFrame.java to resolve checkstyle issue * add refactored file with correct filename to resolve checkstyle issue * add the test data * change filenames from JFrame to Jframe for checkstyle * fix code smell from sonar report * add new testcases to improve the test coverage * remove code smell
This commit is contained in:
-1
@@ -25,7 +25,6 @@
|
|||||||
package com.iluwatar.abstractdocument;
|
package com.iluwatar.abstractdocument;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import com.iluwatar.abstractdocument.domain.Car;
|
|||||||
import com.iluwatar.abstractdocument.domain.Part;
|
import com.iluwatar.abstractdocument.domain.Part;
|
||||||
import com.iluwatar.abstractdocument.domain.enums.Property;
|
import com.iluwatar.abstractdocument.domain.enums.Property;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ package com.iluwatar.abstractfactory;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper class to manufacture {@link KingdomFactory} beans.
|
||||||
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class Kingdom {
|
public class Kingdom {
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ package com.iluwatar.activeobject;
|
|||||||
|
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -77,8 +76,8 @@ public abstract class ActiveCreature {
|
|||||||
*/
|
*/
|
||||||
public void eat() throws InterruptedException {
|
public void eat() throws InterruptedException {
|
||||||
requests.put(() -> {
|
requests.put(() -> {
|
||||||
logger.info("{} is eating!",name());
|
logger.info("{} is eating!", name());
|
||||||
logger.info("{} has finished eating!",name());
|
logger.info("{} has finished eating!", name());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +87,7 @@ public abstract class ActiveCreature {
|
|||||||
*/
|
*/
|
||||||
public void roam() throws InterruptedException {
|
public void roam() throws InterruptedException {
|
||||||
requests.put(() ->
|
requests.put(() ->
|
||||||
logger.info("{} has started to roam in the wastelands.",name())
|
logger.info("{} has started to roam in the wastelands.", name())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ package com.iluwatar.activeobject;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -58,7 +57,7 @@ public class App implements Runnable {
|
|||||||
public void run() {
|
public void run() {
|
||||||
List<ActiveCreature> creatures = new ArrayList<>();
|
List<ActiveCreature> creatures = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
for (int i = 0;i < NUM_CREATURES;i++) {
|
for (int i = 0; i < NUM_CREATURES; i++) {
|
||||||
creatures.add(new Orc(Orc.class.getSimpleName() + i));
|
creatures.add(new Orc(Orc.class.getSimpleName() + i));
|
||||||
creatures.get(i).eat();
|
creatures.get(i).eat();
|
||||||
creatures.get(i).roam();
|
creatures.get(i).roam();
|
||||||
@@ -68,7 +67,7 @@ public class App implements Runnable {
|
|||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
} finally {
|
} finally {
|
||||||
for (int i = 0;i < NUM_CREATURES;i++) {
|
for (int i = 0; i < NUM_CREATURES; i++) {
|
||||||
creatures.get(i).kill(0);
|
creatures.get(i).kill(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ package com.iluwatar.adapter;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
package com.iluwatar.business.delegate;
|
package com.iluwatar.business.delegate;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
|||||||
@@ -25,9 +25,7 @@
|
|||||||
package com.iluwatar.caching;
|
package com.iluwatar.caching;
|
||||||
|
|
||||||
import com.iluwatar.caching.database.DbManager;
|
import com.iluwatar.caching.database.DbManager;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import com.iluwatar.caching.database.DbManager;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class MongoDb implements DbManager {
|
|||||||
private MongoClient client;
|
private MongoClient client;
|
||||||
private MongoDatabase db;
|
private MongoDatabase db;
|
||||||
|
|
||||||
void setDB(MongoDatabase db) {
|
void setDb(MongoDatabase db) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
package com.iluwatar.caching.database;
|
package com.iluwatar.caching.database;
|
||||||
|
|
||||||
import com.iluwatar.caching.UserAccount;
|
import com.iluwatar.caching.UserAccount;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class MongoDbTest {
|
|||||||
@BeforeEach
|
@BeforeEach
|
||||||
void init() {
|
void init() {
|
||||||
db = mock(MongoDatabase.class);
|
db = mock(MongoDatabase.class);
|
||||||
mongoDb.setDB(db);
|
mongoDb.setDb(db);
|
||||||
userAccount = new UserAccount(ID, NAME, ADDITIONAL_INFO);
|
userAccount = new UserAccount(ID, NAME, ADDITIONAL_INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,4 +7,5 @@
|
|||||||
<suppress checks="[a-zA-Z0-9]*" files="[\\/]src[\\/]main[\\/]resources[\\/]" />
|
<suppress checks="[a-zA-Z0-9]*" files="[\\/]src[\\/]main[\\/]resources[\\/]" />
|
||||||
<suppress checks="LineLength" files="." />
|
<suppress checks="LineLength" files="." />
|
||||||
<suppress checks="EmptyLineSeparator" files="." />
|
<suppress checks="EmptyLineSeparator" files="." />
|
||||||
|
<suppress checks="RequireEmptyLineBeforeBlockTagGroup" files=".*\.java"/>
|
||||||
</suppressions>
|
</suppressions>
|
||||||
|
|||||||
-1
@@ -27,7 +27,6 @@ package com.iluwatar.collectingparameter;
|
|||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.Timeout;
|
import org.junit.jupiter.api.Timeout;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
|
|||||||
-1
@@ -27,7 +27,6 @@ package com.iluwatar.collectingparameter;
|
|||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.Timeout;
|
import org.junit.jupiter.api.Timeout;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
package com.iluwatar.commander;
|
package com.iluwatar.commander;
|
||||||
|
|
||||||
import com.iluwatar.commander.exceptions.DatabaseUnavailableException;
|
import com.iluwatar.commander.exceptions.DatabaseUnavailableException;
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ package com.iluwatar.commander.employeehandle;
|
|||||||
import com.iluwatar.commander.Database;
|
import com.iluwatar.commander.Database;
|
||||||
import com.iluwatar.commander.Order;
|
import com.iluwatar.commander.Order;
|
||||||
import com.iluwatar.commander.exceptions.DatabaseUnavailableException;
|
import com.iluwatar.commander.exceptions.DatabaseUnavailableException;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|||||||
@@ -37,10 +37,8 @@ import com.iluwatar.commander.paymentservice.PaymentService;
|
|||||||
import com.iluwatar.commander.queue.QueueDatabase;
|
import com.iluwatar.commander.queue.QueueDatabase;
|
||||||
import com.iluwatar.commander.shippingservice.ShippingDatabase;
|
import com.iluwatar.commander.shippingservice.ShippingDatabase;
|
||||||
import com.iluwatar.commander.shippingservice.ShippingService;
|
import com.iluwatar.commander.shippingservice.ShippingService;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.platform.commons.util.StringUtils;
|
import org.junit.platform.commons.util.StringUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ package com.iluwatar.context.object;
|
|||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Layer A in the context object pattern.
|
||||||
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
public class LayerA {
|
public class LayerA {
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ package com.iluwatar.context.object;
|
|||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Layer B in the context object pattern.
|
||||||
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
public class LayerB {
|
public class LayerB {
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ package com.iluwatar.context.object;
|
|||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Layer C in the context object pattern.
|
||||||
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
public class LayerC {
|
public class LayerC {
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ package com.iluwatar.cqrs.commandes;
|
|||||||
/**
|
/**
|
||||||
* This interface represents the commands of the CQRS pattern.
|
* This interface represents the commands of the CQRS pattern.
|
||||||
*/
|
*/
|
||||||
public interface ICommandService {
|
public interface CommandService {
|
||||||
|
|
||||||
void authorCreated(String username, String name, String email);
|
void authorCreated(String username, String name, String email);
|
||||||
|
|
||||||
@@ -30,10 +30,10 @@ import com.iluwatar.cqrs.util.HibernateUtil;
|
|||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is an implementation of {@link ICommandService} interface. It uses Hibernate as an api
|
* This class is an implementation of {@link CommandService} interface. It uses Hibernate as an api
|
||||||
* for persistence.
|
* for persistence.
|
||||||
*/
|
*/
|
||||||
public class CommandServiceImpl implements ICommandService {
|
public class CommandServiceImpl implements CommandService {
|
||||||
|
|
||||||
private final SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
|
private final SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -32,7 +32,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* This interface represents the query methods of the CQRS pattern.
|
* This interface represents the query methods of the CQRS pattern.
|
||||||
*/
|
*/
|
||||||
public interface IQueryService {
|
public interface QueryService {
|
||||||
|
|
||||||
Author getAuthorByUsername(String username);
|
Author getAuthorByUsername(String username);
|
||||||
|
|
||||||
@@ -34,51 +34,51 @@ import org.hibernate.SessionFactory;
|
|||||||
import org.hibernate.query.Query;
|
import org.hibernate.query.Query;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is an implementation of {@link IQueryService}. It uses Hibernate native queries to
|
* This class is an implementation of {@link QueryService}. It uses Hibernate native queries to
|
||||||
* return DTOs from the database.
|
* return DTOs from the database.
|
||||||
*/
|
*/
|
||||||
public class QueryServiceImpl implements IQueryService {
|
public class QueryServiceImpl implements QueryService {
|
||||||
|
|
||||||
private final SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
|
private final SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Author getAuthorByUsername(String username) {
|
public Author getAuthorByUsername(String username) {
|
||||||
Author authorDTo;
|
Author authorDto;
|
||||||
try (var session = sessionFactory.openSession()) {
|
try (var session = sessionFactory.openSession()) {
|
||||||
Query<Author> sqlQuery = session.createQuery(
|
Query<Author> sqlQuery = session.createQuery(
|
||||||
"select new com.iluwatar.cqrs.dto.Author(a.name, a.email, a.username)"
|
"select new com.iluwatar.cqrs.dto.Author(a.name, a.email, a.username)"
|
||||||
+ " from com.iluwatar.cqrs.domain.model.Author a where a.username=:username");
|
+ " from com.iluwatar.cqrs.domain.model.Author a where a.username=:username");
|
||||||
sqlQuery.setParameter(AppConstants.USER_NAME, username);
|
sqlQuery.setParameter(AppConstants.USER_NAME, username);
|
||||||
authorDTo = sqlQuery.uniqueResult();
|
authorDto = sqlQuery.uniqueResult();
|
||||||
}
|
}
|
||||||
return authorDTo;
|
return authorDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Book getBook(String title) {
|
public Book getBook(String title) {
|
||||||
Book bookDTo;
|
Book bookDto;
|
||||||
try (var session = sessionFactory.openSession()) {
|
try (var session = sessionFactory.openSession()) {
|
||||||
Query<Book> sqlQuery = session.createQuery(
|
Query<Book> sqlQuery = session.createQuery(
|
||||||
"select new com.iluwatar.cqrs.dto.Book(b.title, b.price)"
|
"select new com.iluwatar.cqrs.dto.Book(b.title, b.price)"
|
||||||
+ " from com.iluwatar.cqrs.domain.model.Book b where b.title=:title");
|
+ " from com.iluwatar.cqrs.domain.model.Book b where b.title=:title");
|
||||||
sqlQuery.setParameter("title", title);
|
sqlQuery.setParameter("title", title);
|
||||||
bookDTo = sqlQuery.uniqueResult();
|
bookDto = sqlQuery.uniqueResult();
|
||||||
}
|
}
|
||||||
return bookDTo;
|
return bookDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Book> getAuthorBooks(String username) {
|
public List<Book> getAuthorBooks(String username) {
|
||||||
List<Book> bookDTos;
|
List<Book> bookDtos;
|
||||||
try (var session = sessionFactory.openSession()) {
|
try (var session = sessionFactory.openSession()) {
|
||||||
Query<Book> sqlQuery = session.createQuery(
|
Query<Book> sqlQuery = session.createQuery(
|
||||||
"select new com.iluwatar.cqrs.dto.Book(b.title, b.price)"
|
"select new com.iluwatar.cqrs.dto.Book(b.title, b.price)"
|
||||||
+ " from com.iluwatar.cqrs.domain.model.Author a, com.iluwatar.cqrs.domain.model.Book b "
|
+ " from com.iluwatar.cqrs.domain.model.Author a, com.iluwatar.cqrs.domain.model.Book b "
|
||||||
+ "where b.author.id = a.id and a.username=:username");
|
+ "where b.author.id = a.id and a.username=:username");
|
||||||
sqlQuery.setParameter(AppConstants.USER_NAME, username);
|
sqlQuery.setParameter(AppConstants.USER_NAME, username);
|
||||||
bookDTos = sqlQuery.list();
|
bookDtos = sqlQuery.list();
|
||||||
}
|
}
|
||||||
return bookDTos;
|
return bookDtos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||||||
import com.iluwatar.cqrs.commandes.CommandServiceImpl;
|
import com.iluwatar.cqrs.commandes.CommandServiceImpl;
|
||||||
import com.iluwatar.cqrs.dto.Author;
|
import com.iluwatar.cqrs.dto.Author;
|
||||||
import com.iluwatar.cqrs.dto.Book;
|
import com.iluwatar.cqrs.dto.Book;
|
||||||
import com.iluwatar.cqrs.queries.IQueryService;
|
import com.iluwatar.cqrs.queries.QueryService;
|
||||||
import com.iluwatar.cqrs.queries.QueryServiceImpl;
|
import com.iluwatar.cqrs.queries.QueryServiceImpl;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
@@ -41,7 +41,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
*/
|
*/
|
||||||
class IntegrationTest {
|
class IntegrationTest {
|
||||||
|
|
||||||
private static IQueryService queryService;
|
private static QueryService queryService;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
static void initializeAndPopulateDatabase() {
|
static void initializeAndPopulateDatabase() {
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
-1
@@ -29,7 +29,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.iluwatar.datatransfer.customer.CustomerDto;
|
import com.iluwatar.datatransfer.customer.CustomerDto;
|
||||||
import com.iluwatar.datatransfer.customer.CustomerResource;
|
import com.iluwatar.datatransfer.customer.CustomerResource;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|||||||
-1
@@ -28,7 +28,6 @@ import ch.qos.logback.classic.Logger;
|
|||||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||||
import ch.qos.logback.core.AppenderBase;
|
import ch.qos.logback.core.AppenderBase;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import static org.joda.money.CurrencyUnit.USD;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.h2.jdbcx.JdbcDataSource;
|
import org.h2.jdbcx.JdbcDataSource;
|
||||||
import org.joda.money.Money;
|
import org.joda.money.Money;
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import java.sql.SQLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ package com.iluwatar.domainmodel;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DAO interface for customer transactions.
|
||||||
|
*/
|
||||||
public interface CustomerDao {
|
public interface CustomerDao {
|
||||||
|
|
||||||
Optional<Customer> findByName(String name) throws SQLException;
|
Optional<Customer> findByName(String name) throws SQLException;
|
||||||
|
|||||||
@@ -30,9 +30,11 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.joda.money.Money;
|
import org.joda.money.Money;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementations for database operations of Customer.
|
||||||
|
*/
|
||||||
public class CustomerDaoImpl implements CustomerDao {
|
public class CustomerDaoImpl implements CustomerDao {
|
||||||
|
|
||||||
private final DataSource dataSource;
|
private final DataSource dataSource;
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import java.sql.SQLException;
|
|||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ package com.iluwatar.domainmodel;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DAO interface for product transactions.
|
||||||
|
*/
|
||||||
public interface ProductDao {
|
public interface ProductDao {
|
||||||
|
|
||||||
Optional<Product> findByName(String name) throws SQLException;
|
Optional<Product> findByName(String name) throws SQLException;
|
||||||
|
|||||||
@@ -31,10 +31,11 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.joda.money.Money;
|
import org.joda.money.Money;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementations for database transactions of Product.
|
||||||
|
*/
|
||||||
public class ProductDaoImpl implements ProductDao {
|
public class ProductDaoImpl implements ProductDao {
|
||||||
|
|
||||||
private final DataSource dataSource;
|
private final DataSource dataSource;
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import org.joda.money.Money;
|
|||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import org.joda.money.CurrencyUnit;
|
|||||||
import org.joda.money.Money;
|
import org.joda.money.Money;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import org.joda.money.Money;
|
|||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ package com.iluwatar.domainmodel;
|
|||||||
import org.joda.money.Money;
|
import org.joda.money.Money;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
package com.iluwatar.domainmodel;
|
package com.iluwatar.domainmodel;
|
||||||
|
|
||||||
import org.h2.jdbcx.JdbcDataSource;
|
import org.h2.jdbcx.JdbcDataSource;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
|||||||
@@ -25,22 +25,20 @@
|
|||||||
package com.iluwatar.embedded.value;
|
package com.iluwatar.embedded.value;
|
||||||
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Many small objects make sense in an OO system that don’t make sense as
|
* <p> Many small objects make sense in an OO system that don’t make sense as
|
||||||
* tables in a database. Examples include currency-aware money objects (amount, currency) and date
|
* tables in a database. Examples include currency-aware money objects (amount, currency) and date
|
||||||
* ranges. Although the default thinking is to save an object as a table, no sane
|
* ranges. Although the default thinking is to save an object as a table, no sane
|
||||||
* person would want a table of money values.
|
* person would want a table of money values. </p>
|
||||||
*
|
*
|
||||||
* An Embedded Value maps the values of an object to fields in the record of
|
* <p> An Embedded Value maps the values of an object to fields in the record of
|
||||||
* the object’s owner. In this implementation we have an Order object with links to an
|
* the object’s owner. In this implementation we have an Order object with links to an
|
||||||
* ShippingAddress object. In the resulting table the fields in the ShippingAddress
|
* ShippingAddress object. In the resulting table the fields in the ShippingAddress
|
||||||
* object map to fields in the Order table rather than make new records
|
* object map to fields in the Order table rather than make new records
|
||||||
* themselves.
|
* themselves. </p>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
@@ -62,11 +60,9 @@ public class App {
|
|||||||
final var order3 = new Order("Carrie Soto is Back", "Shiva",
|
final var order3 = new Order("Carrie Soto is Back", "Shiva",
|
||||||
new ShippingAddress("Bangalore", "Karnataka", "560004"));
|
new ShippingAddress("Bangalore", "Karnataka", "560004"));
|
||||||
|
|
||||||
/**
|
// Create table for orders - Orders(id, name, orderedBy, city, state, pincode).
|
||||||
* Create table for orders - Orders(id, name, orderedBy, city, state, pincode).
|
// We can see that table is different from the Order object we have.
|
||||||
* We can see that table is different from the Order object we have.
|
// We're mapping ShippingAddress into city, state, pincode colummns of the database and not creating a separate table.
|
||||||
* We're mapping ShippingAddress into city, state, pincode colummns of the database and not creating a separate table.
|
|
||||||
*/
|
|
||||||
if (dataSource.createSchema()) {
|
if (dataSource.createSchema()) {
|
||||||
LOGGER.info("TABLE CREATED");
|
LOGGER.info("TABLE CREATED");
|
||||||
LOGGER.info("Table \"Orders\" schema:\n" + dataSource.getSchema());
|
LOGGER.info("Table \"Orders\" schema:\n" + dataSource.getSchema());
|
||||||
@@ -84,21 +80,17 @@ public class App {
|
|||||||
dataSource.insertOrder(order2);
|
dataSource.insertOrder(order2);
|
||||||
dataSource.insertOrder(order3);
|
dataSource.insertOrder(order3);
|
||||||
|
|
||||||
/**
|
|
||||||
* Query orders
|
// Query orders.
|
||||||
* We'll create ShippingAddress object from city, state, pincode values from the table
|
// We'll create ShippingAddress object from city, state, pincode values from the table and add it to Order object
|
||||||
* and add it to Order object
|
|
||||||
*/
|
|
||||||
LOGGER.info("Orders Query: {}", dataSource.queryOrders().collect(Collectors.toList()) + "\n");
|
LOGGER.info("Orders Query: {}", dataSource.queryOrders().collect(Collectors.toList()) + "\n");
|
||||||
|
|
||||||
//Query order by given id
|
//Query order by given id
|
||||||
LOGGER.info("Query Order with id=2: {}", dataSource.queryOrder(2));
|
LOGGER.info("Query Order with id=2: {}", dataSource.queryOrder(2));
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove order by given id.
|
//Remove order by given id.
|
||||||
* Since we'd mapped address in the same table, deleting order will also take
|
//Since we'd mapped address in the same table, deleting order will also take out the shipping address details.
|
||||||
* out the shipping address details
|
|
||||||
*/
|
|
||||||
LOGGER.info("Remove Order with id=1");
|
LOGGER.info("Remove Order with id=1");
|
||||||
dataSource.removeOrder(1);
|
dataSource.removeOrder(1);
|
||||||
LOGGER.info("\nOrders Query: {}", dataSource.queryOrders().collect(Collectors.toList()) + "\n");
|
LOGGER.info("\nOrders Query: {}", dataSource.queryOrders().collect(Collectors.toList()) + "\n");
|
||||||
|
|||||||
@@ -31,36 +31,29 @@ import java.sql.SQLException;
|
|||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
/*
|
|
||||||
* Communicates with H2 database with the help of JDBC API
|
|
||||||
*
|
|
||||||
* Inherits the SQL queries and methods from @link AbstractDataSource class
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Communicates with H2 database with the help of JDBC API.
|
||||||
|
* Inherits the SQL queries and methods from @link AbstractDataSource class.
|
||||||
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class DataSource implements DataSourceInterface {
|
public class DataSource implements DataSourceInterface {
|
||||||
private Connection conn;
|
private Connection conn;
|
||||||
|
|
||||||
/**
|
// Statements are objects which are used to execute queries which will not be repeated.
|
||||||
* Statements are objects which are used to execute queries which will not be
|
|
||||||
* repeated.
|
|
||||||
*/
|
|
||||||
private Statement getschema;
|
private Statement getschema;
|
||||||
private Statement deleteschema;
|
private Statement deleteschema;
|
||||||
private Statement queryOrders;
|
private Statement queryOrders;
|
||||||
|
|
||||||
/*
|
// PreparedStatements are used to execute queries which will be repeated.
|
||||||
* PreparedStatements are used to execute queries which will be repeated.
|
|
||||||
*/
|
|
||||||
private PreparedStatement insertIntoOrders;
|
private PreparedStatement insertIntoOrders;
|
||||||
private PreparedStatement removeorder;
|
private PreparedStatement removeorder;
|
||||||
private PreparedStatement queyOrderByID;
|
private PreparedStatement queyOrderById;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@summary}
|
* {@summary Establish connection to database.
|
||||||
* Establish connection to database.
|
* Constructor to create DataSource object.}
|
||||||
*/
|
*/
|
||||||
public DataSource() {
|
public DataSource() {
|
||||||
try {
|
try {
|
||||||
@@ -79,7 +72,7 @@ public class DataSource implements DataSourceInterface {
|
|||||||
getschema = conn.createStatement();
|
getschema = conn.createStatement();
|
||||||
queryOrders = conn.createStatement();
|
queryOrders = conn.createStatement();
|
||||||
removeorder = conn.prepareStatement(REMOVE_ORDER);
|
removeorder = conn.prepareStatement(REMOVE_ORDER);
|
||||||
queyOrderByID = conn.prepareStatement(QUERY_ORDER);
|
queyOrderById = conn.prepareStatement(QUERY_ORDER);
|
||||||
deleteschema = conn.createStatement();
|
deleteschema = conn.createStatement();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LOGGER.error(e.getLocalizedMessage(), e.getCause());
|
LOGGER.error(e.getLocalizedMessage(), e.getCause());
|
||||||
@@ -156,7 +149,6 @@ public class DataSource implements DataSourceInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@summary}
|
|
||||||
* Query order by given id.
|
* Query order by given id.
|
||||||
* @param id as the parameter
|
* @param id as the parameter
|
||||||
* @return Order objct
|
* @return Order objct
|
||||||
@@ -166,9 +158,9 @@ public class DataSource implements DataSourceInterface {
|
|||||||
@Override
|
@Override
|
||||||
public Order queryOrder(int id) throws SQLException {
|
public Order queryOrder(int id) throws SQLException {
|
||||||
Order order = null;
|
Order order = null;
|
||||||
queyOrderByID.setInt(1, id);
|
queyOrderById.setInt(1, id);
|
||||||
try (var rSet = queyOrderByID.executeQuery()) {
|
try (var rSet = queyOrderById.executeQuery()) {
|
||||||
queyOrderByID.setInt(1, id);
|
queyOrderById.setInt(1, id);
|
||||||
if (rSet.next()) {
|
if (rSet.next()) {
|
||||||
var address = new ShippingAddress(rSet.getString(4),
|
var address = new ShippingAddress(rSet.getString(4),
|
||||||
rSet.getString(5), rSet.getString(6));
|
rSet.getString(5), rSet.getString(6));
|
||||||
@@ -204,7 +196,7 @@ public class DataSource implements DataSourceInterface {
|
|||||||
try {
|
try {
|
||||||
deleteschema.execute(DELETE_SCHEMA);
|
deleteschema.execute(DELETE_SCHEMA);
|
||||||
queryOrders.close();
|
queryOrders.close();
|
||||||
queyOrderByID.close();
|
queyOrderById.close();
|
||||||
deleteschema.close();
|
deleteschema.close();
|
||||||
insertIntoOrders.close();
|
insertIntoOrders.close();
|
||||||
conn.close();
|
conn.close();
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ package com.iluwatar.embedded.value;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
/*
|
|
||||||
|
/**
|
||||||
* A POJO which represents the Order object.
|
* A POJO which represents the Order object.
|
||||||
*/
|
*/
|
||||||
@ToString
|
@ToString
|
||||||
|
|||||||
@@ -63,8 +63,8 @@ public abstract class EventEmitter {
|
|||||||
protected void notifyObservers(Event e) {
|
protected void notifyObservers(Event e) {
|
||||||
if (observerLists.containsKey(e)) {
|
if (observerLists.containsKey(e)) {
|
||||||
observerLists
|
observerLists
|
||||||
.get(e)
|
.get(e)
|
||||||
.forEach(observer -> observer.onEvent(e));
|
.forEach(observer -> observer.onEvent(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
* Communicate with pending asynchronous operations using the familiar events-and-delegates model.
|
* Communicate with pending asynchronous operations using the familiar events-and-delegates model.
|
||||||
*
|
*
|
||||||
* @see EventManager
|
* @see EventManager
|
||||||
* @see Event
|
* @see AsyncEvent
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class App {
|
public class App {
|
||||||
|
|||||||
@@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||||
|
*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2022 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.iluwatar.event.asynchronous;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Each Event runs as a separate/individual thread.
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class AsyncEvent implements Event, Runnable {
|
||||||
|
|
||||||
|
private final int eventId;
|
||||||
|
private final int eventTime;
|
||||||
|
@Getter
|
||||||
|
private final boolean synchronous;
|
||||||
|
private Thread thread;
|
||||||
|
private boolean isComplete = false;
|
||||||
|
private ThreadCompleteListener eventListener;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start() {
|
||||||
|
thread = new Thread(this);
|
||||||
|
thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stop() {
|
||||||
|
if (null == thread) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
thread.interrupt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void status() {
|
||||||
|
if (!isComplete) {
|
||||||
|
LOGGER.info("[{}] is not done.", eventId);
|
||||||
|
} else {
|
||||||
|
LOGGER.info("[{}] is done.", eventId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
var currentTime = System.currentTimeMillis();
|
||||||
|
var endTime = currentTime + (eventTime * 1000);
|
||||||
|
while (System.currentTimeMillis() < endTime) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000); // Sleep for 1 second.
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
isComplete = true;
|
||||||
|
completed();
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void addListener(final ThreadCompleteListener listener) {
|
||||||
|
this.eventListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void removeListener() {
|
||||||
|
this.eventListener = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void completed() {
|
||||||
|
if (eventListener != null) {
|
||||||
|
eventListener.completedEventHandler(eventId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -24,76 +24,15 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.event.asynchronous;
|
package com.iluwatar.event.asynchronous;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Each Event runs as a separate/individual thread.
|
* Events that fulfill the start stop and list out current status behaviour follow this interface.
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
public interface Event {
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class Event implements IEvent, Runnable {
|
|
||||||
|
|
||||||
private final int eventId;
|
void start();
|
||||||
private final int eventTime;
|
|
||||||
@Getter
|
|
||||||
private final boolean synchronous;
|
|
||||||
private Thread thread;
|
|
||||||
private boolean isComplete = false;
|
|
||||||
private ThreadCompleteListener eventListener;
|
|
||||||
|
|
||||||
@Override
|
void stop();
|
||||||
public void start() {
|
|
||||||
thread = new Thread(this);
|
|
||||||
thread.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
void status();
|
||||||
public void stop() {
|
|
||||||
if (null == thread) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
thread.interrupt();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void status() {
|
|
||||||
if (!isComplete) {
|
|
||||||
LOGGER.info("[{}] is not done.", eventId);
|
|
||||||
} else {
|
|
||||||
LOGGER.info("[{}] is done.", eventId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
var currentTime = System.currentTimeMillis();
|
|
||||||
var endTime = currentTime + (eventTime * 1000);
|
|
||||||
while (System.currentTimeMillis() < endTime) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(1000); // Sleep for 1 second.
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
isComplete = true;
|
|
||||||
completed();
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void addListener(final ThreadCompleteListener listener) {
|
|
||||||
this.eventListener = listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void removeListener(final ThreadCompleteListener listener) {
|
|
||||||
this.eventListener = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void completed() {
|
|
||||||
if (eventListener != null) {
|
|
||||||
eventListener.completedEventHandler(eventId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EventManager handles and maintains a pool of event threads. {@link Event} threads are created
|
* EventManager handles and maintains a pool of event threads. {@link AsyncEvent} threads are created
|
||||||
* upon user request. Thre are two types of events; Asynchronous and Synchronous. There can be
|
* upon user request. Thre are two types of events; Asynchronous and Synchronous. There can be
|
||||||
* multiple Asynchronous events running at once but only one Synchronous event running at a time.
|
* multiple Asynchronous events running at once but only one Synchronous event running at a time.
|
||||||
* Currently supported event operations are: start, stop, and getStatus. Once an event is complete,
|
* Currently supported event operations are: start, stop, and getStatus. Once an event is complete,
|
||||||
@@ -45,7 +45,7 @@ public class EventManager implements ThreadCompleteListener {
|
|||||||
public static final int MAX_EVENT_TIME = 1800; // in seconds / 30 minutes.
|
public static final int MAX_EVENT_TIME = 1800; // in seconds / 30 minutes.
|
||||||
private int currentlyRunningSyncEvent = -1;
|
private int currentlyRunningSyncEvent = -1;
|
||||||
private final SecureRandom rand;
|
private final SecureRandom rand;
|
||||||
private final Map<Integer, Event> eventPool;
|
private final Map<Integer, AsyncEvent> eventPool;
|
||||||
|
|
||||||
private static final String DOES_NOT_EXIST = " does not exist.";
|
private static final String DOES_NOT_EXIST = " does not exist.";
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ public class EventManager implements ThreadCompleteListener {
|
|||||||
|
|
||||||
var newEventId = generateId();
|
var newEventId = generateId();
|
||||||
|
|
||||||
var newEvent = new Event(newEventId, eventTime, isSynchronous);
|
var newEvent = new AsyncEvent(newEventId, eventTime, isSynchronous);
|
||||||
newEvent.addListener(this);
|
newEvent.addListener(this);
|
||||||
eventPool.put(newEventId, newEvent);
|
eventPool.put(newEventId, newEvent);
|
||||||
|
|
||||||
@@ -167,7 +167,7 @@ public class EventManager implements ThreadCompleteListener {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public void statusOfAllEvents() {
|
public void statusOfAllEvents() {
|
||||||
eventPool.entrySet().forEach(entry -> ((Event) ((Map.Entry) entry).getValue()).status());
|
eventPool.entrySet().forEach(entry -> ((AsyncEvent) ((Map.Entry) entry).getValue()).status());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -175,7 +175,7 @@ public class EventManager implements ThreadCompleteListener {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
eventPool.entrySet().forEach(entry -> ((Event) ((Map.Entry) entry).getValue()).stop());
|
eventPool.entrySet().forEach(entry -> ((AsyncEvent) ((Map.Entry) entry).getValue()).stop());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -195,7 +195,7 @@ public class EventManager implements ThreadCompleteListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback from an {@link Event} (once it is complete). The Event is then removed from the pool.
|
* Callback from an {@link AsyncEvent} (once it is complete). The Event is then removed from the pool.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void completedEventHandler(int eventId) {
|
public void completedEventHandler(int eventId) {
|
||||||
@@ -209,7 +209,7 @@ public class EventManager implements ThreadCompleteListener {
|
|||||||
/**
|
/**
|
||||||
* Getter method for event pool.
|
* Getter method for event pool.
|
||||||
*/
|
*/
|
||||||
public Map<Integer, Event> getEventPool() {
|
public Map<Integer, AsyncEvent> getEventPool() {
|
||||||
return eventPool;
|
return eventPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+23
-1
@@ -136,4 +136,26 @@ class EventAsynchronousTest {
|
|||||||
LOGGER.error(e.getMessage());
|
LOGGER.error(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Test
|
||||||
|
void testLongRunningEventException(){
|
||||||
|
assertThrows(LongRunningEventException.class, () -> {
|
||||||
|
var eventManager = new EventManager();
|
||||||
|
eventManager.createAsync(2000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testMaxNumOfEventsAllowedException(){
|
||||||
|
assertThrows(MaxNumOfEventsAllowedException.class, () -> {
|
||||||
|
final var eventManager = new EventManager();
|
||||||
|
for(int i=0;i<1100;i++){
|
||||||
|
eventManager.createAsync(i);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -27,7 +27,6 @@ package com.iluwatar.execute.around;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ package com.iluwatar.execute.around;
|
|||||||
|
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import ch.qos.logback.core.read.ListAppender;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import units.CommanderUnit;
|
import units.CommanderUnit;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import ch.qos.logback.core.read.ListAppender;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import units.SergeantUnit;
|
import units.SergeantUnit;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
package com.iluwatar.factorykit;
|
package com.iluwatar.factorykit;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ package com.iluwatar.fanout.fanin;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
package com.iluwatar.fanout.fanin;
|
package com.iluwatar.fanout.fanin;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
package com.iluwatar.fanout.fanin;
|
package com.iluwatar.fanout.fanin;
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ package com.iluwatar.fanout.fanin;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|||||||
+2
-3
@@ -25,7 +25,6 @@
|
|||||||
package com.iluwatar.filterer.threat;
|
package com.iluwatar.filterer.threat;
|
||||||
|
|
||||||
import com.iluwatar.filterer.domain.Filterer;
|
import com.iluwatar.filterer.domain.Filterer;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,14 +34,14 @@ public interface ProbabilisticThreatAwareSystem extends ThreatAwareSystem {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
* @return
|
* @return {@link ProbableThreat}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
List<? extends ProbableThreat> threats();
|
List<? extends ProbableThreat> threats();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
* @return
|
* @return {@link Filterer}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
Filterer<? extends ProbabilisticThreatAwareSystem, ? extends ProbableThreat> filtered();
|
Filterer<? extends ProbabilisticThreatAwareSystem, ? extends ProbableThreat> filtered();
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
package com.iluwatar.filterer.threat;
|
package com.iluwatar.filterer.threat;
|
||||||
|
|
||||||
import com.iluwatar.filterer.domain.Filterer;
|
import com.iluwatar.filterer.domain.Filterer;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -24,6 +24,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.filterer.threat;
|
package com.iluwatar.filterer.threat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum class representing Threat types.
|
||||||
|
*/
|
||||||
public enum ThreatType {
|
public enum ThreatType {
|
||||||
TROJAN,
|
TROJAN,
|
||||||
WORM,
|
WORM,
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
package com.iluwatar.filterer.threat;
|
package com.iluwatar.filterer.threat;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|||||||
-1
@@ -28,7 +28,6 @@ import ch.qos.logback.classic.Logger;
|
|||||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||||
import ch.qos.logback.core.AppenderBase;
|
import ch.qos.logback.core.AppenderBase;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.identitymap;
|
package com.iluwatar.identitymap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Using Runtime Exception to control the flow in case Person Id doesn not exist.
|
||||||
|
*/
|
||||||
public class IdNotFoundException extends RuntimeException {
|
public class IdNotFoundException extends RuntimeException {
|
||||||
public IdNotFoundException(final String message) {
|
public IdNotFoundException(final String message) {
|
||||||
super(message);
|
super(message);
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ package com.iluwatar.identitymap;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
package com.iluwatar.identitymap;
|
package com.iluwatar.identitymap;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|||||||
@@ -24,13 +24,16 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.identitymap;
|
package com.iluwatar.identitymap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simulator interface for Person DB.
|
||||||
|
*/
|
||||||
public interface PersonDbSimulator {
|
public interface PersonDbSimulator {
|
||||||
Person find(int personNationalID);
|
Person find(int personNationalId);
|
||||||
|
|
||||||
void insert(Person person);
|
void insert(Person person);
|
||||||
|
|
||||||
void update(Person person);
|
void update(Person person);
|
||||||
|
|
||||||
void delete(int personNationalID);
|
void delete(int personNationalId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -27,7 +27,6 @@ package com.iluwatar.identitymap;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,10 +48,10 @@ public class PersonDbSimulatorImplementation implements PersonDbSimulator {
|
|||||||
static final String ID_STR = "ID : ";
|
static final String ID_STR = "ID : ";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Person find(int personNationalID) throws IdNotFoundException {
|
public Person find(int personNationalId) throws IdNotFoundException {
|
||||||
Optional<Person> elem = personList.stream().filter(p -> p.getPersonNationalId() == personNationalID).findFirst();
|
Optional<Person> elem = personList.stream().filter(p -> p.getPersonNationalId() == personNationalId).findFirst();
|
||||||
if (elem.isEmpty()) {
|
if (elem.isEmpty()) {
|
||||||
throw new IdNotFoundException(ID_STR + personNationalID + NOT_IN_DATA_BASE);
|
throw new IdNotFoundException(ID_STR + personNationalId + NOT_IN_DATA_BASE);
|
||||||
}
|
}
|
||||||
LOGGER.info(elem.get().toString());
|
LOGGER.info(elem.get().toString());
|
||||||
return elem.get();
|
return elem.get();
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ public class Target extends JFrame { //NOSONAR
|
|||||||
jsp.setPreferredSize(new Dimension(500, 250));
|
jsp.setPreferredSize(new Dimension(500, 250));
|
||||||
add(jsp, BorderLayout.CENTER);
|
add(jsp, BorderLayout.CENTER);
|
||||||
|
|
||||||
del.addActionListener(new DListener());
|
del.addActionListener(new TargetListener());
|
||||||
|
|
||||||
var rootPane = SwingUtilities.getRootPane(del);
|
var rootPane = SwingUtilities.getRootPane(del);
|
||||||
rootPane.setDefaultButton(del);
|
rootPane.setDefaultButton(del);
|
||||||
@@ -87,7 +87,7 @@ public class Target extends JFrame { //NOSONAR
|
|||||||
dtm.addRow(new Object[]{request[0], request[1], request[2], request[3], request[4]});
|
dtm.addRow(new Object[]{request[0], request[1], request[2], request[3], request[4]});
|
||||||
}
|
}
|
||||||
|
|
||||||
class DListener implements ActionListener {
|
class TargetListener implements ActionListener {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
var temp = jt.getSelectedRow();
|
var temp = jt.getSelectedRow();
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* This project is licensed under the MIT license. Module intercepting-filter is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||||
|
*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2022 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.iluwatar.intercepting.filter;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Date: 01/29/23 - 1:33 PM
|
||||||
|
*
|
||||||
|
* @author Rahul Raj
|
||||||
|
*/
|
||||||
|
class TargetTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testSetup(){
|
||||||
|
final var target = new Target();
|
||||||
|
assertEquals(target.getSize().getWidth(), Double.valueOf(640));
|
||||||
|
assertEquals(target.getSize().getHeight(), Double.valueOf(480));
|
||||||
|
assertEquals(true,target.isVisible());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,7 +26,6 @@ package com.iluwatar.layers.entity;
|
|||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.FetchType;
|
import javax.persistence.FetchType;
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ package com.iluwatar.leaderfollowers;
|
|||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Worker class that takes work from work center.
|
||||||
|
*/
|
||||||
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class Worker implements Runnable {
|
public class Worker implements Runnable {
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public class App {
|
|||||||
// get service
|
// get service
|
||||||
var userService = new UserService();
|
var userService = new UserService();
|
||||||
// use create service to add users
|
// use create service to add users
|
||||||
for (var user: generateSampleUsers()) {
|
for (var user : generateSampleUsers()) {
|
||||||
var id = userService.createUser(user);
|
var id = userService.createUser(user);
|
||||||
LOGGER.info("Add user" + user + "at" + id + ".");
|
LOGGER.info("Add user" + user + "at" + id + ".");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,9 +47,6 @@ public class DatabaseUtil {
|
|||||||
*/
|
*/
|
||||||
private DatabaseUtil() {}
|
private DatabaseUtil() {}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create database.
|
|
||||||
*/
|
|
||||||
static {
|
static {
|
||||||
LOGGER.info("create h2 database");
|
LOGGER.info("create h2 database");
|
||||||
var source = new JdbcDataSource();
|
var source = new JdbcDataSource();
|
||||||
|
|||||||
-1
@@ -2,7 +2,6 @@ package com.iluwatar.model.view.intent;
|
|||||||
|
|
||||||
import com.iluwatar.model.view.intent.actions.*;
|
import com.iluwatar.model.view.intent.actions.*;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<class-diagram version="1.1.8" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true"
|
<class-diagram version="1.1.8" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true"
|
||||||
realizations="true" associations="true" dependencies="false" nesting-relationships="true">
|
realizations="true" associations="true" dependencies="false" nesting-relationships="true">
|
||||||
<class id="1" language="java" name="com.iluwatar.model.view.presenter.FileSelectorJFrame"
|
<class id="1" language="java" name="com.iluwatar.model.view.presenter.FileSelectorJframe"
|
||||||
project="model-view-presenter"
|
project="model-view-presenter"
|
||||||
file="/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorJFrame.java" binary="false"
|
file="/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorJframe.java" binary="false"
|
||||||
corner="BOTTOM_RIGHT">
|
corner="BOTTOM_RIGHT">
|
||||||
<position height="430" width="259" x="33" y="149"/>
|
<position height="430" width="259" x="33" y="149"/>
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ package com.iluwatar.model.view.presenter {
|
|||||||
+ loadData() : String
|
+ loadData() : String
|
||||||
+ setFileName(fileName : String)
|
+ setFileName(fileName : String)
|
||||||
}
|
}
|
||||||
class FileSelectorJFrame {
|
class FileSelectorJframe {
|
||||||
- area : JTextArea
|
- area : JTextArea
|
||||||
- cancel : JButton
|
- cancel : JButton
|
||||||
- contents : JLabel
|
- contents : JLabel
|
||||||
@@ -27,7 +27,7 @@ package com.iluwatar.model.view.presenter {
|
|||||||
- panel : JPanel
|
- panel : JPanel
|
||||||
- presenter : FileSelectorPresenter
|
- presenter : FileSelectorPresenter
|
||||||
- serialVersionUID : long {static}
|
- serialVersionUID : long {static}
|
||||||
+ FileSelectorJFrame()
|
+ FileSelectorJframe()
|
||||||
+ actionPerformed(e : ActionEvent)
|
+ actionPerformed(e : ActionEvent)
|
||||||
+ close()
|
+ close()
|
||||||
+ displayData(data : String)
|
+ displayData(data : String)
|
||||||
@@ -81,10 +81,10 @@ package com.iluwatar.model.view.presenter {
|
|||||||
+ showMessage(String) {abstract}
|
+ showMessage(String) {abstract}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FileSelectorJFrame --> "-presenter" FileSelectorPresenter
|
FileSelectorJframe --> "-presenter" FileSelectorPresenter
|
||||||
FileSelectorStub --> "-presenter" FileSelectorPresenter
|
FileSelectorStub --> "-presenter" FileSelectorPresenter
|
||||||
FileSelectorPresenter --> "-view" FileSelectorView
|
FileSelectorPresenter --> "-view" FileSelectorView
|
||||||
FileSelectorPresenter --> "-loader" FileLoader
|
FileSelectorPresenter --> "-loader" FileLoader
|
||||||
FileSelectorJFrame ..|> FileSelectorView
|
FileSelectorJframe ..|> FileSelectorView
|
||||||
FileSelectorStub ..|> FileSelectorView
|
FileSelectorStub ..|> FileSelectorView
|
||||||
@enduml
|
@enduml
|
||||||
@@ -31,7 +31,7 @@ package com.iluwatar.model.view.presenter;
|
|||||||
* (Presenter).
|
* (Presenter).
|
||||||
*
|
*
|
||||||
* <p>In the following example, The {@link FileLoader} class represents the app's logic, the {@link
|
* <p>In the following example, The {@link FileLoader} class represents the app's logic, the {@link
|
||||||
* FileSelectorJFrame} is the GUI and the {@link FileSelectorPresenter} is responsible to respond to
|
* FileSelectorJframe} is the GUI and the {@link FileSelectorPresenter} is responsible to respond to
|
||||||
* users' actions.
|
* users' actions.
|
||||||
*
|
*
|
||||||
* <p>Finally, please notice the wiring between the Presenter and the View and between the
|
* <p>Finally, please notice the wiring between the Presenter and the View and between the
|
||||||
@@ -46,7 +46,7 @@ public class App {
|
|||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
var loader = new FileLoader();
|
var loader = new FileLoader();
|
||||||
var frame = new FileSelectorJFrame();
|
var frame = new FileSelectorJframe();
|
||||||
var presenter = new FileSelectorPresenter(frame);
|
var presenter = new FileSelectorPresenter(frame);
|
||||||
presenter.setLoader(loader);
|
presenter.setLoader(loader);
|
||||||
presenter.start();
|
presenter.start();
|
||||||
|
|||||||
+2
-3
@@ -30,7 +30,6 @@ import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
@@ -43,7 +42,7 @@ import javax.swing.JTextField;
|
|||||||
/**
|
/**
|
||||||
* This class is the GUI implementation of the View component in the Model-View-Presenter pattern.
|
* This class is the GUI implementation of the View component in the Model-View-Presenter pattern.
|
||||||
*/
|
*/
|
||||||
public class FileSelectorJFrame extends JFrame implements FileSelectorView, ActionListener {
|
public class FileSelectorJframe extends JFrame implements FileSelectorView, ActionListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default serial version ID.
|
* Default serial version ID.
|
||||||
@@ -83,7 +82,7 @@ public class FileSelectorJFrame extends JFrame implements FileSelectorView, Acti
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public FileSelectorJFrame() {
|
public FileSelectorJframe() {
|
||||||
super("File Loader");
|
super("File Loader");
|
||||||
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
this.setLayout(null);
|
this.setLayout(null);
|
||||||
+24
-10
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
* This project is licensed under the MIT license. Module model-view-presenter is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||||
*
|
*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright © 2014-2022 Ilkka Seppälä
|
* Copyright © 2014-2022 Ilkka Seppälä
|
||||||
@@ -22,17 +22,31 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package com.iluwatar.event.asynchronous;
|
package com.iluwatar.model.view.presenter;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Events that fulfill the start stop and list out current status behaviour follow this interface.
|
* Date: 01/29/23 - 6:00 PM
|
||||||
|
*
|
||||||
|
* @author Rahul Raj
|
||||||
*/
|
*/
|
||||||
public interface IEvent {
|
class FileSelectorJframeTest {
|
||||||
|
|
||||||
void start();
|
/**
|
||||||
|
* Tests if the jframe action event is triggered without any exception.
|
||||||
void stop();
|
*/
|
||||||
|
@Test
|
||||||
void status();
|
void testActionEvent() {
|
||||||
|
assertDoesNotThrow(() ->{
|
||||||
|
FileSelectorJframe jFrame = new FileSelectorJframe();
|
||||||
|
ActionEvent action = new ActionEvent("dummy", 1, "dummy");
|
||||||
|
jFrame.actionPerformed(action);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+12
@@ -144,4 +144,16 @@ class FileSelectorPresenterTest {
|
|||||||
|
|
||||||
assertFalse(stub.isOpened());
|
assertFalse(stub.isOpened());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testNullFile() {
|
||||||
|
stub.setFileName(null);
|
||||||
|
presenter.start();
|
||||||
|
presenter.fileNameChanged();
|
||||||
|
presenter.confirmed();
|
||||||
|
|
||||||
|
assertFalse(loader.isLoaded());
|
||||||
|
assertFalse(stub.dataDisplayed());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ package com.iluwatar.model.view.viewmodel;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Book class.
|
||||||
|
*/
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Data
|
@Data
|
||||||
public class Book {
|
public class Book {
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ package com.iluwatar.model.view.viewmodel;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class representing a service to load books.
|
||||||
|
*/
|
||||||
public interface BookService {
|
public interface BookService {
|
||||||
/* List all books
|
/* List all books
|
||||||
* @return all books
|
* @return all books
|
||||||
|
|||||||
+3
@@ -27,6 +27,9 @@ package com.iluwatar.model.view.viewmodel;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class that actually implement the books to load.
|
||||||
|
*/
|
||||||
public class BookServiceImpl implements BookService {
|
public class BookServiceImpl implements BookService {
|
||||||
private List<Book> designPatternBooks = new ArrayList<>();
|
private List<Book> designPatternBooks = new ArrayList<>();
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -25,11 +25,13 @@
|
|||||||
package com.iluwatar.model.view.viewmodel;
|
package com.iluwatar.model.view.viewmodel;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.zkoss.bind.annotation.Command;
|
import org.zkoss.bind.annotation.Command;
|
||||||
import org.zkoss.bind.annotation.NotifyChange;
|
import org.zkoss.bind.annotation.NotifyChange;
|
||||||
import org.zkoss.zk.ui.select.annotation.WireVariable;
|
import org.zkoss.zk.ui.select.annotation.WireVariable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BookViewModel class.
|
||||||
|
*/
|
||||||
public class BookViewModel {
|
public class BookViewModel {
|
||||||
|
|
||||||
@WireVariable
|
@WireVariable
|
||||||
@@ -56,7 +58,7 @@ public class BookViewModel {
|
|||||||
* and used to delete the selected book from the list of books.
|
* and used to delete the selected book from the list of books.
|
||||||
*/
|
*/
|
||||||
@Command
|
@Command
|
||||||
@NotifyChange({"selectedBook","bookList"})
|
@NotifyChange({"selectedBook", "bookList"})
|
||||||
public void deleteBook() {
|
public void deleteBook() {
|
||||||
if (selectedBook != null) {
|
if (selectedBook != null) {
|
||||||
getBookList().remove(selectedBook);
|
getBookList().remove(selectedBook);
|
||||||
|
|||||||
@@ -24,9 +24,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.observer;
|
package com.iluwatar.observer;
|
||||||
|
|
||||||
import com.iluwatar.observer.generic.GHobbits;
|
import com.iluwatar.observer.generic.GenHobbits;
|
||||||
import com.iluwatar.observer.generic.GOrcs;
|
import com.iluwatar.observer.generic.GenOrcs;
|
||||||
import com.iluwatar.observer.generic.GWeather;
|
import com.iluwatar.observer.generic.GenWeather;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,9 +61,9 @@ public class App {
|
|||||||
|
|
||||||
// Generic observer inspired by Java Generics and Collections by Naftalin & Wadler
|
// Generic observer inspired by Java Generics and Collections by Naftalin & Wadler
|
||||||
LOGGER.info("--Running generic version--");
|
LOGGER.info("--Running generic version--");
|
||||||
var genericWeather = new GWeather();
|
var genericWeather = new GenWeather();
|
||||||
genericWeather.addObserver(new GOrcs());
|
genericWeather.addObserver(new GenOrcs());
|
||||||
genericWeather.addObserver(new GHobbits());
|
genericWeather.addObserver(new GenHobbits());
|
||||||
|
|
||||||
genericWeather.timePasses();
|
genericWeather.timePasses();
|
||||||
genericWeather.timePasses();
|
genericWeather.timePasses();
|
||||||
|
|||||||
+2
-2
@@ -31,10 +31,10 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
* GHobbits.
|
* GHobbits.
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class GHobbits implements Race {
|
public class GenHobbits implements Race {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(GWeather weather, WeatherType weatherType) {
|
public void update(GenWeather weather, WeatherType weatherType) {
|
||||||
LOGGER.info("The hobbits are facing " + weatherType.getDescription() + " weather now");
|
LOGGER.info("The hobbits are facing " + weatherType.getDescription() + " weather now");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-2
@@ -31,10 +31,10 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
* GOrcs.
|
* GOrcs.
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class GOrcs implements Race {
|
public class GenOrcs implements Race {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(GWeather weather, WeatherType weatherType) {
|
public void update(GenWeather weather, WeatherType weatherType) {
|
||||||
LOGGER.info("The orcs are facing " + weatherType.getDescription() + " weather now");
|
LOGGER.info("The orcs are facing " + weatherType.getDescription() + " weather now");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-2
@@ -31,11 +31,11 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
* GWeather.
|
* GWeather.
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class GWeather extends Observable<GWeather, Race, WeatherType> {
|
public class GenWeather extends Observable<GenWeather, Race, WeatherType> {
|
||||||
|
|
||||||
private WeatherType currentWeather;
|
private WeatherType currentWeather;
|
||||||
|
|
||||||
public GWeather() {
|
public GenWeather() {
|
||||||
currentWeather = WeatherType.SUNNY;
|
currentWeather = WeatherType.SUNNY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,5 +29,5 @@ import com.iluwatar.observer.WeatherType;
|
|||||||
/**
|
/**
|
||||||
* Race.
|
* Race.
|
||||||
*/
|
*/
|
||||||
public interface Race extends Observer<GWeather, Race, WeatherType> {
|
public interface Race extends Observer<GenWeather, Race, WeatherType> {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import com.iluwatar.observer.utils.InMemoryAppender;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
package com.iluwatar.observer.generic;
|
package com.iluwatar.observer.generic;
|
||||||
|
|
||||||
import com.iluwatar.observer.WeatherType;
|
import com.iluwatar.observer.WeatherType;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -34,7 +33,7 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* @author Jeroen Meulemeester
|
* @author Jeroen Meulemeester
|
||||||
*/
|
*/
|
||||||
class GHobbitsTest extends ObserverTest<GHobbits> {
|
class GHobbitsTest extends ObserverTest<GenHobbits> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Object[]> dataProvider() {
|
public Collection<Object[]> dataProvider() {
|
||||||
@@ -50,7 +49,7 @@ class GHobbitsTest extends ObserverTest<GHobbits> {
|
|||||||
* Create a new test with the given weather and expected response
|
* Create a new test with the given weather and expected response
|
||||||
*/
|
*/
|
||||||
public GHobbitsTest() {
|
public GHobbitsTest() {
|
||||||
super(GHobbits::new);
|
super(GenHobbits::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class GWeatherTest {
|
|||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
void setUp() {
|
||||||
appender = new InMemoryAppender(GWeather.class);
|
appender = new InMemoryAppender(GenWeather.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
@@ -64,7 +64,7 @@ class GWeatherTest {
|
|||||||
void testAddRemoveObserver() {
|
void testAddRemoveObserver() {
|
||||||
final var observer = mock(Race.class);
|
final var observer = mock(Race.class);
|
||||||
|
|
||||||
final var weather = new GWeather();
|
final var weather = new GenWeather();
|
||||||
weather.addObserver(observer);
|
weather.addObserver(observer);
|
||||||
verifyNoMoreInteractions(observer);
|
verifyNoMoreInteractions(observer);
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ class GWeatherTest {
|
|||||||
@Test
|
@Test
|
||||||
void testTimePasses() {
|
void testTimePasses() {
|
||||||
final var observer = mock(Race.class);
|
final var observer = mock(Race.class);
|
||||||
final var weather = new GWeather();
|
final var weather = new GenWeather();
|
||||||
weather.addObserver(observer);
|
weather.addObserver(observer);
|
||||||
|
|
||||||
final var inOrder = inOrder(observer);
|
final var inOrder = inOrder(observer);
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
package com.iluwatar.observer.generic;
|
package com.iluwatar.observer.generic;
|
||||||
|
|
||||||
import com.iluwatar.observer.WeatherType;
|
import com.iluwatar.observer.WeatherType;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -34,7 +33,7 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* @author Jeroen Meulemeester
|
* @author Jeroen Meulemeester
|
||||||
*/
|
*/
|
||||||
class OrcsTest extends ObserverTest<GOrcs> {
|
class OrcsTest extends ObserverTest<GenOrcs> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Object[]> dataProvider() {
|
public Collection<Object[]> dataProvider() {
|
||||||
@@ -50,7 +49,7 @@ class OrcsTest extends ObserverTest<GOrcs> {
|
|||||||
* Create a new test with the given weather and expected response
|
* Create a new test with the given weather and expected response
|
||||||
*/
|
*/
|
||||||
public OrcsTest() {
|
public OrcsTest() {
|
||||||
super(GOrcs::new);
|
super(GenOrcs::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import ch.qos.logback.classic.Logger;
|
|||||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||||
import ch.qos.logback.core.AppenderBase;
|
import ch.qos.logback.core.AppenderBase;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.parameter.object;
|
package com.iluwatar.parameter.object;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ParameterObject.
|
||||||
|
*/
|
||||||
public class ParameterObject {
|
public class ParameterObject {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,6 +86,9 @@ public class ParameterObject {
|
|||||||
type, sortBy, sortOrder);
|
type, sortBy, sortOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder for ParameterObject.
|
||||||
|
*/
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
|
|
||||||
private String type;
|
private String type;
|
||||||
|
|||||||
@@ -24,6 +24,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.parameter.object;
|
package com.iluwatar.parameter.object;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SearchService to demonstrate parameter object pattern.
|
||||||
|
*/
|
||||||
public class SearchService {
|
public class SearchService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -24,6 +24,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.parameter.object;
|
package com.iluwatar.parameter.object;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* enum for sort order types.
|
||||||
|
*/
|
||||||
public enum SortOrder {
|
public enum SortOrder {
|
||||||
ASC("asc"),
|
ASC("asc"),
|
||||||
DESC("desc");
|
DESC("desc");
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user