Use local variable type inference (#995)
* "visitor" pattern: Use local variable type inference Update "visitor" pattern with local variable type inference. * "value-object" pattern: Use local variable type inference Update "value-object" pattern with local variable type inference. * "unit-of-work" pattern: Use local variable type inference Update "value-object" pattern with local variable type inference. * "typeobjectpattern" pattern: Use local variable type inference Update "value-object" pattern with local variable type inference.
This commit is contained in:
committed by
Ilkka Seppälä
parent
5fc03ee9f8
commit
c81c3ff1c7
@ -34,13 +34,13 @@ public class App {
|
||||
* @param args no argument sent
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Student ram = new Student(1, "Ram", "Street 9, Cupertino");
|
||||
Student shyam = new Student(2, "Shyam", "Z bridge, Pune");
|
||||
Student gopi = new Student(3, "Gopi", "Street 10, Mumbai");
|
||||
var ram = new Student(1, "Ram", "Street 9, Cupertino");
|
||||
var shyam = new Student(2, "Shyam", "Z bridge, Pune");
|
||||
var gopi = new Student(3, "Gopi", "Street 10, Mumbai");
|
||||
|
||||
HashMap<String, List<Student>> context = new HashMap<>();
|
||||
StudentDatabase studentDatabase = new StudentDatabase();
|
||||
StudentRepository studentRepository = new StudentRepository(context, studentDatabase);
|
||||
var studentDatabase = new StudentDatabase();
|
||||
var studentRepository = new StudentRepository(context, studentDatabase);
|
||||
|
||||
studentRepository.registerNew(ram);
|
||||
studentRepository.registerModified(shyam);
|
||||
|
@ -68,7 +68,7 @@ public class StudentRepository implements IUnitOfWork<Student> {
|
||||
}
|
||||
|
||||
private void register(Student student, String operation) {
|
||||
List<Student> studentsToOperate = context.get(operation);
|
||||
var studentsToOperate = context.get(operation);
|
||||
if (studentsToOperate == null) {
|
||||
studentsToOperate = new ArrayList<>();
|
||||
}
|
||||
@ -99,24 +99,24 @@ public class StudentRepository implements IUnitOfWork<Student> {
|
||||
}
|
||||
|
||||
private void commitInsert() {
|
||||
List<Student> studentsToBeInserted = context.get(IUnitOfWork.INSERT);
|
||||
for (Student student : studentsToBeInserted) {
|
||||
var studentsToBeInserted = context.get(IUnitOfWork.INSERT);
|
||||
for (var student : studentsToBeInserted) {
|
||||
LOGGER.info("Saving {} to database.", student.getName());
|
||||
studentDatabase.insert(student);
|
||||
}
|
||||
}
|
||||
|
||||
private void commitModify() {
|
||||
List<Student> modifiedStudents = context.get(IUnitOfWork.MODIFY);
|
||||
for (Student student : modifiedStudents) {
|
||||
var modifiedStudents = context.get(IUnitOfWork.MODIFY);
|
||||
for (var student : modifiedStudents) {
|
||||
LOGGER.info("Modifying {} to database.", student.getName());
|
||||
studentDatabase.modify(student);
|
||||
}
|
||||
}
|
||||
|
||||
private void commitDelete() {
|
||||
List<Student> deletedStudents = context.get(IUnitOfWork.DELETE);
|
||||
for (Student student : deletedStudents) {
|
||||
var deletedStudents = context.get(IUnitOfWork.DELETE);
|
||||
for (var student : deletedStudents) {
|
||||
LOGGER.info("Deleting {} to database.", student.getName());
|
||||
studentDatabase.delete(student);
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ public class StudentRepositoryTest {
|
||||
|
||||
@Test
|
||||
public void shouldNotWriteToDbIfContextIsNull() {
|
||||
StudentRepository studentRepository = new StudentRepository(null, studentDatabase);
|
||||
var studentRepository = new StudentRepository(null, studentDatabase);
|
||||
|
||||
studentRepository.commit();
|
||||
|
||||
@ -106,7 +106,7 @@ public class StudentRepositoryTest {
|
||||
|
||||
@Test
|
||||
public void shouldNotWriteToDbIfNothingToCommit() {
|
||||
StudentRepository studentRepository = new StudentRepository(new HashMap<>(), studentDatabase);
|
||||
var studentRepository = new StudentRepository(new HashMap<>(), studentDatabase);
|
||||
|
||||
studentRepository.commit();
|
||||
|
||||
|
Reference in New Issue
Block a user