From 6d1fdd05ab28189f3e3a274628f1626dffda4957 Mon Sep 17 00:00:00 2001 From: David Guler Date: Fri, 14 Oct 2022 21:08:34 +0200 Subject: [PATCH] feat: TaskDB types and interfaces Created the types and interfaces relating to the TaskDatabase --- .../gartenverwaltung/io/TaskDatabase.java | 13 +++++ .../ch/zhaw/gartenverwaltung/types/Task.java | 50 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/main/java/ch/zhaw/gartenverwaltung/io/TaskDatabase.java create mode 100644 src/main/java/ch/zhaw/gartenverwaltung/types/Task.java diff --git a/src/main/java/ch/zhaw/gartenverwaltung/io/TaskDatabase.java b/src/main/java/ch/zhaw/gartenverwaltung/io/TaskDatabase.java new file mode 100644 index 0000000..73cf8e0 --- /dev/null +++ b/src/main/java/ch/zhaw/gartenverwaltung/io/TaskDatabase.java @@ -0,0 +1,13 @@ +package ch.zhaw.gartenverwaltung.io; + +import ch.zhaw.gartenverwaltung.types.Task; + +import java.io.IOException; +import java.util.Date; +import java.util.List; + +public interface TaskDatabase { + List getTaskList(Date start, Date end); + void saveTask(Task task) throws IOException; + void removeTask(Task task) throws IOException; +} diff --git a/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java new file mode 100644 index 0000000..d85435b --- /dev/null +++ b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java @@ -0,0 +1,50 @@ +package ch.zhaw.gartenverwaltung.types; + +import java.util.Date; +import java.util.Optional; + +/** + * Models a Task + * May be created using the builder pattern. + */ +public class Task { + private long id; + private final String name; + private final String description; + private final Date startDate; + private Integer interval; + private Date endDate; + + public Task(String name, String description, Date startDate) { + this.name = name; + this.description = description; + this.startDate = endDate; + } + + // Builder-pattern-style setters + public Task withId(long id) { + this.id = id; + return this; + } + public Task withInterval(int interval) { + this.interval = interval; + return this; + } + public Task withEndDate(Date endDate) { + this.endDate = endDate; + return this; + } + + // Getters + public long getId() { return id; } + public String getName() { return name; } + public String getDescription() { return description; } + public Date getStartDate() { return startDate; } + + public Optional getInterval() { + return Optional.ofNullable(interval); + } + public Optional getEndDate() { + return Optional.ofNullable(endDate); + } +}