1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.security.authorization.testwikis.internal.entities; |
21 |
|
|
22 |
|
import java.util.AbstractCollection; |
23 |
|
import java.util.Collection; |
24 |
|
import java.util.Iterator; |
25 |
|
import java.util.NoSuchElementException; |
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
@param |
32 |
|
|
33 |
|
@version |
34 |
|
@since |
35 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 5 |
Complexity Density: 0.56 |
|
36 |
|
public class TypeFilteredCollection<T> extends AbstractCollection<T> |
37 |
|
{ |
38 |
|
|
39 |
|
private final Collection<?> source; |
40 |
|
|
41 |
|
|
42 |
|
private final Class<T> type; |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
@param |
47 |
|
@param |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
49 |
84 |
TypeFilteredCollection(Collection<?> source, Class<T> type) {... |
50 |
84 |
this.source = source; |
51 |
84 |
this.type = type; |
52 |
|
} |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
@param |
57 |
|
@param |
58 |
|
@param |
59 |
|
@return |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
61 |
84 |
public static <T> TypeFilteredCollection<T> getNewInstance(Collection<?> source, Class<T> type) {... |
62 |
84 |
return new TypeFilteredCollection<T>(source, type); |
63 |
|
} |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
65 |
6 |
@Override... |
66 |
|
public int size() |
67 |
|
{ |
68 |
6 |
int count = 0; |
69 |
6 |
for (Object entity : source) { |
70 |
18 |
if (type.isAssignableFrom(entity.getClass())) { |
71 |
16 |
count++; |
72 |
|
} |
73 |
|
} |
74 |
6 |
return count; |
75 |
|
} |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
79 |
@Override... |
78 |
|
public Iterator<T> iterator() |
79 |
|
{ |
80 |
79 |
return new TypeFilteredIterator<T>(); |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
@param |
86 |
|
|
|
|
| 76.2% |
Uncovered Elements: 5 (21) |
Complexity: 8 |
Complexity Density: 0.67 |
|
87 |
|
class TypeFilteredIterator<T> implements Iterator<T> |
88 |
|
{ |
89 |
|
|
90 |
|
private final Iterator<?> it = source.iterator(); |
91 |
|
|
92 |
|
|
93 |
|
private Object next; |
94 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 5 |
Complexity Density: 0.83 |
|
95 |
153 |
@Override... |
96 |
|
public boolean hasNext() |
97 |
|
{ |
98 |
153 |
if (next == null) { |
99 |
116 |
do { |
100 |
116 |
try { |
101 |
116 |
next = it.next(); |
102 |
|
} catch (NoSuchElementException e) { |
103 |
79 |
next = null; |
104 |
|
} |
105 |
116 |
} while (next != null && !(type.isAssignableFrom(next.getClass()))); |
106 |
|
} |
107 |
153 |
return next != null; |
108 |
|
} |
109 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
110 |
37 |
@Override... |
111 |
|
@SuppressWarnings("unchecked") |
112 |
|
public T next() |
113 |
|
{ |
114 |
37 |
if (hasNext()) { |
115 |
37 |
T result = (T) next; |
116 |
37 |
next = null; |
117 |
37 |
return result; |
118 |
|
} else { |
119 |
0 |
throw new NoSuchElementException(); |
120 |
|
} |
121 |
|
} |
122 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
123 |
0 |
@Override... |
124 |
|
public void remove() |
125 |
|
{ |
126 |
0 |
throw new UnsupportedOperationException(); |
127 |
|
} |
128 |
|
} |
129 |
|
} |