1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.script.internal.safe; |
21 |
|
|
22 |
|
import java.lang.reflect.Constructor; |
23 |
|
import java.util.Collection; |
24 |
|
import java.util.Iterator; |
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
@param |
30 |
|
@param |
31 |
|
@version |
32 |
|
@since |
33 |
|
|
|
|
| 0% |
Uncovered Elements: 47 (47) |
Complexity: 19 |
Complexity Density: 0.73 |
|
34 |
|
public class SafeCollection<E, C extends Collection<E>> extends AbstractSafeObject<C> implements Collection<E> |
35 |
|
{ |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
protected Constructor< ? extends E> safeConstructor; |
40 |
|
|
41 |
|
|
42 |
|
@param |
43 |
|
@param |
44 |
|
@param |
45 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
46 |
0 |
public SafeCollection(C collection, ScriptSafeProvider< ? > safeProvider, Constructor< ? extends E> safeConstructor)... |
47 |
|
{ |
48 |
0 |
super(collection, safeProvider); |
49 |
|
|
50 |
0 |
this.safeConstructor = safeConstructor; |
51 |
|
} |
52 |
|
|
53 |
|
|
54 |
|
@param |
55 |
|
@return |
56 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
57 |
0 |
protected E safeElement(E element)... |
58 |
|
{ |
59 |
0 |
if (this.safeConstructor != null) { |
60 |
0 |
try { |
61 |
0 |
return this.safeConstructor.newInstance(element, this.safeProvider); |
62 |
|
} catch (Exception e) { |
63 |
0 |
return safe(element); |
64 |
|
} |
65 |
|
} else { |
66 |
0 |
return safe(element); |
67 |
|
} |
68 |
|
} |
69 |
|
|
70 |
|
|
71 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
0 |
@Override... |
73 |
|
public int size() |
74 |
|
{ |
75 |
0 |
return getWrapped().size(); |
76 |
|
} |
77 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
0 |
@Override... |
79 |
|
public boolean isEmpty() |
80 |
|
{ |
81 |
0 |
return getWrapped().isEmpty(); |
82 |
|
} |
83 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
84 |
0 |
@Override... |
85 |
|
public boolean contains(Object o) |
86 |
|
{ |
87 |
0 |
return getWrapped().contains(o); |
88 |
|
} |
89 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
90 |
0 |
@Override... |
91 |
|
public Iterator<E> iterator() |
92 |
|
{ |
93 |
0 |
return new SafeIterator<E, Iterator<E>>(getWrapped().iterator(), this.safeProvider, this.safeConstructor); |
94 |
|
} |
95 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
96 |
0 |
@Override... |
97 |
|
public Object[] toArray() |
98 |
|
{ |
99 |
0 |
Object[] copy = getWrapped().toArray(); |
100 |
|
|
101 |
0 |
for (int i = 0; i < copy.length; ++i) { |
102 |
0 |
copy[i] = safe(copy[i]); |
103 |
|
} |
104 |
|
|
105 |
0 |
return copy; |
106 |
|
} |
107 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
108 |
0 |
@Override... |
109 |
|
public <T> T[] toArray(T[] a) |
110 |
|
{ |
111 |
0 |
T[] copy = getWrapped().toArray(a); |
112 |
|
|
113 |
0 |
for (int i = 0; i < copy.length; ++i) { |
114 |
0 |
copy[i] = safe(copy[i]); |
115 |
|
} |
116 |
|
|
117 |
0 |
return copy; |
118 |
|
} |
119 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
120 |
0 |
@Override... |
121 |
|
public boolean add(E e) |
122 |
|
{ |
123 |
0 |
throw new UnsupportedOperationException(FORBIDDEN); |
124 |
|
} |
125 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
126 |
0 |
@Override... |
127 |
|
public boolean remove(Object o) |
128 |
|
{ |
129 |
0 |
throw new UnsupportedOperationException(FORBIDDEN); |
130 |
|
} |
131 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
132 |
0 |
@Override... |
133 |
|
public boolean containsAll(Collection< ? > c) |
134 |
|
{ |
135 |
0 |
return getWrapped().containsAll(c); |
136 |
|
} |
137 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
138 |
0 |
@Override... |
139 |
|
public boolean addAll(Collection< ? extends E> c) |
140 |
|
{ |
141 |
0 |
throw new UnsupportedOperationException(FORBIDDEN); |
142 |
|
} |
143 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
144 |
0 |
@Override... |
145 |
|
public boolean removeAll(Collection< ? > c) |
146 |
|
{ |
147 |
0 |
throw new UnsupportedOperationException(FORBIDDEN); |
148 |
|
} |
149 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
150 |
0 |
@Override... |
151 |
|
public boolean retainAll(Collection< ? > c) |
152 |
|
{ |
153 |
0 |
throw new UnsupportedOperationException(FORBIDDEN); |
154 |
|
} |
155 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
156 |
0 |
@Override... |
157 |
|
public void clear() |
158 |
|
{ |
159 |
0 |
throw new UnsupportedOperationException(FORBIDDEN); |
160 |
|
} |
161 |
|
} |