upload
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package hhn.temp.project;
|
||||
|
||||
import hhn.temp.project.expections.TaskAlreadyExistsException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -12,9 +14,14 @@ public class TaskManager {
|
||||
}
|
||||
|
||||
public Task createTask(String name, String description) {
|
||||
|
||||
boolean taskExited = this.taskMap.values().stream().anyMatch(task -> task.getName().equals(name));
|
||||
if(taskExited) {
|
||||
throw new TaskAlreadyExistsException("Task already exits, with the name: " + name);
|
||||
}
|
||||
|
||||
Task task = new Task(name, description);
|
||||
taskMap.put(task.getTaskID(), task);
|
||||
|
||||
return task;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package hhn.temp.project.expections;
|
||||
|
||||
public class TaskAlreadyExistsException extends RuntimeException {
|
||||
|
||||
public TaskAlreadyExistsException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user