upload
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 1m2s
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 1m2s
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package hhn.temp.project;
|
||||
|
||||
import hhn.temp.project.expections.TaskHasNoWorkerException;
|
||||
|
||||
public class Task {
|
||||
|
||||
private String name;
|
||||
@@ -7,16 +9,10 @@ public class Task {
|
||||
private TaskStatus taskStatus;
|
||||
private int taskID;
|
||||
private static int idCounter = 0;
|
||||
private String workername;
|
||||
|
||||
public Task(String name, String description) {
|
||||
|
||||
if (name == null || description == null ) {
|
||||
|
||||
throw new IllegalArgumentException("Name/Description is null!");
|
||||
}
|
||||
if(name.isEmpty()) {
|
||||
throw new IllegalArgumentException("Name is empty!");
|
||||
}
|
||||
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
@@ -26,11 +22,11 @@ public class Task {
|
||||
}
|
||||
|
||||
public int getTaskID() {
|
||||
return taskID;
|
||||
return this.taskID;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
@@ -59,4 +55,34 @@ public class Task {
|
||||
this.taskStatus = taskStatus;
|
||||
}
|
||||
|
||||
public void setWorker(String workerName) {
|
||||
if(workerName == null || workerName.isEmpty()) {
|
||||
throw new IllegalArgumentException("There is nothing in this variable.");
|
||||
}
|
||||
if(!checkOnlyLetter(workerName)){
|
||||
throw new IllegalArgumentException("Only Lettery as Worker Name!");
|
||||
}
|
||||
this.workername = workerName;
|
||||
this.setStatus(TaskStatus.INPROCESS);
|
||||
}
|
||||
|
||||
public String getWorker() {
|
||||
if(this.workername == null) {
|
||||
throw new TaskHasNoWorkerException("Please set first a Worker");
|
||||
}
|
||||
return this.workername;
|
||||
}
|
||||
|
||||
private boolean checkOnlyLetter(String text) {
|
||||
boolean result = true;
|
||||
|
||||
for(int i = 0; i < text.length(); i++) {
|
||||
char c = text.charAt(i);
|
||||
if(!Character.isLetter(c)) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,16 +16,25 @@ public class TaskManager {
|
||||
}
|
||||
|
||||
public Task createTask(String name, String description) {
|
||||
if (name == null || description == null ) {
|
||||
|
||||
throw new IllegalArgumentException("Name/Description is null!");
|
||||
}
|
||||
if(name.isEmpty()) {
|
||||
throw new IllegalArgumentException("Name is empty!");
|
||||
}
|
||||
|
||||
if(!checkOnlyLetterOrDigit(name)) {
|
||||
throw new TaskAlreadyExistsException("Only Letters or Digit are allowed in the name: " + name);
|
||||
throw new IllegalArgumentException("Only Letters or Digit are allowed in the name: " + name);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
@@ -72,16 +81,16 @@ public class TaskManager {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private boolean checkOnlyLetter(String text) {
|
||||
boolean result = true;
|
||||
|
||||
for(int i = 0; i < text.length(); i++) {
|
||||
char c = text.charAt(i);
|
||||
if(!Character.isLetter(c)) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// private boolean checkOnlyLetter(String text) {
|
||||
// boolean result = true;
|
||||
//
|
||||
// for(int i = 0; i < text.length(); i++) {
|
||||
// char c = text.charAt(i);
|
||||
// if(!Character.isLetter(c)) {
|
||||
// result = false;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package hhn.temp.project;
|
||||
|
||||
public enum TaskStatus {
|
||||
OPEN, CLOSED, IN_PROCESS
|
||||
OPEN, CLOSED, INPROCESS
|
||||
}
|
||||
|
||||
@@ -6,3 +6,4 @@ public class TaskAlreadyExistsException extends RuntimeException {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package hhn.temp.project.expections;
|
||||
|
||||
public class TaskHasNoWorkerException extends RuntimeException {
|
||||
|
||||
public TaskHasNoWorkerException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user