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:
@@ -16,44 +16,82 @@ public class TaskManager {
|
||||
<span class="fc" id="L16"> }</span>
|
||||
|
||||
public Task createTask(String name, String description) {
|
||||
<span class="fc bfc" id="L19" title="All 4 branches covered."> if (name == null || description == null ) {</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="L21"> throw new IllegalArgumentException("Name/Description is null!");</span>
|
||||
}
|
||||
<span class="fc bfc" id="L23" title="All 2 branches covered."> if(name.isEmpty()) {</span>
|
||||
<span class="fc" id="L24"> throw new IllegalArgumentException("Name is empty!");</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>
|
||||
<span class="fc bfc" id="L27" title="All 2 branches covered."> if(!checkOnlyLetterOrDigit(name)) {</span>
|
||||
<span class="fc" id="L28"> throw new IllegalArgumentException("Only Letters or Digit are allowed in the name: " + name);</span>
|
||||
}
|
||||
|
||||
|
||||
<span class="fc" id="L32"> boolean taskExited = this.taskMap.values().stream().anyMatch(task -> task.getName().equals(name));</span>
|
||||
<span class="fc bfc" id="L33" title="All 2 branches covered."> if(taskExited) {</span>
|
||||
<span class="fc" id="L34"> throw new TaskAlreadyExistsException("Task already exits, with the name: " + name);</span>
|
||||
}
|
||||
|
||||
|
||||
<span class="fc" id="L38"> Task task = new Task(name, description);</span>
|
||||
<span class="fc" id="L39"> taskMap.put(task.getTaskID(), task);</span>
|
||||
<span class="fc" id="L40"> return task;</span>
|
||||
}
|
||||
|
||||
public List<Task> getTaskList() {
|
||||
<span class="fc" id="L31"> return new ArrayList<>(this.taskMap.values());</span>
|
||||
<span class="fc" id="L44"> 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>
|
||||
<span class="fc" id="L48"> return taskMap.values().stream().filter(t -> t.getName().equals(name)).findFirst()</span>
|
||||
<span class="fc" id="L49"> .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 bfc" id="L52" title="All 2 branches covered."> if(!this.taskMap.containsKey(taskID)) {</span>
|
||||
<span class="fc" id="L53"> throw new IllegalArgumentException("Wrong id");</span>
|
||||
}
|
||||
<span class="fc" id="L42"> return this.taskMap.get(taskID);</span>
|
||||
<span class="fc" id="L55"> return this.taskMap.get(taskID);</span>
|
||||
}
|
||||
|
||||
public void deleteTask(String name) {
|
||||
<span class="fc bfc" id="L46" title="All 2 branches covered."> if (name == null ) {</span>
|
||||
<span class="fc bfc" id="L59" title="All 2 branches covered."> if (name == null ) {</span>
|
||||
|
||||
<span class="fc" id="L48"> throw new IllegalArgumentException("Name is null!");</span>
|
||||
<span class="fc" id="L61"> throw new IllegalArgumentException("Name is null!");</span>
|
||||
}
|
||||
<span class="fc bfc" id="L50" title="All 4 branches covered."> if(name.isEmpty() || this.taskMap.values().stream().noneMatch(t -> t.getName().equals(name))) {</span>
|
||||
<span class="fc" id="L51"> throw new IllegalArgumentException("Wrong name!");</span>
|
||||
<span class="fc bfc" id="L63" title="All 4 branches covered."> if(name.isEmpty() || this.taskMap.values().stream().noneMatch(t -> t.getName().equals(name))) {</span>
|
||||
<span class="fc" id="L64"> throw new IllegalArgumentException("Wrong name!");</span>
|
||||
}
|
||||
|
||||
<span class="fc" id="L54"> this.taskMap.remove(this.taskMap.values().stream().filter(t -> t.getName().equals(name)).findFirst()</span>
|
||||
<span class="fc" id="L55"> .orElseThrow().getTaskID());</span>
|
||||
<span class="fc" id="L67"> this.taskMap.remove(this.taskMap.values().stream().filter(t -> t.getName().equals(name)).findFirst()</span>
|
||||
<span class="fc" id="L68"> .orElseThrow().getTaskID());</span>
|
||||
|
||||
<span class="fc" id="L57"> }</span>
|
||||
<span class="fc" id="L70"> }</span>
|
||||
|
||||
private boolean checkOnlyLetterOrDigit(String text) {
|
||||
<span class="fc" id="L73"> boolean result = true;</span>
|
||||
|
||||
<span class="fc bfc" id="L75" title="All 2 branches covered."> for(int i = 0; i < text.length(); i++) {</span>
|
||||
<span class="fc" id="L76"> char c = text.charAt(i);</span>
|
||||
<span class="fc bfc" id="L77" title="All 2 branches covered."> if(!Character.isLetterOrDigit(c)) {</span>
|
||||
<span class="fc" id="L78"> result = false;</span>
|
||||
<span class="fc" id="L79"> break;</span>
|
||||
}
|
||||
}
|
||||
<span class="fc" id="L82"> return result;</span>
|
||||
}
|
||||
// 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;
|
||||
// }
|
||||
}
|
||||
</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