📍Use lombok, reformat, and optimize the code (#1560)

* Use lombok, reformat, and optimize the code

* Fix merge conflicts and some sonar issues

Co-authored-by: va1m <va1m@email.com>
This commit is contained in:
va1m
2021-03-13 13:19:21 +01:00
committed by GitHub
parent 0e26a6adb5
commit 5cf2fe009b
681 changed files with 2472 additions and 4966 deletions

View File

@ -23,8 +23,7 @@
package com.iluwatar.datamapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
/**
* The Data Mapper (DM) is a layer of software that separates the in-memory objects from the
@ -36,12 +35,11 @@ import org.slf4j.LoggerFactory;
*
* <p>The below example demonstrates basic CRUD operations: Create, Read, Update, and Delete.
*/
@Slf4j
public final class App {
private static final Logger log = LoggerFactory.getLogger(App.class);
private static final String STUDENT_STRING = "App.main(), student : ";
/**
* Program entry point.
*
@ -58,12 +56,12 @@ public final class App {
/* Add student in respectibe store */
mapper.insert(student);
log.debug(STUDENT_STRING + student + ", is inserted");
LOGGER.debug(STUDENT_STRING + student + ", is inserted");
/* Find this student */
final var studentToBeFound = mapper.find(student.getStudentId());
log.debug(STUDENT_STRING + studentToBeFound + ", is searched");
LOGGER.debug(STUDENT_STRING + studentToBeFound + ", is searched");
/* Update existing student object */
student = new Student(student.getStudentId(), "AdamUpdated", 'A');
@ -71,8 +69,8 @@ public final class App {
/* Update student in respectibe db */
mapper.update(student);
log.debug(STUDENT_STRING + student + ", is updated");
log.debug(STUDENT_STRING + student + ", is going to be deleted");
LOGGER.debug(STUDENT_STRING + student + ", is updated");
LOGGER.debug(STUDENT_STRING + student + ", is going to be deleted");
/* Delete student in db */
mapper.delete(student);

View File

@ -24,88 +24,27 @@
package com.iluwatar.datamapper;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* Class defining Student.
*/
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@ToString
@Getter
@Setter
@AllArgsConstructor
public final class Student implements Serializable {
private static final long serialVersionUID = 1L;
@EqualsAndHashCode.Include
private int studentId;
private String name;
private char grade;
/**
* Use this constructor to create a Student with all details.
*
* @param studentId as unique student id
* @param name as student name
* @param grade as respective grade of student
*/
public Student(final int studentId, final String name, final char grade) {
this.studentId = studentId;
this.name = name;
this.grade = grade;
}
public int getStudentId() {
return studentId;
}
public void setStudentId(final int studentId) {
this.studentId = studentId;
}
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public char getGrade() {
return grade;
}
public void setGrade(final char grade) {
this.grade = grade;
}
@Override
public boolean equals(final Object inputObject) {
boolean isEqual = false;
/* Check if both objects are same */
if (this == inputObject) {
isEqual = true;
} else if (inputObject != null && getClass() == inputObject.getClass()) {
final var inputStudent = (Student) inputObject;
/* If student id matched */
if (this.getStudentId() == inputStudent.getStudentId()) {
isEqual = true;
}
}
return isEqual;
}
@Override
public int hashCode() {
/* Student id is assumed to be unique */
return this.getStudentId();
}
@Override
public String toString() {
return "Student [studentId=" + studentId + ", name=" + name + ", grade=" + grade + "]";
}
}

View File

@ -37,13 +37,13 @@ import org.junit.jupiter.api.Test;
* Data Mapper itself is even unknown to the domain layer.
* <p>
*/
public class DataMapperTest {
class DataMapperTest {
/**
* This test verify that first data mapper is able to perform all CRUD operations on Student
*/
@Test
public void testFirstDataMapper() {
void testFirstDataMapper() {
/* Create new data mapper of first type */
final var mapper = new StudentDataMapperImpl();

View File

@ -31,7 +31,7 @@ import org.junit.jupiter.api.Test;
/**
* Tests {@link Student}.
*/
public final class StudentTest {
final class StudentTest {
/**
* This API tests the equality behaviour of Student object Object Equality should work as per
@ -40,7 +40,7 @@ public final class StudentTest {
* @throws Exception if any execution error during test
*/
@Test
public void testEquality() throws Exception {
void testEquality() throws Exception {
/* Create some students */
final var firstStudent = new Student(1, "Adam", 'A');