formatting changes

This commit is contained in:
amdegregorio 2018-11-16 16:40:46 -05:00
parent 9a6688f638
commit 35db28ccfb
8 changed files with 55 additions and 52 deletions

View File

@ -21,7 +21,6 @@ public class Application {
EmployeeInput ui = new EmployeeConsoleInputImpl(); EmployeeInput ui = new EmployeeConsoleInputImpl();
ui.collectData(service); ui.collectData(service);
service.generateOutput(); service.generateOutput();
} }
} }

View File

@ -1,26 +1,25 @@
package com.baeldung.hexagonal.domain; package com.baeldung.hexagonal.domain;
import java.util.List; import java.util.List;
import com.baeldung.hexagonal.output.EmployeeOutput; import com.baeldung.hexagonal.output.EmployeeOutput;
import com.baeldung.hexagonal.storage.EmployeeRepository; import com.baeldung.hexagonal.storage.EmployeeRepository;
public class EmployeeService { public class EmployeeService {
private EmployeeRepository employeeRepository; private EmployeeRepository employeeRepository;
private EmployeeOutput employeeOutput; private EmployeeOutput employeeOutput;
public EmployeeService(EmployeeRepository employeeRepository, EmployeeOutput employeeOutput) { public EmployeeService(EmployeeRepository employeeRepository, EmployeeOutput employeeOutput) {
this.employeeRepository = employeeRepository; this.employeeRepository = employeeRepository;
this.employeeOutput = employeeOutput; this.employeeOutput = employeeOutput;
} }
public Long add(Employee employee) { public Long add(Employee employee) {
return employeeRepository.save(employee); return employeeRepository.save(employee);
} }
public void generateOutput() { public void generateOutput() {
List<Employee> employees = employeeRepository.findAll(); List<Employee> employees = employeeRepository.findAll();
employeeOutput.writeAll(employees); employeeOutput.writeAll(employees);
} }
} }

View File

@ -20,7 +20,9 @@ public class EmployeeCsvWriter implements EmployeeOutput {
} }
System.out.println(path); System.out.println(path);
if (!path.endsWith("/")) path += "/"; if (!path.endsWith("/")) {
path += "/";
}
outputFile = new File(path, fileName); outputFile = new File(path, fileName);
} }
@ -48,13 +50,13 @@ public class EmployeeCsvWriter implements EmployeeOutput {
} }
writer.flush(); writer.flush();
} catch (IOException ioe) { } catch (IOException ioe) {
//handle the exception // handle the exception
} finally { } finally {
if (writer != null) { if (writer != null) {
try { try {
writer.close(); writer.close();
} catch (IOException e) { } catch (IOException e) {
//handle the exception // handle the exception
} }
} }
} }

View File

@ -11,7 +11,7 @@ public class EmployeeLogger implements EmployeeOutput {
@Override @Override
public void writeAll(List<Employee> employees) { public void writeAll(List<Employee> employees) {
employees.forEach(employee -> LOG.info(employee.toString())); employees.forEach(employee -> LOG.info(employee.toString()));
} }
} }

View File

@ -5,7 +5,9 @@ import java.util.List;
import com.baeldung.hexagonal.domain.Employee; import com.baeldung.hexagonal.domain.Employee;
public interface EmployeeRepository { public interface EmployeeRepository {
public Long save(Employee employee); public Long save(Employee employee);
public Employee findById(Long id);
public List<Employee> findAll(); public Employee findById(Long id);
public List<Employee> findAll();
} }

View File

@ -14,24 +14,24 @@ public class EmployeeConsoleInputImpl implements EmployeeInput {
public void enterEmployee(EmployeeService service, Scanner scanner) { public void enterEmployee(EmployeeService service, Scanner scanner) {
LOG.info("ID: "); LOG.info("ID: ");
System.out.print("> "); System.out.print("> ");
Long id = scanner.nextLong(); Long id = scanner.nextLong();
LOG.info("First Name: "); LOG.info("First Name: ");
System.out.print("> "); System.out.print("> ");
String firstName = scanner.next(); String firstName = scanner.next();
LOG.info("Last Name: "); LOG.info("Last Name: ");
System.out.print("> "); System.out.print("> ");
String lastName = scanner.next(); String lastName = scanner.next();
LOG.info("Employee ID: "); LOG.info("Employee ID: ");
System.out.print("> "); System.out.print("> ");
String employeeId = scanner.next(); String employeeId = scanner.next();
LOG.info("Salary: " ); LOG.info("Salary: ");
System.out.print("> "); System.out.print("> ");
BigDecimal salary = scanner.nextBigDecimal(); BigDecimal salary = scanner.nextBigDecimal();
Employee employee = new Employee(id, firstName, lastName, employeeId, salary); Employee employee = new Employee(id, firstName, lastName, employeeId, salary);
service.add(employee); service.add(employee);
} }
@ -45,7 +45,8 @@ public class EmployeeConsoleInputImpl implements EmployeeInput {
LOG.info("Do you want to enter another employee? (Y/N)"); LOG.info("Do you want to enter another employee? (Y/N)");
System.out.print("> "); System.out.print("> ");
keepGoing = scanner.next(); 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")); } while (keepGoing.equalsIgnoreCase("Y"));
} }
} }

View File

@ -3,5 +3,5 @@ package com.baeldung.hexagonal.ui;
import com.baeldung.hexagonal.domain.EmployeeService; import com.baeldung.hexagonal.domain.EmployeeService;
public interface EmployeeInput { public interface EmployeeInput {
void collectData(EmployeeService service); void collectData(EmployeeService service);
} }