1 | package de.aikiit.mailversendala; | |
2 | ||
3 | import java.util.Optional; | |
4 | import java.util.concurrent.atomic.AtomicInteger; | |
5 | ||
6 | /** | |
7 | * Class encapsulates internal counters to gauge | |
8 | * <ul> | |
9 | * <li>how many errors and</li> | |
10 | * <li>how many mails were successfully sent out</li> | |
11 | * </ul> | |
12 | * during an application run. | |
13 | */ | |
14 | public class MailingResult { | |
15 | ||
16 | private AtomicInteger errorCounter; | |
17 | private AtomicInteger mailCounter; | |
18 | ||
19 | /** | |
20 | * Increment internal error counter by 1. | |
21 | */ | |
22 | public void addError() { | |
23 |
1
1. addError : negated conditional → KILLED |
if (errorCounter == null) { |
24 | this.errorCounter = new AtomicInteger(0); | |
25 | } | |
26 | errorCounter.incrementAndGet(); | |
27 | } | |
28 | ||
29 | /** | |
30 | * Increment internal success counter by 1. | |
31 | */ | |
32 | public void addSuccess() { | |
33 |
1
1. addSuccess : negated conditional → KILLED |
if (mailCounter == null) { |
34 | this.mailCounter = new AtomicInteger(0); | |
35 | } | |
36 | mailCounter.incrementAndGet(); | |
37 | } | |
38 | ||
39 | /** | |
40 | * Returns error counter. | |
41 | * @return current error counter if existing. | |
42 | */ | |
43 | public Optional<AtomicInteger> getErrorCounter() { | |
44 |
1
1. getErrorCounter : replaced return value with Optional.empty for de/aikiit/mailversendala/MailingResult::getErrorCounter → KILLED |
return Optional.ofNullable(errorCounter); |
45 | } | |
46 | ||
47 | /** | |
48 | * Returns success counter. | |
49 | * @return current success counter if existing. | |
50 | */ | |
51 | public Optional<AtomicInteger> getMailCounter() { | |
52 |
1
1. getMailCounter : replaced return value with Optional.empty for de/aikiit/mailversendala/MailingResult::getMailCounter → KILLED |
return Optional.ofNullable(mailCounter); |
53 | } | |
54 | ||
55 | /** | |
56 | * Returns total counter. | |
57 | * @return sum of {@link #mailCounter} and {@link #errorCounter}. | |
58 | */ | |
59 | public int getTotal() { | |
60 |
2
1. getTotal : Replaced integer addition with subtraction → KILLED 2. getTotal : replaced int return with 0 for de/aikiit/mailversendala/MailingResult::getTotal → KILLED |
return getErrorCounter().orElse(new AtomicInteger(0)).get() + getMailCounter().orElse(new AtomicInteger(0)).get(); |
61 | } | |
62 | ||
63 | } | |
Mutations | ||
23 |
1.1 |
|
33 |
1.1 |
|
44 |
1.1 |
|
52 |
1.1 |
|
60 |
1.1 2.2 |