diff --git a/hexagonal-architecture/.gitignore b/hexagonal-architecture/.gitignore deleted file mode 100644 index ae3c172604..0000000000 --- a/hexagonal-architecture/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin/ diff --git a/hexagonal-architecture/pom.xml b/hexagonal-architecture/pom.xml deleted file mode 100644 index d184576705..0000000000 --- a/hexagonal-architecture/pom.xml +++ /dev/null @@ -1,14 +0,0 @@ - - 4.0.0 - com.baeldung.hexagonal - hexagonal-architecture - jar - hexagonal-architecture - - com.baeldung - parent-java - 0.0.1-SNAPSHOT - ../parent-java - - diff --git a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/Application.java b/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/Application.java deleted file mode 100644 index 237b664708..0000000000 --- a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/Application.java +++ /dev/null @@ -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(); - } - -} 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 deleted file mode 100644 index 0d883995b6..0000000000 --- a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/domain/Employee.java +++ /dev/null @@ -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; - } - -} 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 deleted file mode 100644 index 2ab3ce9712..0000000000 --- a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/domain/EmployeeService.java +++ /dev/null @@ -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 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 deleted file mode 100644 index 799fbc28ba..0000000000 --- a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/output/EmployeeCsvWriter.java +++ /dev/null @@ -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 employees) { - BufferedWriter writer = null; - - try { - writer = new BufferedWriter(new FileWriter(outputFile)); - for (Iterator 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 - } - } - } - - } - -} 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 deleted file mode 100644 index 5272d18961..0000000000 --- a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/output/EmployeeLogger.java +++ /dev/null @@ -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 employees) { - employees.forEach(employee -> LOG.info(employee.toString())); - } - -} diff --git a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/output/EmployeeOutput.java b/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/output/EmployeeOutput.java deleted file mode 100644 index 979c06e1f4..0000000000 --- a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/output/EmployeeOutput.java +++ /dev/null @@ -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 employees); -} 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 deleted file mode 100644 index 2787601998..0000000000 --- a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/storage/EmployeeRepository.java +++ /dev/null @@ -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 findAll(); -} diff --git a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/storage/InMemoryEmployeeRepository.java b/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/storage/InMemoryEmployeeRepository.java deleted file mode 100644 index e860c16462..0000000000 --- a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/storage/InMemoryEmployeeRepository.java +++ /dev/null @@ -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 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 findAll() { - List all = new ArrayList(employees.values()); - return all; - } - -} 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 deleted file mode 100644 index 77453da48f..0000000000 --- a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/ui/EmployeeConsoleInputImpl.java +++ /dev/null @@ -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")); - } - } - -} 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 deleted file mode 100644 index adec2852cd..0000000000 --- a/hexagonal-architecture/src/main/java/com/baeldung/hexagonal/ui/EmployeeInput.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.hexagonal.ui; - -import com.baeldung.hexagonal.domain.EmployeeService; - -public interface EmployeeInput { - void collectData(EmployeeService service); -}