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 b785da1494..0d883995b6 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 @@ -1,25 +1,12 @@ package com.baeldung.hexagonal.domain; -import java.math.BigDecimal; - public class Employee { private Long id; - private String firstName; - private String lastName; - private String employeeId; - private BigDecimal salary; + private String name; - public Employee( - Long id, - String firstName, - String lastName, - String employeeId, - BigDecimal salary) { + public Employee(Long id, String name) { this.id = id; - this.firstName = firstName; - this.lastName = lastName; - this.employeeId = employeeId; - this.salary = salary; + this.name = name; } public Long getId() { @@ -30,41 +17,44 @@ public class Employee { this.id = id; } - public String getFirstName() { - return firstName; + public String getName() { + return name; } - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getEmployeeId() { - return employeeId; - } - - public void setEmployeeId(String employeeId) { - this.employeeId = employeeId; - } - - public BigDecimal getSalary() { - return salary; - } - - public void setSalary(BigDecimal salary) { - this.salary = salary; + public void setName(String name) { + this.name = name; } @Override public String toString() { - return "Employee [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", employeeId=" + employeeId + ", salary=" + salary + "]"; + return "Employee [id=" + id + ", name=" + name + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Employee other = (Employee) obj; + if (id == null) { + if (other.id != null) { + return false; + } + } else if (!id.equals(other.id)) { + return false; + } + + return true; } } 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 6d364dd11b..799fbc28ba 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 @@ -38,14 +38,7 @@ public class EmployeeCsvWriter implements EmployeeOutput { StringBuffer empLine = new StringBuffer(); empLine.append(emp.getId()); empLine.append(","); - empLine.append(emp.getFirstName()); - empLine.append(","); - empLine.append(emp.getLastName()); - empLine.append(","); - empLine.append(emp.getEmployeeId()); - empLine.append(","); - empLine.append(emp.getSalary()); - writer.write(empLine.toString()); + empLine.append(emp.getName()); writer.newLine(); } writer.flush(); 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 4960dfd254..77453da48f 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 @@ -1,6 +1,5 @@ package com.baeldung.hexagonal.ui; -import java.math.BigDecimal; import java.util.Scanner; import org.slf4j.Logger; @@ -13,26 +12,15 @@ 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: "); + LOG.info("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(); + String name = scanner.next(); - Employee employee = new Employee(id, firstName, lastName, employeeId, salary); + Employee employee = new Employee(id, name); service.add(employee); - } @Override @@ -45,8 +33,9 @@ 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) + if (keepGoing.length() > 1) { keepGoing = keepGoing.substring(0, 1); + } } while (keepGoing.equalsIgnoreCase("Y")); } }