1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.mail.internal; |
21 |
|
|
22 |
|
import java.util.Iterator; |
23 |
|
import java.util.LinkedHashMap; |
24 |
|
import java.util.Map; |
25 |
|
import java.util.NoSuchElementException; |
26 |
|
|
27 |
|
import org.xwiki.mail.MailState; |
28 |
|
import org.xwiki.mail.MailStatus; |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
@version |
37 |
|
@since |
38 |
|
|
|
|
| 85.7% |
Uncovered Elements: 2 (14) |
Complexity: 7 |
Complexity Density: 1 |
|
39 |
|
public class MemoryMailStatusResult extends AbstractMailStatusResult |
40 |
|
{ |
|
|
| 81% |
Uncovered Elements: 4 (21) |
Complexity: 7 |
Complexity Density: 0.58 |
|
41 |
|
private abstract class AbstractMailStatusIterator implements Iterator<MailStatus> |
42 |
|
{ |
43 |
|
private final Iterator<MailStatus> it = statusMap.values().iterator(); |
44 |
|
private MailStatus nextStatus; |
45 |
|
|
46 |
|
abstract boolean match(MailStatus status); |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
48 |
33 |
@Override... |
49 |
|
public boolean hasNext() |
50 |
|
{ |
51 |
62 |
while (nextStatus == null && it.hasNext()) { |
52 |
29 |
nextStatus = it.next(); |
53 |
29 |
if (!match(nextStatus)) { |
54 |
16 |
nextStatus = null; |
55 |
|
} |
56 |
|
} |
57 |
33 |
return (nextStatus != null); |
58 |
|
} |
59 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
60 |
13 |
@Override... |
61 |
|
public MailStatus next() |
62 |
|
{ |
63 |
13 |
hasNext(); |
64 |
13 |
if (nextStatus == null) { |
65 |
0 |
throw new NoSuchElementException(); |
66 |
|
} |
67 |
13 |
try { |
68 |
13 |
return nextStatus; |
69 |
|
} finally { |
70 |
13 |
nextStatus = null; |
71 |
|
} |
72 |
|
} |
73 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
74 |
0 |
@Override... |
75 |
|
public void remove() |
76 |
|
{ |
77 |
0 |
throw new UnsupportedOperationException(); |
78 |
|
} |
79 |
|
} |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
private Map<String, MailStatus> statusMap = new LinkedHashMap<>(); |
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
@param |
93 |
|
@return |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
95 |
2 |
public MailStatus getStatus(String uniqueMessageId)... |
96 |
|
{ |
97 |
2 |
return this.statusMap.get(uniqueMessageId); |
98 |
|
} |
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
@param |
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
105 |
33 |
public void setStatus(MailStatus status)... |
106 |
|
{ |
107 |
33 |
this.statusMap.put(status.getMessageId(), status); |
108 |
|
} |
109 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
110 |
0 |
@Override... |
111 |
|
public Iterator<MailStatus> getAll() |
112 |
|
{ |
113 |
0 |
return this.statusMap.values().iterator(); |
114 |
|
} |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
116 |
1 |
@Override... |
117 |
|
public Iterator<MailStatus> getAllErrors() |
118 |
|
{ |
119 |
1 |
return new AbstractMailStatusIterator() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
120 |
5 |
@Override... |
121 |
|
boolean match(MailStatus status) |
122 |
|
{ |
123 |
5 |
return status.getState().endsWith("_error"); |
124 |
|
} |
125 |
|
}; |
126 |
|
} |
127 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
128 |
15 |
@Override... |
129 |
|
public Iterator<MailStatus> getByState(final MailState state) |
130 |
|
{ |
131 |
15 |
return new AbstractMailStatusIterator() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
132 |
24 |
@Override... |
133 |
|
boolean match(MailStatus status) |
134 |
|
{ |
135 |
24 |
return MailState.parse(status.getState()).equals(state); |
136 |
|
} |
137 |
|
}; |
138 |
|
} |
139 |
|
} |