upload
This commit is contained in:
@@ -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<>();</span>
|
||||
<span class="fc" id="L14"> }</span>
|
||||
<span class="fc" id="L14"> public TaskManager() {</span>
|
||||
<span class="fc" id="L15"> taskMap = new HashMap<>();</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 -> 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("Task already exits, with the name: " + name);</span>
|
||||
<span class="fc" id="L20"> boolean taskExited = this.taskMap.values().stream().anyMatch(task -> 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("Task already exits, with the name: " + 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<Task> getTaskList() {
|
||||
<span class="fc" id="L31"> return new ArrayList<>(this.taskMap.values());</span>
|
||||
}
|
||||
|
||||
public Task getTask(String name) {
|
||||
<span class="fc" id="L35"> return taskMap.values().stream().filter(t -> t.getName().equals(name)).findFirst()</span>
|
||||
<span class="fc" id="L36"> .orElseThrow(() -> new IllegalArgumentException("Wrong name"));</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("Wrong id");</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>
|
||||
Reference in New Issue
Block a user