trim down Exmployee fields

This commit is contained in:
amdegregorio 2018-11-18 09:57:39 -05:00
parent 35db28ccfb
commit f1c3029c59
3 changed files with 41 additions and 69 deletions

View File

@ -1,25 +1,12 @@
package com.baeldung.hexagonal.domain; package com.baeldung.hexagonal.domain;
import java.math.BigDecimal;
public class Employee { public class Employee {
private Long id; private Long id;
private String firstName; private String name;
private String lastName;
private String employeeId;
private BigDecimal salary;
public Employee( public Employee(Long id, String name) {
Long id,
String firstName,
String lastName,
String employeeId,
BigDecimal salary) {
this.id = id; this.id = id;
this.firstName = firstName; this.name = name;
this.lastName = lastName;
this.employeeId = employeeId;
this.salary = salary;
} }
public Long getId() { public Long getId() {
@ -30,41 +17,44 @@ public class Employee {
this.id = id; this.id = id;
} }
public String getFirstName() { public String getName() {
return firstName; return name;
} }
public void setFirstName(String firstName) { public void setName(String name) {
this.firstName = firstName; this.name = name;
}
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;
} }
@Override @Override
public String toString() { 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;
} }
} }

View File

@ -38,14 +38,7 @@ public class EmployeeCsvWriter implements EmployeeOutput {
StringBuffer empLine = new StringBuffer(); StringBuffer empLine = new StringBuffer();
empLine.append(emp.getId()); empLine.append(emp.getId());
empLine.append(","); empLine.append(",");
empLine.append(emp.getFirstName()); empLine.append(emp.getName());
empLine.append(",");
empLine.append(emp.getLastName());
empLine.append(",");
empLine.append(emp.getEmployeeId());
empLine.append(",");
empLine.append(emp.getSalary());
writer.write(empLine.toString());
writer.newLine(); writer.newLine();
} }
writer.flush(); writer.flush();

View File

@ -1,6 +1,5 @@
package com.baeldung.hexagonal.ui; package com.baeldung.hexagonal.ui;
import java.math.BigDecimal;
import java.util.Scanner; import java.util.Scanner;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -13,26 +12,15 @@ public class EmployeeConsoleInputImpl implements EmployeeInput {
private static final Logger LOG = LoggerFactory.getLogger(EmployeeConsoleInputImpl.class); private static final Logger LOG = LoggerFactory.getLogger(EmployeeConsoleInputImpl.class);
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("Name: ");
System.out.print("> "); System.out.print("> ");
String firstName = scanner.next(); String name = 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); Employee employee = new Employee(id, name);
service.add(employee); service.add(employee);
} }
@Override @Override
@ -45,8 +33,9 @@ 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) if (keepGoing.length() > 1) {
keepGoing = keepGoing.substring(0, 1); keepGoing = keepGoing.substring(0, 1);
}
} while (keepGoing.equalsIgnoreCase("Y")); } while (keepGoing.equalsIgnoreCase("Y"));
} }
} }