This commit is contained in:
Jan-Philipp Luithardt
2025-12-03 15:04:30 +01:00
parent 835bd912df
commit 21a95a8388
31 changed files with 99 additions and 33 deletions

View File

@@ -2,27 +2,44 @@
import hhn.temp.project.expections.TaskAlreadyExistsException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TaskManager {
private Map<Integer, Task> taskMap;
<span class="fc" id="L12"> public TaskManager() {</span>
<span class="fc" id="L13"> taskMap = new HashMap&lt;&gt;();</span>
<span class="fc" id="L14"> }</span>
<span class="fc" id="L14"> public TaskManager() {</span>
<span class="fc" id="L15"> taskMap = new HashMap&lt;&gt;();</span>
<span class="fc" id="L16"> }</span>
public Task createTask(String name, String description) {
<span class="fc" id="L18"> boolean taskExited = this.taskMap.values().stream().anyMatch(task -&gt; task.getName().equals(name));</span>
<span class="fc bfc" id="L19" title="All 2 branches covered."> if(taskExited) {</span>
<span class="fc" id="L20"> throw new TaskAlreadyExistsException(&quot;Task already exits, with the name: &quot; + name);</span>
<span class="fc" id="L20"> boolean taskExited = this.taskMap.values().stream().anyMatch(task -&gt; task.getName().equals(name));</span>
<span class="fc bfc" id="L21" title="All 2 branches covered."> if(taskExited) {</span>
<span class="fc" id="L22"> throw new TaskAlreadyExistsException(&quot;Task already exits, with the name: &quot; + name);</span>
}
<span class="fc" id="L23"> Task task = new Task(name, description);</span>
<span class="fc" id="L24"> taskMap.put(task.getTaskID(), task);</span>
<span class="fc" id="L25"> return task;</span>
<span class="fc" id="L25"> Task task = new Task(name, description);</span>
<span class="fc" id="L26"> taskMap.put(task.getTaskID(), task);</span>
<span class="fc" id="L27"> return task;</span>
}
public List&lt;Task&gt; getTaskList() {
<span class="fc" id="L31"> return new ArrayList&lt;&gt;(this.taskMap.values());</span>
}
public Task getTask(String name) {
<span class="fc" id="L35"> return taskMap.values().stream().filter(t -&gt; t.getName().equals(name)).findFirst()</span>
<span class="fc" id="L36"> .orElseThrow(() -&gt; new IllegalArgumentException(&quot;Wrong name&quot;));</span>
}
public Task getTask(int taskID) {
<span class="fc bfc" id="L39" title="All 2 branches covered."> if(!this.taskMap.containsKey(taskID)) {</span>
<span class="fc" id="L40"> throw new IllegalArgumentException(&quot;Wrong id&quot;);</span>
}
<span class="fc" id="L42"> return this.taskMap.get(taskID);</span>
}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.13.202504020838</span></div></body></html>