Skip to content

Commit 4f9ee01

Browse files
anuragagarwal561994iluwatar
authored andcommitted
Resolves checkstyle errors for converter, cqrs (iluwatar#1063)
* Reduces checkstyle errors in converter * Reduces checkstyle errors in cqrs
1 parent 2f49648 commit 4f9ee01

File tree

16 files changed

+129
-127
lines changed

16 files changed

+129
-127
lines changed

converter/src/main/java/com/iluwatar/converter/App.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@
2323

2424
package com.iluwatar.converter;
2525

26-
26+
import java.util.List;
2727
import org.slf4j.Logger;
2828
import org.slf4j.LoggerFactory;
2929

30-
import java.util.List;
31-
3230
/**
3331
* The Converter pattern is a behavioral design pattern which allows a common way of bidirectional
3432
* conversion between corresponding types (e.g. DTO and domain representations of the logically
@@ -38,8 +36,9 @@
3836
public class App {
3937

4038
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
39+
4140
/**
42-
* Program entry point
41+
* Program entry point.
4342
*
4443
* @param args command line args
4544
*/

converter/src/main/java/com/iluwatar/converter/Converter.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030

3131
/**
3232
* Generic converter, thanks to Java8 features not only provides a way of generic bidirectional
33-
* conversion between corresponding types, but also a common way of converting a collection of objects
34-
* of the same type, reducing boilerplate code to the absolute minimum.
33+
* conversion between corresponding types, but also a common way of converting a collection of
34+
* objects of the same type, reducing boilerplate code to the absolute minimum.
35+
*
3536
* @param <T> DTO representation's type
3637
* @param <U> Domain representation's type
3738
*/
@@ -41,7 +42,9 @@ public class Converter<T, U> {
4142
private final Function<U, T> fromEntity;
4243

4344
/**
44-
* @param fromDto Function that converts given dto entity into the domain entity.
45+
* Constructor.
46+
*
47+
* @param fromDto Function that converts given dto entity into the domain entity.
4548
* @param fromEntity Function that converts given domain entity into the dto entity.
4649
*/
4750
public Converter(final Function<T, U> fromDto, final Function<U, T> fromEntity) {
@@ -50,34 +53,44 @@ public Converter(final Function<T, U> fromDto, final Function<U, T> fromEntity)
5053
}
5154

5255
/**
56+
* Converts DTO to Entity.
57+
*
5358
* @param dto DTO entity
54-
* @return The domain representation - the result of the converting function application on dto entity.
59+
* @return The domain representation - the result of the converting function application on dto
60+
* entity.
5561
*/
5662
public final U convertFromDto(final T dto) {
5763
return fromDto.apply(dto);
5864
}
5965

6066
/**
67+
* Converts Entity to DTO.
68+
*
6169
* @param entity domain entity
62-
* @return The DTO representation - the result of the converting function application on domain entity.
70+
* @return The DTO representation - the result of the converting function application on domain
71+
* entity.
6372
*/
6473
public final T convertFromEntity(final U entity) {
6574
return fromEntity.apply(entity);
6675
}
6776

6877
/**
78+
* Converts list of DTOs to list of Entities.
79+
*
6980
* @param dtos collection of DTO entities
70-
* @return List of domain representation of provided entities retrieved by
71-
* mapping each of them with the conversion function
81+
* @return List of domain representation of provided entities retrieved by mapping each of them
82+
* with the conversion function
7283
*/
7384
public final List<U> createFromDtos(final Collection<T> dtos) {
7485
return dtos.stream().map(this::convertFromDto).collect(Collectors.toList());
7586
}
7687

7788
/**
89+
* Converts list of Entities to list of DTOs.
90+
*
7891
* @param entities collection of domain entities
79-
* @return List of domain representation of provided entities retrieved by
80-
* mapping each of them with the conversion function
92+
* @return List of domain representation of provided entities retrieved by mapping each of them
93+
* with the conversion function
8194
*/
8295
public final List<T> createFromEntities(final Collection<U> entities) {
8396
return entities.stream().map(this::convertFromEntity).collect(Collectors.toList());

converter/src/main/java/com/iluwatar/converter/User.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.util.Objects;
2727

2828
/**
29-
* User class
29+
* User class.
3030
*/
3131
public class User {
3232
private String firstName;
@@ -35,10 +35,12 @@ public class User {
3535
private String userId;
3636

3737
/**
38+
* Constructor.
39+
*
3840
* @param firstName user's first name
3941
* @param lastName user's last name
4042
* @param isActive flag indicating whether the user is active
41-
* @param userId user's identificator
43+
* @param userId user's identificator
4244
*/
4345
public User(String firstName, String lastName, boolean isActive, String userId) {
4446
this.firstName = firstName;
@@ -63,7 +65,8 @@ public String getUserId() {
6365
return userId;
6466
}
6567

66-
@Override public boolean equals(Object o) {
68+
@Override
69+
public boolean equals(Object o) {
6770
if (this == o) {
6871
return true;
6972
}
@@ -72,15 +75,17 @@ public String getUserId() {
7275
}
7376
User user = (User) o;
7477
return isActive == user.isActive && Objects.equals(firstName, user.firstName) && Objects
75-
.equals(lastName, user.lastName) && Objects.equals(userId, user.userId);
78+
.equals(lastName, user.lastName) && Objects.equals(userId, user.userId);
7679
}
7780

78-
@Override public int hashCode() {
81+
@Override
82+
public int hashCode() {
7983
return Objects.hash(firstName, lastName, isActive, userId);
8084
}
8185

82-
@Override public String toString() {
86+
@Override
87+
public String toString() {
8388
return "User{" + "firstName='" + firstName + '\'' + ", lastName='" + lastName + '\''
84-
+ ", isActive=" + isActive + ", userId='" + userId + '\'' + '}';
89+
+ ", isActive=" + isActive + ", userId='" + userId + '\'' + '}';
8590
}
8691
}

converter/src/main/java/com/iluwatar/converter/UserConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public class UserConverter extends Converter<UserDto, User> {
3333
*/
3434
public UserConverter() {
3535
super(userDto -> new User(userDto.getFirstName(), userDto.getLastName(), userDto.isActive(),
36-
userDto.getEmail()),
36+
userDto.getEmail()),
3737
user -> new UserDto(user.getFirstName(), user.getLastName(), user.isActive(),
38-
user.getUserId()));
38+
user.getUserId()));
3939
}
4040
}

converter/src/main/java/com/iluwatar/converter/UserDto.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@
2323

2424
package com.iluwatar.converter;
2525

26-
2726
import java.util.Objects;
2827

2928
/**
30-
* User DTO class
29+
* User DTO class.
3130
*/
3231
public class UserDto {
3332

@@ -37,6 +36,8 @@ public class UserDto {
3736
private String email;
3837

3938
/**
39+
* Constructor.
40+
*
4041
* @param firstName user's first name
4142
* @param lastName user's last name
4243
* @param isActive flag indicating whether the user is active
@@ -65,7 +66,8 @@ public String getEmail() {
6566
return email;
6667
}
6768

68-
@Override public boolean equals(Object o) {
69+
@Override
70+
public boolean equals(Object o) {
6971
if (this == o) {
7072
return true;
7173
}
@@ -74,15 +76,17 @@ public String getEmail() {
7476
}
7577
UserDto userDto = (UserDto) o;
7678
return isActive == userDto.isActive && Objects.equals(firstName, userDto.firstName) && Objects
77-
.equals(lastName, userDto.lastName) && Objects.equals(email, userDto.email);
79+
.equals(lastName, userDto.lastName) && Objects.equals(email, userDto.email);
7880
}
7981

80-
@Override public int hashCode() {
82+
@Override
83+
public int hashCode() {
8184
return Objects.hash(firstName, lastName, isActive, email);
8285
}
8386

84-
@Override public String toString() {
87+
@Override
88+
public String toString() {
8589
return "UserDto{" + "firstName='" + firstName + '\'' + ", lastName='" + lastName + '\''
86-
+ ", isActive=" + isActive + ", email='" + email + '\'' + '}';
90+
+ ", isActive=" + isActive + ", email='" + email + '\'' + '}';
8791
}
8892
}

cqrs/src/main/java/com/iluwatar/cqrs/app/App.java

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@
2323

2424
package com.iluwatar.cqrs.app;
2525

26-
import java.math.BigInteger;
27-
import java.util.List;
28-
29-
import org.slf4j.Logger;
30-
import org.slf4j.LoggerFactory;
31-
3226
import com.iluwatar.cqrs.commandes.CommandServiceImpl;
3327
import com.iluwatar.cqrs.commandes.ICommandService;
3428
import com.iluwatar.cqrs.constants.AppConstants;
@@ -37,59 +31,63 @@
3731
import com.iluwatar.cqrs.queries.IQueryService;
3832
import com.iluwatar.cqrs.queries.QueryServiceImpl;
3933
import com.iluwatar.cqrs.util.HibernateUtil;
34+
import java.math.BigInteger;
35+
import java.util.List;
36+
import org.slf4j.Logger;
37+
import org.slf4j.LoggerFactory;
4038

4139
/**
42-
* CQRS : Command Query Responsibility Segregation. A pattern used to separate query services from commands or writes
43-
* services. The pattern is very simple but it has many consequences. For example, it can be used to tackle down a
44-
* complex domain, or to use other architectures that were hard to implement with the classical way.
45-
*
46-
* This implementation is an example of managing books and authors in a library. The persistence of books and authors is
47-
* done according to the CQRS architecture. A command side that deals with a data model to persist(insert,update,delete)
48-
* objects to a database. And a query side that uses native queries to get data from the database and return objects as
49-
* DTOs (Data transfer Objects).
40+
* CQRS : Command Query Responsibility Segregation. A pattern used to separate query services from
41+
* commands or writes services. The pattern is very simple but it has many consequences. For
42+
* example, it can be used to tackle down a complex domain, or to use other architectures that were
43+
* hard to implement with the classical way.
5044
*
45+
* <p>This implementation is an example of managing books and authors in a library. The persistence
46+
* of books and authors is done according to the CQRS architecture. A command side that deals with a
47+
* data model to persist(insert,update,delete) objects to a database. And a query side that uses
48+
* native queries to get data from the database and return objects as DTOs (Data transfer Objects).
5149
*/
5250
public class App {
5351
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
5452

5553
/**
56-
* Program entry point
57-
*
58-
* @param args
59-
* command line args
54+
* Program entry point.
55+
*
56+
* @param args command line args
6057
*/
6158
public static void main(String[] args) {
6259
ICommandService commands = new CommandServiceImpl();
6360

6461
// Create Authors and Books using CommandService
65-
commands.authorCreated(AppConstants.E_EVANS, "Eric Evans", "eEvans@email.com");
62+
commands.authorCreated(AppConstants.E_EVANS, "Eric Evans", "evans@email.com");
6663
commands.authorCreated(AppConstants.J_BLOCH, "Joshua Bloch", "jBloch@email.com");
6764
commands.authorCreated(AppConstants.M_FOWLER, "Martin Fowler", "mFowler@email.com");
6865

6966
commands.bookAddedToAuthor("Domain-Driven Design", 60.08, AppConstants.E_EVANS);
7067
commands.bookAddedToAuthor("Effective Java", 40.54, AppConstants.J_BLOCH);
7168
commands.bookAddedToAuthor("Java Puzzlers", 39.99, AppConstants.J_BLOCH);
7269
commands.bookAddedToAuthor("Java Concurrency in Practice", 29.40, AppConstants.J_BLOCH);
73-
commands.bookAddedToAuthor("Patterns of Enterprise Application Architecture", 54.01, AppConstants.M_FOWLER);
70+
commands.bookAddedToAuthor("Patterns of Enterprise"
71+
+ " Application Architecture", 54.01, AppConstants.M_FOWLER);
7472
commands.bookAddedToAuthor("Domain Specific Languages", 48.89, AppConstants.M_FOWLER);
7573
commands.authorNameUpdated(AppConstants.E_EVANS, "Eric J. Evans");
7674

7775
IQueryService queries = new QueryServiceImpl();
7876

7977
// Query the database using QueryService
8078
Author nullAuthor = queries.getAuthorByUsername("username");
81-
Author eEvans = queries.getAuthorByUsername(AppConstants.E_EVANS);
82-
BigInteger jBlochBooksCount = queries.getAuthorBooksCount(AppConstants.J_BLOCH);
79+
Author evans = queries.getAuthorByUsername(AppConstants.E_EVANS);
80+
BigInteger blochBooksCount = queries.getAuthorBooksCount(AppConstants.J_BLOCH);
8381
BigInteger authorsCount = queries.getAuthorsCount();
8482
Book dddBook = queries.getBook("Domain-Driven Design");
85-
List<Book> jBlochBooks = queries.getAuthorBooks(AppConstants.J_BLOCH);
83+
List<Book> blochBooks = queries.getAuthorBooks(AppConstants.J_BLOCH);
8684

8785
LOGGER.info("Author username : {}", nullAuthor);
88-
LOGGER.info("Author eEvans : {}", eEvans);
89-
LOGGER.info("jBloch number of books : {}", jBlochBooksCount);
86+
LOGGER.info("Author evans : {}", evans);
87+
LOGGER.info("jBloch number of books : {}", blochBooksCount);
9088
LOGGER.info("Number of authors : {}", authorsCount);
9189
LOGGER.info("DDD book : {}", dddBook);
92-
LOGGER.info("jBloch books : {}", jBlochBooks);
90+
LOGGER.info("jBloch books : {}", blochBooks);
9391

9492
HibernateUtil.getSessionFactory().close();
9593
}

cqrs/src/main/java/com/iluwatar/cqrs/commandes/CommandServiceImpl.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,16 @@
2323

2424
package com.iluwatar.cqrs.commandes;
2525

26-
import org.hibernate.Query;
27-
import org.hibernate.Session;
28-
import org.hibernate.SessionFactory;
29-
3026
import com.iluwatar.cqrs.domain.model.Author;
3127
import com.iluwatar.cqrs.domain.model.Book;
3228
import com.iluwatar.cqrs.util.HibernateUtil;
29+
import org.hibernate.Query;
30+
import org.hibernate.Session;
31+
import org.hibernate.SessionFactory;
3332

3433
/**
35-
* This class is an implementation of {@link ICommandService} interface. It uses Hibernate as an api for persistence.
36-
*
34+
* This class is an implementation of {@link ICommandService} interface. It uses Hibernate as an api
35+
* for persistence.
3736
*/
3837
public class CommandServiceImpl implements ICommandService {
3938

cqrs/src/main/java/com/iluwatar/cqrs/commandes/ICommandService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
package com.iluwatar.cqrs.commandes;
2525

2626
/**
27-
* This interface represents the commands of the CQRS pattern
28-
*
27+
* This interface represents the commands of the CQRS pattern.
2928
*/
3029
public interface ICommandService {
3130

cqrs/src/main/java/com/iluwatar/cqrs/constants/AppConstants.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
package com.iluwatar.cqrs.constants;
2525

2626
/**
27-
*
28-
* Class to define the constants
29-
*
27+
* Class to define the constants.
3028
*/
3129
public class AppConstants {
3230

cqrs/src/main/java/com/iluwatar/cqrs/domain/model/Author.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
/**
3232
* This is an Author entity. It is used by Hibernate for persistence.
33-
*
3433
*/
3534
@Entity
3635
public class Author {
@@ -42,13 +41,11 @@ public class Author {
4241
private String email;
4342

4443
/**
45-
*
46-
* @param username
47-
* username of the author
48-
* @param name
49-
* name of the author
50-
* @param email
51-
* email of the author
44+
* Constructor.
45+
*
46+
* @param username username of the author
47+
* @param name name of the author
48+
* @param email email of the author
5249
*/
5350
public Author(String username, String name, String email) {
5451
this.username = username;

0 commit comments

Comments
 (0)