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; |
21 |
|
|
22 |
|
import java.util.AbstractSet; |
23 |
|
import java.util.Collection; |
24 |
|
import java.util.Collections; |
25 |
|
import java.util.Iterator; |
26 |
|
import java.util.NoSuchElementException; |
27 |
|
|
28 |
|
|
29 |
|
@link |
30 |
|
|
31 |
|
@version |
32 |
|
@since |
33 |
|
|
|
|
| 88.7% |
Uncovered Elements: 14 (124) |
Complexity: 38 |
Complexity Density: 0.54 |
|
34 |
|
public class RightSet extends AbstractSet<Right> implements Cloneable, java.io.Serializable |
35 |
|
{ |
36 |
|
|
37 |
|
private static final long serialVersionUID = 1L; |
38 |
|
|
39 |
|
|
40 |
|
private long rights; |
41 |
|
|
42 |
|
|
|
|
| 50% |
Uncovered Elements: 2 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
43 |
33346 |
public RightSet()... |
44 |
|
{ |
45 |
33347 |
if (Right.size() > 64) { |
46 |
0 |
throw new IllegalStateException(); |
47 |
|
} |
48 |
|
} |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
@param |
54 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
55 |
303 |
public RightSet(Collection<? extends Right> rights)... |
56 |
|
{ |
57 |
303 |
if (Right.size() > 64) { |
58 |
0 |
throw new IllegalStateException(); |
59 |
|
} |
60 |
303 |
this.addAll(rights); |
61 |
|
} |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
@param |
66 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
67 |
444 |
public RightSet(Right... rights)... |
68 |
|
{ |
69 |
444 |
if (Right.size() > 64) { |
70 |
0 |
throw new IllegalStateException(); |
71 |
|
} |
72 |
|
|
73 |
444 |
Collections.addAll(this, rights); |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
24054 |
@Override... |
77 |
|
public Iterator<Right> iterator() |
78 |
|
{ |
79 |
24054 |
return new RightIterator(); |
80 |
|
} |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 6 |
Complexity Density: 0.55 |
|
85 |
|
private class RightIterator implements Iterator<Right> |
86 |
|
{ |
87 |
|
|
88 |
|
|
89 |
|
private long index; |
90 |
|
|
91 |
|
|
92 |
|
private long lastIndex; |
93 |
|
|
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
95 |
24056 |
RightIterator()... |
96 |
|
{ |
97 |
24056 |
index = rights; |
98 |
|
} |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
100 |
145774 |
@Override... |
101 |
|
public boolean hasNext() |
102 |
|
{ |
103 |
145778 |
return index != 0; |
104 |
|
} |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
106 |
122456 |
@Override... |
107 |
|
public Right next() |
108 |
|
{ |
109 |
122457 |
if (index == 0) { |
110 |
39 |
throw new NoSuchElementException(); |
111 |
|
} |
112 |
122419 |
lastIndex = index & -index; |
113 |
122420 |
index -= lastIndex; |
114 |
122421 |
return Right.get(Long.numberOfTrailingZeros(lastIndex)); |
115 |
|
} |
116 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
117 |
1238 |
@Override... |
118 |
|
public void remove() |
119 |
|
{ |
120 |
1238 |
if (lastIndex == 0) { |
121 |
789 |
throw new IllegalStateException(); |
122 |
|
} |
123 |
449 |
rights -= lastIndex; |
124 |
449 |
lastIndex = 0; |
125 |
|
} |
126 |
|
} |
127 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
128 |
489 |
@Override... |
129 |
|
public boolean equals(Object o) |
130 |
|
{ |
131 |
489 |
if (!(o instanceof RightSet)) { |
132 |
21 |
return super.equals(o); |
133 |
|
} |
134 |
|
|
135 |
468 |
return ((RightSet) o).rights == rights; |
136 |
|
} |
137 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
138 |
330 |
@Override... |
139 |
|
public int hashCode() |
140 |
|
{ |
141 |
330 |
return new Long(rights).hashCode(); |
142 |
|
} |
143 |
|
|
|
|
| 42.9% |
Uncovered Elements: 4 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
144 |
21 |
@Override... |
145 |
|
public boolean removeAll(Collection<?> objects) |
146 |
|
{ |
147 |
21 |
if (!(objects instanceof RightSet)) { |
148 |
21 |
return super.removeAll(objects); |
149 |
|
} |
150 |
0 |
long old = rights; |
151 |
0 |
rights &= ~((RightSet) objects).rights; |
152 |
0 |
return rights != old; |
153 |
|
} |
154 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
155 |
54720 |
@Override... |
156 |
|
public boolean add(Right right) |
157 |
|
{ |
158 |
54720 |
long old = rights; |
159 |
54720 |
rights |= (1L << right.ordinal()); |
160 |
54721 |
return rights != old; |
161 |
|
} |
162 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
163 |
1704 |
@Override... |
164 |
|
public boolean addAll(Collection<? extends Right> rights) |
165 |
|
{ |
166 |
1705 |
if (!(rights instanceof RightSet)) { |
167 |
19 |
return super.addAll(rights); |
168 |
|
} |
169 |
|
|
170 |
1685 |
long old = this.rights; |
171 |
1685 |
this.rights |= ((RightSet) rights).rights; |
172 |
1685 |
return this.rights != old; |
173 |
|
} |
174 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
175 |
3 |
@Override... |
176 |
|
public void clear() |
177 |
|
{ |
178 |
3 |
rights = 0; |
179 |
|
} |
180 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
181 |
380906 |
@Override... |
182 |
|
public boolean contains(Object o) |
183 |
|
{ |
184 |
380914 |
return o != null && o instanceof Right && (rights & (1L << ((Right) o).ordinal())) != 0; |
185 |
|
} |
186 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
187 |
30 |
@Override... |
188 |
|
public boolean containsAll(Collection<?> objects) |
189 |
|
{ |
190 |
30 |
if (!(objects instanceof RightSet)) { |
191 |
27 |
return super.containsAll(objects); |
192 |
|
} |
193 |
3 |
return (((RightSet) objects).rights & ~rights) == 0; |
194 |
|
} |
195 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
196 |
37611 |
@Override... |
197 |
|
public boolean remove(Object o) |
198 |
|
{ |
199 |
37612 |
if (o == null || !(o instanceof Right)) { |
200 |
12 |
return false; |
201 |
|
} |
202 |
37600 |
long old = rights; |
203 |
37600 |
rights &= ~(1L << ((Right) o).ordinal()); |
204 |
37600 |
return rights != old; |
205 |
|
} |
206 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
207 |
75789 |
@Override... |
208 |
|
public boolean isEmpty() |
209 |
|
{ |
210 |
75789 |
return rights == 0; |
211 |
|
} |
212 |
|
|
|
|
| 42.9% |
Uncovered Elements: 4 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
213 |
22 |
@Override... |
214 |
|
public boolean retainAll(Collection<?> objects) |
215 |
|
{ |
216 |
22 |
if (!(objects instanceof RightSet)) { |
217 |
22 |
return super.retainAll(objects); |
218 |
|
} |
219 |
0 |
long old = rights; |
220 |
0 |
rights &= ((RightSet) objects).rights; |
221 |
0 |
return rights != old; |
222 |
|
} |
223 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
224 |
1163 |
@Override... |
225 |
|
public int size() |
226 |
|
{ |
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
1163 |
long v = rights - ((rights >>> 1) & 0x5555555555555555L); |
238 |
1163 |
v = (v & 0x3333333333333333L) + ((v >>> 2) & 0x3333333333333333L); |
239 |
1163 |
return (int) (((v + (v >> 4) & 0x0F0F0F0F0F0F0F0FL) * 0x0101010101010101L) >>> 56); |
240 |
|
} |
241 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
242 |
6 |
@Override... |
243 |
|
public Object[] toArray() |
244 |
|
{ |
245 |
6 |
return fillArray(new Object[size()]); |
246 |
|
} |
247 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
248 |
30 |
@Override... |
249 |
|
@SuppressWarnings("unchecked") |
250 |
|
public <T> T[] toArray(T[] ts) |
251 |
|
{ |
252 |
30 |
T[] a = ts; |
253 |
30 |
int size = size(); |
254 |
30 |
if (a.length < size) { |
255 |
11 |
a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); |
256 |
|
} |
257 |
30 |
if (a.length > size) { |
258 |
6 |
a[size] = null; |
259 |
|
} |
260 |
30 |
return (T[]) fillArray(a); |
261 |
|
} |
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
@param |
266 |
|
@return |
267 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
268 |
36 |
private Object[] fillArray(Object[] ts)... |
269 |
|
{ |
270 |
36 |
int j = 0; |
271 |
446 |
for (int i = 0; i < Right.size(); i++) { |
272 |
412 |
if ((rights & (1 << i)) > 0) { |
273 |
101 |
ts[j++] = Right.get(i); |
274 |
|
} |
275 |
|
} |
276 |
34 |
return ts; |
277 |
|
} |
278 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 4 |
Complexity Density: 0.4 |
|
279 |
6 |
@Override... |
280 |
|
public String toString() |
281 |
|
{ |
282 |
6 |
StringBuilder sb = new StringBuilder("["); |
283 |
6 |
boolean first = true; |
284 |
78 |
for (int i = 0; i < Right.size(); i++) { |
285 |
72 |
if ((rights & (1 << i)) > 0) { |
286 |
13 |
if (first) { |
287 |
5 |
first = false; |
288 |
|
} else { |
289 |
8 |
sb.append(", "); |
290 |
|
} |
291 |
13 |
sb.append(Right.get(i).getName()); |
292 |
|
} |
293 |
|
} |
294 |
6 |
sb.append("]"); |
295 |
6 |
return sb.toString(); |
296 |
|
} |
297 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
298 |
4938 |
@Override... |
299 |
|
public RightSet clone() throws CloneNotSupportedException |
300 |
|
{ |
301 |
4938 |
RightSet clone = (RightSet) super.clone(); |
302 |
4938 |
clone.rights = rights; |
303 |
4938 |
return clone; |
304 |
|
} |
305 |
|
} |