upload
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 1m10s

This commit is contained in:
Jan-Philipp Luithardt
2025-12-03 17:23:31 +01:00
parent 322763f98c
commit ed7bd7d1ed

View File

@@ -17,6 +17,10 @@ public class TaskManager {
public Task createTask(String name, String description) { public Task createTask(String name, String description) {
if(!checkOnlyLetterOrDigit(name)) {
throw new TaskAlreadyExistsException("Only Letters or Digit are allowed in the name: " + name);
}
boolean taskExited = this.taskMap.values().stream().anyMatch(task -> task.getName().equals(name)); boolean taskExited = this.taskMap.values().stream().anyMatch(task -> task.getName().equals(name));
if(taskExited) { if(taskExited) {
throw new TaskAlreadyExistsException("Task already exits, with the name: " + name); throw new TaskAlreadyExistsException("Task already exits, with the name: " + name);
@@ -55,4 +59,29 @@ public class TaskManager {
.orElseThrow().getTaskID()); .orElseThrow().getTaskID());
} }
private boolean checkOnlyLetterOrDigit(String text) {
boolean result = true;
for(int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
if(!Character.isLetterOrDigit(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;
}
} }