Resolves checkstyle errors for converter, cqrs (#1063)

* Reduces checkstyle errors in converter

* Reduces checkstyle errors in cqrs
This commit is contained in:
Anurag Agarwal
2019-11-10 22:09:27 +05:30
committed by Ilkka Seppälä
parent 2f49648047
commit 4f9ee0189c
16 changed files with 129 additions and 127 deletions

View File

@ -23,12 +23,10 @@
package com.iluwatar.converter;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
/**
* The Converter pattern is a behavioral design pattern which allows a common way of bidirectional
* conversion between corresponding types (e.g. DTO and domain representations of the logically
@ -38,8 +36,9 @@ import java.util.List;
public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
* Program entry point
* Program entry point.
*
* @param args command line args
*/

View File

@ -30,8 +30,9 @@ import java.util.stream.Collectors;
/**
* Generic converter, thanks to Java8 features not only provides a way of generic bidirectional
* conversion between corresponding types, but also a common way of converting a collection of objects
* of the same type, reducing boilerplate code to the absolute minimum.
* conversion between corresponding types, but also a common way of converting a collection of
* objects of the same type, reducing boilerplate code to the absolute minimum.
*
* @param <T> DTO representation's type
* @param <U> Domain representation's type
*/
@ -41,7 +42,9 @@ public class Converter<T, U> {
private final Function<U, T> fromEntity;
/**
* @param fromDto Function that converts given dto entity into the domain entity.
* Constructor.
*
* @param fromDto Function that converts given dto entity into the domain entity.
* @param fromEntity Function that converts given domain entity into the dto entity.
*/
public Converter(final Function<T, U> fromDto, final Function<U, T> fromEntity) {
@ -50,34 +53,44 @@ public class Converter<T, U> {
}
/**
* Converts DTO to Entity.
*
* @param dto DTO entity
* @return The domain representation - the result of the converting function application on dto entity.
* @return The domain representation - the result of the converting function application on dto
* entity.
*/
public final U convertFromDto(final T dto) {
return fromDto.apply(dto);
}
/**
* Converts Entity to DTO.
*
* @param entity domain entity
* @return The DTO representation - the result of the converting function application on domain entity.
* @return The DTO representation - the result of the converting function application on domain
* entity.
*/
public final T convertFromEntity(final U entity) {
return fromEntity.apply(entity);
}
/**
* Converts list of DTOs to list of Entities.
*
* @param dtos collection of DTO entities
* @return List of domain representation of provided entities retrieved by
* mapping each of them with the conversion function
* @return List of domain representation of provided entities retrieved by mapping each of them
* with the conversion function
*/
public final List<U> createFromDtos(final Collection<T> dtos) {
return dtos.stream().map(this::convertFromDto).collect(Collectors.toList());
}
/**
* Converts list of Entities to list of DTOs.
*
* @param entities collection of domain entities
* @return List of domain representation of provided entities retrieved by
* mapping each of them with the conversion function
* @return List of domain representation of provided entities retrieved by mapping each of them
* with the conversion function
*/
public final List<T> createFromEntities(final Collection<U> entities) {
return entities.stream().map(this::convertFromEntity).collect(Collectors.toList());

View File

@ -26,7 +26,7 @@ package com.iluwatar.converter;
import java.util.Objects;
/**
* User class
* User class.
*/
public class User {
private String firstName;
@ -35,10 +35,12 @@ public class User {
private String userId;
/**
* Constructor.
*
* @param firstName user's first name
* @param lastName user's last name
* @param isActive flag indicating whether the user is active
* @param userId user's identificator
* @param userId user's identificator
*/
public User(String firstName, String lastName, boolean isActive, String userId) {
this.firstName = firstName;
@ -63,7 +65,8 @@ public class User {
return userId;
}
@Override public boolean equals(Object o) {
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
@ -72,15 +75,17 @@ public class User {
}
User user = (User) o;
return isActive == user.isActive && Objects.equals(firstName, user.firstName) && Objects
.equals(lastName, user.lastName) && Objects.equals(userId, user.userId);
.equals(lastName, user.lastName) && Objects.equals(userId, user.userId);
}
@Override public int hashCode() {
@Override
public int hashCode() {
return Objects.hash(firstName, lastName, isActive, userId);
}
@Override public String toString() {
@Override
public String toString() {
return "User{" + "firstName='" + firstName + '\'' + ", lastName='" + lastName + '\''
+ ", isActive=" + isActive + ", userId='" + userId + '\'' + '}';
+ ", isActive=" + isActive + ", userId='" + userId + '\'' + '}';
}
}

View File

@ -33,8 +33,8 @@ public class UserConverter extends Converter<UserDto, User> {
*/
public UserConverter() {
super(userDto -> new User(userDto.getFirstName(), userDto.getLastName(), userDto.isActive(),
userDto.getEmail()),
userDto.getEmail()),
user -> new UserDto(user.getFirstName(), user.getLastName(), user.isActive(),
user.getUserId()));
user.getUserId()));
}
}

View File

@ -23,11 +23,10 @@
package com.iluwatar.converter;
import java.util.Objects;
/**
* User DTO class
* User DTO class.
*/
public class UserDto {
@ -37,6 +36,8 @@ public class UserDto {
private String email;
/**
* Constructor.
*
* @param firstName user's first name
* @param lastName user's last name
* @param isActive flag indicating whether the user is active
@ -65,7 +66,8 @@ public class UserDto {
return email;
}
@Override public boolean equals(Object o) {
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
@ -74,15 +76,17 @@ public class UserDto {
}
UserDto userDto = (UserDto) o;
return isActive == userDto.isActive && Objects.equals(firstName, userDto.firstName) && Objects
.equals(lastName, userDto.lastName) && Objects.equals(email, userDto.email);
.equals(lastName, userDto.lastName) && Objects.equals(email, userDto.email);
}
@Override public int hashCode() {
@Override
public int hashCode() {
return Objects.hash(firstName, lastName, isActive, email);
}
@Override public String toString() {
@Override
public String toString() {
return "UserDto{" + "firstName='" + firstName + '\'' + ", lastName='" + lastName + '\''
+ ", isActive=" + isActive + ", email='" + email + '\'' + '}';
+ ", isActive=" + isActive + ", email='" + email + '\'' + '}';
}
}