removed eval article code

This commit is contained in:
amdegregorio 2018-12-12 06:32:57 -05:00
parent 09e7119f89
commit 2e6a5a3510
12 changed files with 0 additions and 305 deletions

View File

@ -1 +0,0 @@
/bin/

View File

@ -1,14 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung.hexagonal</groupId>
<artifactId>hexagonal-architecture</artifactId>
<packaging>jar</packaging>
<name>hexagonal-architecture</name>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-java</relativePath>
</parent>
</project>

View File

@ -1,26 +0,0 @@
package com.baeldung.hexagonal;
import java.io.File;
import com.baeldung.hexagonal.domain.EmployeeService;
import com.baeldung.hexagonal.output.EmployeeCsvWriter;
import com.baeldung.hexagonal.output.EmployeeLogger;
import com.baeldung.hexagonal.output.EmployeeOutput;
import com.baeldung.hexagonal.storage.EmployeeRepository;
import com.baeldung.hexagonal.storage.InMemoryEmployeeRepository;
import com.baeldung.hexagonal.ui.EmployeeConsoleInputImpl;
import com.baeldung.hexagonal.ui.EmployeeInput;
public class Application {
public static void main(String[] args) {
EmployeeRepository repository = new InMemoryEmployeeRepository();
EmployeeOutput output = new EmployeeLogger();
EmployeeOutput csvOutput = new EmployeeCsvWriter(new File(".").getAbsolutePath(), "output.csv");
EmployeeService service = new EmployeeService(repository, csvOutput);
EmployeeInput ui = new EmployeeConsoleInputImpl();
ui.collectData(service);
service.generateOutput();
}
}

View File

@ -1,60 +0,0 @@
package com.baeldung.hexagonal.domain;
public class Employee {
private Long id;
private String name;
public Employee(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
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

@ -1,25 +0,0 @@
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<Employee> employees = employeeRepository.findAll();
employeeOutput.writeAll(employees);
}
}

View File

@ -1,59 +0,0 @@
package com.baeldung.hexagonal.output;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
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 += "/";
}
outputFile = new File(path, fileName);
}
@Override
public void writeAll(List<Employee> employees) {
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(outputFile));
for (Iterator<Employee> it = employees.iterator(); it.hasNext();) {
Employee emp = it.next();
StringBuffer empLine = new StringBuffer();
empLine.append(emp.getId());
empLine.append(",");
empLine.append(emp.getName());
writer.newLine();
}
writer.flush();
} catch (IOException ioe) {
// handle the exception
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
// handle the exception
}
}
}
}
}

View File

@ -1,17 +0,0 @@
package com.baeldung.hexagonal.output;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.baeldung.hexagonal.domain.Employee;
public class EmployeeLogger implements EmployeeOutput {
private static final Logger LOG = LoggerFactory.getLogger(EmployeeLogger.class);
@Override
public void writeAll(List<Employee> employees) {
employees.forEach(employee -> LOG.info(employee.toString()));
}
}

View File

@ -1,9 +0,0 @@
package com.baeldung.hexagonal.output;
import java.util.List;
import com.baeldung.hexagonal.domain.Employee;
public interface EmployeeOutput {
public void writeAll(List<Employee> employees);
}

View File

@ -1,13 +0,0 @@
package com.baeldung.hexagonal.storage;
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<Employee> findAll();
}

View File

@ -1,31 +0,0 @@
package com.baeldung.hexagonal.storage;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.baeldung.hexagonal.domain.Employee;
public class InMemoryEmployeeRepository implements EmployeeRepository {
private static Map<Long, Employee> employees = new HashMap<>();
@Override
public Long save(Employee employee) {
Long id = employee.getId();
employees.put(id, employee);
return id;
}
@Override
public Employee findById(Long id) {
return employees.get(id);
}
@Override
public List<Employee> findAll() {
List<Employee> all = new ArrayList<Employee>(employees.values());
return all;
}
}

View File

@ -1,43 +0,0 @@
package com.baeldung.hexagonal.ui;
import java.util.Scanner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.baeldung.hexagonal.domain.Employee;
import com.baeldung.hexagonal.domain.EmployeeService;
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("Name: ");
System.out.print("> ");
String name = scanner.next();
Employee employee = new Employee(id, name);
service.add(employee);
}
@Override
public void collectData(EmployeeService service) {
try (final Scanner scanner = new Scanner(System.in)) {
String keepGoing = "Y";
do {
LOG.info("Enter information for an employee");
enterEmployee(service, scanner);
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);
}
} while (keepGoing.equalsIgnoreCase("Y"));
}
}
}

View File

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