1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.internal

File AbstractNotifyOnUpdateList.java

 

Coverage histogram

../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

12
67
39
3
350
246
45
0.67
1.72
13
1.15

Classes

Class Line # Actions
AbstractNotifyOnUpdateList 35 52 0% 34 12
0.869565287%
AbstractNotifyOnUpdateList.Itr 259 5 0% 4 0
1.0100%
AbstractNotifyOnUpdateList.ListItr 297 10 0% 7 8
0.529411852.9%
 

Contributing tests

This file is covered by 355 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.internal;
21   
22    import java.util.Collection;
23    import java.util.Iterator;
24    import java.util.List;
25    import java.util.ListIterator;
26   
27    /**
28    * Generic list implementation with method to call when updating the list. This is used for the attachment list in
29    * XWikiDocument.
30    *
31    * @version $Id: 69e542a305c68f7c3c6cc2cbcaff43b87e98bcb4 $
32    * @since 4.3M2
33    * @param <E> type parameter.
34    */
 
35    public abstract class AbstractNotifyOnUpdateList<E> implements List<E>
36    {
37   
38    /** The list to wrap. */
39    private final List<E> list;
40   
41    /**
42    * @param list the list to wrap.
43    */
 
44  1314286 toggle protected AbstractNotifyOnUpdateList(List<E> list)
45    {
46  1314241 this.list = list;
47    }
48   
49    /** Called when the list is updated. The method will be called at least once, but may be called several times. */
50    protected abstract void onUpdate();
51   
 
52  56994 toggle @Override
53    public boolean add(E e)
54    {
55  56994 boolean ret = this.list.add(e);
56  56994 if (ret) {
57  56994 onUpdate();
58    }
59  56994 return ret;
60    }
61   
 
62  95 toggle @Override
63    public void add(int index, E element)
64    {
65  95 this.list.add(index, element);
66  95 onUpdate();
67    }
68   
 
69  736 toggle @Override
70    public boolean addAll(Collection<? extends E> c)
71    {
72  736 boolean ret = this.list.addAll(c);
73  736 if (ret) {
74  381 onUpdate();
75    }
76  736 return ret;
77    }
78   
 
79  1 toggle @Override
80    public boolean addAll(int index, Collection<? extends E> c)
81    {
82  1 boolean ret = this.list.addAll(index, c);
83  1 if (ret) {
84  1 onUpdate();
85    }
86  1 return ret;
87    }
88   
 
89  32100 toggle @Override
90    public void clear()
91    {
92  32099 this.list.clear();
93  32092 onUpdate();
94    }
95   
 
96  200 toggle @Override
97    public boolean contains(Object o)
98    {
99  200 return this.list.contains(o);
100    }
101   
 
102  1 toggle @Override
103    public boolean containsAll(Collection<?> c)
104    {
105  1 return this.list.containsAll(c);
106    }
107   
 
108  2 toggle @Override
109    public boolean equals(Object o)
110    {
111  2 return this.list.equals(o);
112    }
113   
 
114  61 toggle @Override
115    public E get(int index)
116    {
117  61 return this.list.get(index);
118    }
119   
 
120  0 toggle @Override
121    public int hashCode()
122    {
123  0 return this.list.hashCode();
124    }
125   
 
126  0 toggle @Override
127    public int indexOf(Object o)
128    {
129  0 return this.list.indexOf(o);
130    }
131   
 
132  120 toggle @Override
133    public boolean isEmpty()
134    {
135  120 return this.list.isEmpty();
136    }
137   
 
138  56169 toggle @Override
139    public Iterator<E> iterator()
140    {
141  56164 return new Itr(this.list.iterator());
142    }
143   
 
144  0 toggle @Override
145    public int lastIndexOf(Object o)
146    {
147  0 return this.list.lastIndexOf(o);
148    }
149   
 
150  17 toggle @Override
151    public ListIterator<E> listIterator()
152    {
153  17 return new ListItr(this.list.listIterator());
154    }
155   
 
156  0 toggle @Override
157    public ListIterator<E> listIterator(int index)
158    {
159  0 return new ListItr(this.list.listIterator(index));
160    }
161   
 
162  10 toggle @Override
163    public E remove(int index)
164    {
165  10 E ret = this.list.remove(index);
166  10 onUpdate();
167  10 return ret;
168    }
169   
 
170  7 toggle @Override
171    public boolean remove(Object o)
172    {
173  7 boolean ret = this.list.remove(o);
174  7 if (ret) {
175  6 onUpdate();
176    }
177  7 return ret;
178    }
179   
 
180  2 toggle @Override
181    public boolean removeAll(Collection<?> c)
182    {
183  2 boolean ret = this.list.removeAll(c);
184  2 if (ret) {
185  1 onUpdate();
186    }
187  2 return ret;
188    }
189   
 
190  2 toggle @Override
191    public boolean retainAll(Collection<?> c)
192    {
193  2 boolean ret = this.list.retainAll(c);
194  2 if (ret) {
195  1 onUpdate();
196    }
197  2 return ret;
198    }
199   
 
200  96 toggle @Override
201    public E set(int index, E element)
202    {
203  96 E ret = this.list.set(index, element);
204  96 onUpdate();
205  96 return ret;
206    }
207   
 
208  5164 toggle @Override
209    public int size()
210    {
211  5164 return this.list.size();
212    }
213   
 
214  2 toggle @Override
215    public List<E> subList(int fromIndex, int toIndex)
216    {
217  2 return new AbstractNotifyOnUpdateList<E>(this.list.subList(fromIndex, toIndex))
218    {
 
219  1 toggle @Override
220    public void onUpdate()
221    {
222  1 AbstractNotifyOnUpdateList.this.onUpdate();
223    }
224    };
225    }
226   
 
227  214 toggle @Override
228    public Object[] toArray()
229    {
230  214 return this.list.toArray();
231    }
232   
 
233  0 toggle @Override
234    public <T> T[] toArray(T[] a)
235    {
236  0 return this.list.toArray(a);
237    }
238   
239    /**
240    * {@inheritDoc}
241    * <p>
242    * NOTE: We override the default {@link Object#toString()} implementation in order to preserve backwards
243    * compatibility with code that was using {@link List#toString()} before we introduced
244    * {@link AbstractNotifyOnUpdateList}.
245    * </p>
246    *
247    * @see <a href="http://jira.xwiki.org/browse/XWIKI-9013">XWIKI-9013: Multiple Select List values are not correctly
248    * indexed by Lucene</a>
249    */
 
250  162 toggle @Override
251    public String toString()
252    {
253  162 return this.list.toString();
254    }
255   
256    /**
257    * Wrap iterator.
258    */
 
259    private class Itr implements Iterator<E>
260    {
261   
262    /** Wrapped iterator. */
263    private final Iterator<E> iterator;
264   
265    /**
266    * @param iterator wrapped iteratlr
267    */
 
268  56180 toggle Itr(Iterator<E> iterator)
269    {
270  56177 this.iterator = iterator;
271    }
272   
 
273  143992 toggle @Override
274    public boolean hasNext()
275    {
276  143994 return this.iterator.hasNext();
277    }
278   
 
279  92073 toggle @Override
280    public E next()
281    {
282  92068 return this.iterator.next();
283    }
284   
 
285  2 toggle @Override
286    public void remove()
287    {
288  2 this.iterator.remove();
289  2 onUpdate();
290    }
291   
292    }
293   
294    /**
295    * Wrap list iterator.
296    */
 
297    private class ListItr extends Itr implements ListIterator<E>
298    {
299   
300    /** The wrapped iterator. */
301    private final ListIterator<E> iterator;
302   
303    /**
304    * @param iterator wrapped iterator.
305    */
 
306  17 toggle ListItr(ListIterator<E> iterator)
307    {
308  17 super(iterator);
309  17 this.iterator = iterator;
310    }
311   
 
312  1 toggle @Override
313    public void add(E e)
314    {
315  1 this.iterator.add(e);
316  1 onUpdate();
317    }
318   
 
319  0 toggle @Override
320    public int nextIndex()
321    {
322  0 return this.iterator.nextIndex();
323    }
324   
 
325  0 toggle @Override
326    public boolean hasPrevious()
327    {
328  0 return this.iterator.hasPrevious();
329    }
330   
 
331  0 toggle @Override
332    public E previous()
333    {
334  0 return this.iterator.previous();
335    }
336   
 
337  0 toggle @Override
338    public int previousIndex()
339    {
340  0 return this.iterator.previousIndex();
341    }
342   
 
343  1 toggle @Override
344    public void set(E e)
345    {
346  1 this.iterator.set(e);
347  1 onUpdate();
348    }
349    }
350    }