From 35db28ccfb884d8f277c6bdb3adc4e5fa5f0bb1c Mon Sep 17 00:00:00 2001 From: amdegregorio Date: Fri, 16 Nov 2018 16:40:46 -0500 Subject: [PATCH] formatting changes --- .../com/baeldung/hexagonal/Application.java | 1 - .../baeldung/hexagonal/domain/Employee.java | 2 +- .../hexagonal/domain/EmployeeService.java | 33 +++++++------- .../hexagonal/output/EmployeeCsvWriter.java | 16 ++++--- .../hexagonal/output/EmployeeLogger.java | 2 +- .../hexagonal/storage/EmployeeRepository.java | 8 ++-- .../ui/EmployeeConsoleInputImpl.java | 43 ++++++++++--------- .../baeldung/hexagonal/ui/EmployeeInput.java | 2 +- 8 files changed, 55 insertions(+), 52 deletions(-) diff --git a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/Application.java b/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/Application.java index 4691d498f4..237b664708 100644 --- a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/Application.java +++ b/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/Application.java @@ -21,7 +21,6 @@ public class Application { EmployeeInput ui = new EmployeeConsoleInputImpl(); ui.collectData(service); service.generateOutput(); - } } diff --git a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/domain/Employee.java b/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/domain/Employee.java index 91b22d0d11..b785da1494 100644 --- a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/domain/Employee.java +++ b/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/domain/Employee.java @@ -8,7 +8,7 @@ public class Employee { private String lastName; private String employeeId; private BigDecimal salary; - + public Employee( Long id, String firstName, diff --git a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/domain/EmployeeService.java b/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/domain/EmployeeService.java index 12b2028035..2ab3ce9712 100644 --- a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/domain/EmployeeService.java +++ b/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/domain/EmployeeService.java @@ -1,26 +1,25 @@ package com.baeldung.hexagonal.domain; - import java.util.List; import com.baeldung.hexagonal.output.EmployeeOutput; import com.baeldung.hexagonal.storage.EmployeeRepository; public class EmployeeService { - private EmployeeRepository employeeRepository; - private EmployeeOutput employeeOutput; - - public EmployeeService(EmployeeRepository employeeRepository, EmployeeOutput employeeOutput) { - this.employeeRepository = employeeRepository; - this.employeeOutput = employeeOutput; - } - - public Long add(Employee employee) { - return employeeRepository.save(employee); - } - - public void generateOutput() { - List employees = employeeRepository.findAll(); - employeeOutput.writeAll(employees); - } + private EmployeeRepository employeeRepository; + private EmployeeOutput employeeOutput; + + public EmployeeService(EmployeeRepository employeeRepository, EmployeeOutput employeeOutput) { + this.employeeRepository = employeeRepository; + this.employeeOutput = employeeOutput; + } + + public Long add(Employee employee) { + return employeeRepository.save(employee); + } + + public void generateOutput() { + List employees = employeeRepository.findAll(); + employeeOutput.writeAll(employees); + } } diff --git a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/output/EmployeeCsvWriter.java b/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/output/EmployeeCsvWriter.java index c434d19525..6d364dd11b 100644 --- a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/output/EmployeeCsvWriter.java +++ b/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/output/EmployeeCsvWriter.java @@ -11,24 +11,26 @@ import com.baeldung.hexagonal.domain.Employee; public class EmployeeCsvWriter implements EmployeeOutput { private File outputFile; - + public EmployeeCsvWriter(String path, String fileName) throws IllegalArgumentException { if (fileName == null || path == null || fileName.length() == 0 || path.length() == 0) { throw new IllegalArgumentException("Path and FileName are required"); } else if (!fileName.endsWith(".csv")) { throw new IllegalArgumentException("File name must be a .csv file"); } - + System.out.println(path); - if (!path.endsWith("/")) path += "/"; - + if (!path.endsWith("/")) { + path += "/"; + } + outputFile = new File(path, fileName); } @Override public void writeAll(List employees) { BufferedWriter writer = null; - + try { writer = new BufferedWriter(new FileWriter(outputFile)); for (Iterator it = employees.iterator(); it.hasNext();) { @@ -48,13 +50,13 @@ public class EmployeeCsvWriter implements EmployeeOutput { } writer.flush(); } catch (IOException ioe) { - //handle the exception + // handle the exception } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { - //handle the exception + // handle the exception } } } diff --git a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/output/EmployeeLogger.java b/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/output/EmployeeLogger.java index 681e631012..5272d18961 100644 --- a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/output/EmployeeLogger.java +++ b/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/output/EmployeeLogger.java @@ -11,7 +11,7 @@ public class EmployeeLogger implements EmployeeOutput { @Override public void writeAll(List employees) { - employees.forEach(employee -> LOG.info(employee.toString())); + employees.forEach(employee -> LOG.info(employee.toString())); } } diff --git a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/storage/EmployeeRepository.java b/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/storage/EmployeeRepository.java index f12584f8e1..2787601998 100644 --- a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/storage/EmployeeRepository.java +++ b/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/storage/EmployeeRepository.java @@ -5,7 +5,9 @@ import java.util.List; import com.baeldung.hexagonal.domain.Employee; public interface EmployeeRepository { - public Long save(Employee employee); - public Employee findById(Long id); - public List findAll(); + public Long save(Employee employee); + + public Employee findById(Long id); + + public List findAll(); } diff --git a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/ui/EmployeeConsoleInputImpl.java b/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/ui/EmployeeConsoleInputImpl.java index 5f613f7bf9..4960dfd254 100644 --- a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/ui/EmployeeConsoleInputImpl.java +++ b/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/ui/EmployeeConsoleInputImpl.java @@ -13,26 +13,26 @@ public class EmployeeConsoleInputImpl implements EmployeeInput { private static final Logger LOG = LoggerFactory.getLogger(EmployeeConsoleInputImpl.class); public void enterEmployee(EmployeeService service, Scanner scanner) { - - LOG.info("ID: "); - System.out.print("> "); - Long id = scanner.nextLong(); - LOG.info("First Name: "); - System.out.print("> "); - String firstName = scanner.next(); - LOG.info("Last Name: "); - System.out.print("> "); - String lastName = scanner.next(); - LOG.info("Employee ID: "); - System.out.print("> "); - String employeeId = scanner.next(); - LOG.info("Salary: " ); - System.out.print("> "); - BigDecimal salary = scanner.nextBigDecimal(); - - Employee employee = new Employee(id, firstName, lastName, employeeId, salary); - service.add(employee); - + + LOG.info("ID: "); + System.out.print("> "); + Long id = scanner.nextLong(); + LOG.info("First Name: "); + System.out.print("> "); + String firstName = scanner.next(); + LOG.info("Last Name: "); + System.out.print("> "); + String lastName = scanner.next(); + LOG.info("Employee ID: "); + System.out.print("> "); + String employeeId = scanner.next(); + LOG.info("Salary: "); + System.out.print("> "); + BigDecimal salary = scanner.nextBigDecimal(); + + Employee employee = new Employee(id, firstName, lastName, employeeId, salary); + service.add(employee); + } @Override @@ -45,7 +45,8 @@ public class EmployeeConsoleInputImpl implements EmployeeInput { LOG.info("Do you want to enter another employee? (Y/N)"); System.out.print("> "); keepGoing = scanner.next(); - if (keepGoing.length() > 1) keepGoing = keepGoing.substring(0, 1); + if (keepGoing.length() > 1) + keepGoing = keepGoing.substring(0, 1); } while (keepGoing.equalsIgnoreCase("Y")); } } diff --git a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/ui/EmployeeInput.java b/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/ui/EmployeeInput.java index 62156fc6d9..adec2852cd 100644 --- a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/ui/EmployeeInput.java +++ b/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/ui/EmployeeInput.java @@ -3,5 +3,5 @@ package com.baeldung.hexagonal.ui; import com.baeldung.hexagonal.domain.EmployeeService; public interface EmployeeInput { - void collectData(EmployeeService service); + void collectData(EmployeeService service); }