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.factory.usersandgroups; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Iterator; |
24 |
|
import java.util.List; |
25 |
|
import java.util.NoSuchElementException; |
26 |
|
|
27 |
|
import javax.mail.Address; |
28 |
|
|
29 |
|
import org.xwiki.context.Execution; |
30 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
31 |
|
|
32 |
|
import com.xpn.xwiki.internal.plugin.rightsmanager.UserIterator; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
@version |
39 |
|
@since |
40 |
|
@since |
41 |
|
|
|
|
| 82.1% |
Uncovered Elements: 7 (39) |
Complexity: 11 |
Complexity Density: 0.48 |
|
42 |
|
public class AddressUserIterator extends UserIterator<Address> |
43 |
|
{ |
44 |
|
private UsersAndGroupsSource usersAndGroupsSource; |
45 |
|
|
46 |
|
private Iterator<Address> addressIterator; |
47 |
|
|
48 |
|
private List<Address> excludedAddresses; |
49 |
|
|
50 |
|
private List<Address> processedAddresses = new ArrayList<>(); |
51 |
|
|
52 |
|
private Address lookaheadAddress; |
53 |
|
|
54 |
|
|
55 |
|
@param |
56 |
|
|
57 |
|
@param |
58 |
|
@link |
59 |
|
@param@link |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
61 |
4 |
public AddressUserIterator(UsersAndGroupsSource usersAndGroupsSource,... |
62 |
|
DocumentReferenceResolver<String> explicitDocumentReferenceResolver, Execution execution) |
63 |
|
{ |
64 |
4 |
super(usersAndGroupsSource.getIncludedUserAndGroupReferences(), |
65 |
|
usersAndGroupsSource.getExcludedUserAndGroupReferences(), new AddressUserDataExtractor(), |
66 |
|
explicitDocumentReferenceResolver, execution); |
67 |
4 |
this.addressIterator = usersAndGroupsSource.getIncludedAddresses().iterator(); |
68 |
4 |
this.excludedAddresses = usersAndGroupsSource.getExcludedAddresses(); |
69 |
4 |
this.usersAndGroupsSource = usersAndGroupsSource; |
70 |
|
} |
71 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
72 |
7 |
@Override... |
73 |
|
public boolean hasNext() |
74 |
|
{ |
75 |
7 |
if (this.lookaheadAddress == null) { |
76 |
7 |
this.lookaheadAddress = getNext(); |
77 |
|
} |
78 |
7 |
return this.lookaheadAddress != null; |
79 |
|
} |
80 |
|
|
|
|
| 45.5% |
Uncovered Elements: 6 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
81 |
5 |
@Override... |
82 |
|
public Address next() |
83 |
|
{ |
84 |
5 |
Address address = this.lookaheadAddress; |
85 |
5 |
if (address != null) { |
86 |
5 |
this.lookaheadAddress = null; |
87 |
|
} else { |
88 |
0 |
address = getNext(); |
89 |
0 |
if (address == null) { |
90 |
0 |
throw new NoSuchElementException(String.format("No more addresses to extract from [%s]", |
91 |
|
this.usersAndGroupsSource)); |
92 |
|
} |
93 |
|
} |
94 |
5 |
return address; |
95 |
|
} |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 5 |
Complexity Density: 0.56 |
|
97 |
7 |
private Address getNext()... |
98 |
|
{ |
99 |
7 |
Address address; |
100 |
|
|
101 |
7 |
do { |
102 |
|
|
103 |
|
|
104 |
9 |
if (super.hasNext()) { |
105 |
6 |
address = super.next(); |
106 |
3 |
} else if (this.addressIterator.hasNext()) { |
107 |
1 |
address = this.addressIterator.next(); |
108 |
|
} else { |
109 |
2 |
return null; |
110 |
|
} |
111 |
7 |
} while (this.excludedAddresses.contains(address) || this.processedAddresses.contains(address)); |
112 |
|
|
113 |
5 |
this.processedAddresses.add(address); |
114 |
|
|
115 |
5 |
return address; |
116 |
|
} |
117 |
|
} |