1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.objects; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Iterator; |
24 |
|
import java.util.List; |
25 |
|
|
26 |
|
import org.dom4j.Element; |
27 |
|
import org.dom4j.dom.DOMElement; |
28 |
|
import org.hibernate.collection.PersistentCollection; |
29 |
|
import org.xwiki.xar.internal.property.ListXarObjectPropertySerializer; |
30 |
|
|
31 |
|
import com.xpn.xwiki.doc.merge.MergeResult; |
32 |
|
import com.xpn.xwiki.internal.AbstractNotifyOnUpdateList; |
33 |
|
import com.xpn.xwiki.internal.merge.MergeUtils; |
34 |
|
import com.xpn.xwiki.internal.objects.ListPropertyPersistentList; |
35 |
|
import com.xpn.xwiki.objects.classes.ListClass; |
36 |
|
|
|
|
| 71.8% |
Uncovered Elements: 31 (110) |
Complexity: 36 |
Complexity Density: 0.59 |
|
37 |
|
public class ListProperty extends BaseProperty implements Cloneable |
38 |
|
{ |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
protected transient List<String> list; |
43 |
|
|
44 |
|
|
45 |
|
@deprecated |
46 |
|
@link |
47 |
|
@link |
48 |
|
|
49 |
|
@Deprecated |
50 |
|
private String formStringSeparator = ListClass.DEFAULT_SEPARATOR; |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
private List<String> actualList = new ArrayList<String>(); |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
964 |
{... |
58 |
964 |
this.list = new NotifyList(this.actualList, this); |
59 |
|
} |
60 |
|
|
61 |
|
|
62 |
|
@deprecated |
63 |
|
@link |
64 |
|
@link |
65 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
0 |
@Deprecated... |
67 |
|
public String getFormStringSeparator() |
68 |
|
{ |
69 |
0 |
return this.formStringSeparator; |
70 |
|
} |
71 |
|
|
72 |
|
|
73 |
|
@deprecated |
74 |
|
@link |
75 |
|
@link |
76 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
0 |
@Deprecated... |
78 |
|
public void setFormStringSeparator(String formStringSeparator) |
79 |
|
{ |
80 |
0 |
this.formStringSeparator = formStringSeparator; |
81 |
|
} |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
83 |
4857 |
@Override... |
84 |
|
public Object getValue() |
85 |
|
{ |
86 |
4857 |
return getList(); |
87 |
|
} |
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
89 |
189 |
@Override... |
90 |
|
public void setValue(Object value) |
91 |
|
{ |
92 |
189 |
this.setList((List<String>) value); |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
@return |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
100 |
257 |
public String getTextValue()... |
101 |
|
{ |
102 |
257 |
return toText(); |
103 |
|
} |
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
105 |
742 |
@Override... |
106 |
|
public String toText() |
107 |
|
{ |
108 |
|
|
109 |
|
|
110 |
742 |
return ListClass.getStringFromList(this.getList(), ListClass.DEFAULT_SEPARATOR); |
111 |
|
} |
112 |
|
|
113 |
|
|
114 |
|
@deprecated |
115 |
|
@link |
116 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
117 |
0 |
@Deprecated... |
118 |
|
public String toSingleFormString() |
119 |
|
{ |
120 |
0 |
return super.toFormString(); |
121 |
|
} |
122 |
|
|
|
|
| 68.8% |
Uncovered Elements: 10 (32) |
Complexity: 10 |
Complexity Density: 0.56 |
|
123 |
96 |
@Override... |
124 |
|
public boolean equals(Object obj) |
125 |
|
{ |
126 |
|
|
127 |
96 |
if (this == obj) { |
128 |
93 |
return true; |
129 |
|
} |
130 |
|
|
131 |
3 |
if (!super.equals(obj)) { |
132 |
0 |
return false; |
133 |
|
} |
134 |
|
|
135 |
3 |
List<String> list1 = getList(); |
136 |
3 |
List<String> list2 = (List<String>) ((BaseProperty) obj).getValue(); |
137 |
|
|
138 |
|
|
139 |
|
|
140 |
3 |
if ((list1 instanceof PersistentCollection) && (!((PersistentCollection) list1).wasInitialized())) { |
141 |
0 |
return true; |
142 |
|
} |
143 |
|
|
144 |
3 |
if ((list2 instanceof PersistentCollection) && (!((PersistentCollection) list2).wasInitialized())) { |
145 |
0 |
return true; |
146 |
|
} |
147 |
|
|
148 |
3 |
if (list1.size() != list2.size()) { |
149 |
0 |
return false; |
150 |
|
} |
151 |
|
|
152 |
9 |
for (int i = 0; i < list1.size(); i++) { |
153 |
6 |
Object obj1 = list1.get(i); |
154 |
6 |
Object obj2 = list2.get(i); |
155 |
|
|
156 |
6 |
if (!obj1.equals(obj2)) { |
157 |
0 |
return false; |
158 |
|
} |
159 |
|
} |
160 |
|
|
161 |
3 |
return true; |
162 |
|
} |
163 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
164 |
4805 |
@Override... |
165 |
|
public ListProperty clone() |
166 |
|
{ |
167 |
4805 |
return (ListProperty) super.clone(); |
168 |
|
} |
169 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
170 |
4804 |
@Override... |
171 |
|
protected void cloneInternal(BaseProperty clone) |
172 |
|
{ |
173 |
4804 |
ListProperty property = (ListProperty) clone; |
174 |
4804 |
property.actualList = new ArrayList<String>(); |
175 |
4806 |
for (String entry : getList()) { |
176 |
1806 |
property.actualList.add(entry); |
177 |
|
} |
178 |
4806 |
property.list = new NotifyList(property.actualList, property); |
179 |
|
} |
180 |
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
181 |
11648 |
public List<String> getList()... |
182 |
|
{ |
183 |
|
|
184 |
|
|
185 |
11648 |
if (this.list instanceof NotifyList) { |
186 |
5154 |
((NotifyList) this.list).setOwner(this); |
187 |
6494 |
} else if (this.list instanceof ListPropertyPersistentList) { |
188 |
6493 |
((ListPropertyPersistentList) this.list).setOwner(this); |
189 |
|
} |
190 |
|
|
191 |
11649 |
return this.list; |
192 |
|
} |
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
@param |
199 |
|
|
|
|
| 82.4% |
Uncovered Elements: 6 (34) |
Complexity: 9 |
Complexity Density: 0.45 |
|
200 |
1190 |
public void setList(List<String> list)... |
201 |
|
{ |
202 |
1190 |
if (list == this.list || list == this.actualList) { |
203 |
|
|
204 |
0 |
return; |
205 |
|
} |
206 |
|
|
207 |
1190 |
if (this.list instanceof ListPropertyPersistentList) { |
208 |
55 |
ListPropertyPersistentList persistentList = (ListPropertyPersistentList) this.list; |
209 |
55 |
if (persistentList.isWrapper(list)) { |
210 |
|
|
211 |
0 |
return; |
212 |
|
} |
213 |
|
} |
214 |
|
|
215 |
1190 |
if (list instanceof ListPropertyPersistentList) { |
216 |
|
|
217 |
607 |
ListPropertyPersistentList persistentList = (ListPropertyPersistentList) list; |
218 |
607 |
this.list = persistentList; |
219 |
607 |
persistentList.setOwner(this); |
220 |
607 |
return; |
221 |
|
} |
222 |
|
|
223 |
583 |
if (list == null) { |
224 |
1 |
setValueDirty(true); |
225 |
1 |
this.actualList = new ArrayList(); |
226 |
1 |
this.list = new NotifyList(this.actualList, this); |
227 |
|
} else { |
228 |
582 |
this.list.clear(); |
229 |
582 |
this.list.addAll(list); |
230 |
|
} |
231 |
|
|
232 |
|
|
233 |
|
|
234 |
951 |
for (Iterator<String> it = this.list.iterator(); it.hasNext();) { |
235 |
368 |
if (it.next() == null) { |
236 |
0 |
it.remove(); |
237 |
|
} |
238 |
|
} |
239 |
|
} |
240 |
|
|
241 |
|
|
242 |
|
@inheritDoc |
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
@see |
248 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
249 |
0 |
@Override... |
250 |
|
public String toString() |
251 |
|
{ |
252 |
0 |
if ((getList() instanceof PersistentCollection) && (!((PersistentCollection) getList()).wasInitialized())) { |
253 |
0 |
return ""; |
254 |
|
} |
255 |
|
|
256 |
0 |
return super.toString(); |
257 |
|
} |
258 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
259 |
0 |
@Override... |
260 |
|
protected void mergeValue(Object previousValue, Object newValue, MergeResult mergeResult) |
261 |
|
{ |
262 |
0 |
MergeUtils.mergeList((List<String>) previousValue, (List<String>) newValue, this.list, mergeResult); |
263 |
|
} |
264 |
|
|
265 |
|
|
266 |
|
|
267 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 8 |
Complexity Density: 0.62 |
|
268 |
|
public static class NotifyList extends AbstractNotifyOnUpdateList<String> |
269 |
|
{ |
270 |
|
|
271 |
|
|
272 |
|
private ListProperty owner; |
273 |
|
|
274 |
|
|
275 |
|
private boolean dirty; |
276 |
|
|
277 |
|
private List<String> actualList; |
278 |
|
|
279 |
|
|
280 |
|
@param@link |
281 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
282 |
6487 |
public NotifyList(List<String> list)... |
283 |
|
{ |
284 |
6487 |
super(list); |
285 |
6487 |
this.actualList = list; |
286 |
|
} |
287 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
288 |
5771 |
private NotifyList(List<String> list, ListProperty owner)... |
289 |
|
{ |
290 |
5771 |
this(list); |
291 |
|
|
292 |
5771 |
this.owner = owner; |
293 |
|
} |
294 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
295 |
996 |
@Override... |
296 |
|
public void onUpdate() |
297 |
|
{ |
298 |
996 |
setDirty(); |
299 |
|
} |
300 |
|
|
301 |
|
|
302 |
|
@param |
303 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
304 |
12255 |
public void setOwner(ListProperty owner)... |
305 |
|
{ |
306 |
12257 |
if (this.dirty) { |
307 |
5221 |
owner.setValueDirty(true); |
308 |
|
} |
309 |
12257 |
this.owner = owner; |
310 |
12256 |
owner.actualList = this.actualList; |
311 |
|
} |
312 |
|
|
313 |
|
|
314 |
|
@return |
315 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
316 |
55 |
public boolean isWrapper(Object collection)... |
317 |
|
{ |
318 |
55 |
return this.actualList == collection; |
319 |
|
} |
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
324 |
996 |
private void setDirty()... |
325 |
|
{ |
326 |
996 |
if (this.owner != null) { |
327 |
808 |
this.owner.setValueDirty(true); |
328 |
|
} |
329 |
996 |
this.dirty = true; |
330 |
|
} |
331 |
|
} |
332 |
|
} |