Clover.NET coverage report - Coverage

Coverage timestamp: Friday, May 20, 2005 9:17:00 PM

File Stats: LOC: 505   Methods: 35
NCLOC: 285 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Pagination\PaginatedArrayList.cs 0.0 % 0.0 % 0.0 % 0.0 %
coverage
1  
2   #region Apache Notice
3   /*****************************************************************************
4   * $Header: $
5   * $Revision: $
6   * $Date: $
7   *
8   * iBATIS.NET Data Mapper
9   * Copyright (C) 2004 - Gilles Bayon
10   *
11   *
12   * Licensed under the Apache License, Version 2.0 (the "License");
13   * you may not use this file except in compliance with the License.
14   * You may obtain a copy of the License at
15   *
16   * http://www.apache.org/licenses/LICENSE-2.0
17   *
18   * Unless required by applicable law or agreed to in writing, software
19   * distributed under the License is distributed on an "AS IS" BASIS,
20   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21   * See the License for the specific language governing permissions and
22   * limitations under the License.
23   *
24   ********************************************************************************/
25   #endregion
26  
27   #region Imports
28   using System;
29   using System.Collections;
30   #endregion
31  
32  
33   namespace IBatisNet.Common.Pagination
34   {
35   /// <summary>
36   /// Summary description for PaginatedArrayList.
37   /// </summary>
38   public class PaginatedArrayList: IPaginatedList
39   {
40  
41   #region Fields
42  
43   private static ArrayList _emptyList = new ArrayList();
44  
45   private int _pageSize = 0;
46   private int _pageIndex = 0;
47   private IList _list = null;
48   private IList _page = null;
49   #endregion
50  
51   #region Properties
52   /// <summary>
53   ///
54   /// </summary>
55 0 public bool IsEmpty
56   {
57   get
58   {
59   return (_page.Count == 0);
60   }
61   }
62   #endregion
63  
64   #region Constructor (s) / Destructor
65  
66   /// <summary>
67   ///
68   /// </summary>
69   /// <param name="pageSize"></param>
70 0 public PaginatedArrayList(int pageSize)
71   {
72   _pageSize = pageSize;
73   _pageIndex = 0;
74   _list = new ArrayList();
75   Repaginate();
76   }
77  
78   /// <summary>
79   ///
80   /// </summary>
81   /// <param name="initialCapacity"></param>
82   /// <param name="pageSize"></param>
83 0 public PaginatedArrayList(int initialCapacity, int pageSize)
84   {
85   _pageSize = pageSize;
86   _pageIndex = 0;
87   _list = new ArrayList(initialCapacity);
88   Repaginate();
89   }
90  
91   /// <summary>
92   ///
93   /// </summary>
94   /// <param name="c"></param>
95   /// <param name="pageSize"></param>
96 0 public PaginatedArrayList(ICollection c, int pageSize)
97   {
98   _pageSize = pageSize;
99   _pageIndex = 0;
100   _list = new ArrayList(c);
101   Repaginate();
102   }
103   #endregion
104  
105   #region Methods
106  
107   /// <summary>
108   ///
109   /// </summary>
110 0 private void Repaginate()
111   {
112   if (_list.Count==0)
113   {
114   _page = _emptyList;
115   }
116   else
117   {
118   int start = _pageIndex * _pageSize;
119   int end = start + _pageSize - 1;
120   if (end >= _list.Count)
121   {
122   end = _list.Count - 1;
123   }
124   if (start >= _list.Count)
125   {
126   _pageIndex = 0;
127   Repaginate();
128   }
129   else if (start < 0)
130   {
131   _pageIndex = _list.Count / _pageSize;
132   if (_list.Count % _pageSize == 0)
133   {
134   _pageIndex--;
135   }
136   Repaginate();
137   }
138   else
139   {
140   _page = SubList(_list, start, end + 1);
141   }
142   }
143   }
144  
145  
146   /// <summary>
147   /// Provides a view of the IList pramaeter
148   /// from the specified position <paramref name="fromIndex"/>
149   /// to the specified position <paramref name="toIndex"/>.
150   /// </summary>
151   /// <param name="list">The IList elements.</param>
152   /// <param name="fromIndex">Starting position for the view of elements. </param>
153   /// <param name="toIndex">Ending position for the view of elements. </param>
154   /// <returns> A view of list.
155   /// </returns>
156   /// <remarks>
157   /// The list that is returned is just a view, it is still backed
158   /// by the orignal list. Any changes you make to it will be
159   /// reflected in the orignal list.
160   /// </remarks>
161 0 private IList SubList(IList list, int fromIndex, int toIndex)
162   {
163   return ((ArrayList)list).GetRange(fromIndex, toIndex-fromIndex);
164   }
165   #endregion
166  
167   #region IPaginatedList Members
168  
169   /// <summary>
170   ///
171   /// </summary>
172 0 public int PageSize
173   {
174   get
175   {
176   return _pageSize;
177   }
178   }
179  
180   /// <summary>
181   ///
182   /// </summary>
183 0 public bool IsFirstPage
184   {
185   get
186   {
187   return (_pageIndex == 0);
188   }
189   }
190  
191   /// <summary>
192   ///
193   /// </summary>
194 0 public bool IsMiddlePage
195   {
196   get
197   {
198   return !(this.IsFirstPage || this.IsLastPage);
199   }
200   }
201  
202   /// <summary>
203   ///
204   /// </summary>
205 0 public bool IsLastPage
206   {
207   get
208   {
209   return _list.Count - ((_pageIndex + 1) * _pageSize) < 1;
210   }
211   }
212  
213   /// <summary>
214   ///
215   /// </summary>
216 0 public bool IsNextPageAvailable
217   {
218   get
219   {
220   return !this.IsLastPage;
221   }
222   }
223  
224   /// <summary>
225   ///
226   /// </summary>
227 0 public bool IsPreviousPageAvailable
228   {
229   get
230   {
231   return !this.IsFirstPage;
232   }
233   }
234  
235   /// <summary>
236   ///
237   /// </summary>
238   /// <returns></returns>
239 0 public bool NextPage()
240   {
241   if (this.IsNextPageAvailable)
242   {
243   _pageIndex++;
244   Repaginate();
245   return true;
246   }
247   else
248   {
249   return false;
250   }
251   }
252  
253   /// <summary>
254   ///
255   /// </summary>
256   /// <returns></returns>
257 0 public bool PreviousPage()
258   {
259   if (this.IsPreviousPageAvailable)
260   {
261   _pageIndex--;
262   Repaginate();
263   return true;
264   }
265   else
266   {
267   return false;
268   }
269   }
270  
271   /// <summary>
272   ///
273   /// </summary>
274   /// <param name="pageIndex"></param>
275 0 public void GotoPage(int pageIndex)
276   {
277   _pageIndex = pageIndex;
278   Repaginate();
279   }
280  
281   /// <summary>
282   ///
283   /// </summary>
284 0 public int PageIndex
285   {
286   get
287   {
288   return _pageIndex;
289   }
290   }
291  
292   #endregion
293  
294   #region IList Members
295  
296   /// <summary>
297   ///
298   /// </summary>
299 0 public bool IsReadOnly
300   {
301   get
302   {
303   return _list.IsReadOnly;
304   }
305   }
306  
307   /// <summary>
308   ///
309   /// </summary>
310 0 public object this[int index]
311   {
312   get
313   {
314   return _page[index];
315   }
316   set
317   {
318   _list[index] = value;
319   Repaginate();
320   }
321   }
322  
323   /// <summary>
324   ///
325   /// </summary>
326   /// <param name="index"></param>
327 0 public void RemoveAt(int index)
328   {
329   _list.RemoveAt(index);
330   Repaginate();
331   }
332  
333   /// <summary>
334   ///
335   /// </summary>
336   /// <param name="index"></param>
337   /// <param name="value"></param>
338 0 public void Insert(int index, object value)
339   {
340   _list.Insert(index, value);
341   Repaginate();
342   }
343  
344   /// <summary>
345   ///
346   /// </summary>
347   /// <param name="value"></param>
348 0 public void Remove(object value)
349   {
350   _list.Remove(value);
351   Repaginate();
352   }
353  
354   /// <summary>
355   ///
356   /// </summary>
357   /// <param name="value"></param>
358   /// <returns></returns>
359 0 public bool Contains(object value)
360   {
361   return _page.Contains(value);
362   }
363  
364   /// <summary>
365   ///
366   /// </summary>
367 0 public void Clear()
368   {
369   _list.Clear();
370   Repaginate();
371   }
372  
373   /// <summary>
374   ///
375   /// </summary>
376   /// <param name="value"></param>
377   /// <returns></returns>
378 0 public int IndexOf(object value)
379   {
380   return _page.IndexOf(value);
381   }
382  
383   /// <summary>
384   ///
385   /// </summary>
386   /// <param name="value"></param>
387   /// <returns></returns>
388 0 public int Add(object value)
389   {
390   int i = _list.Add(value);
391   Repaginate();
392   return i;
393   }
394  
395   /// <summary>
396   ///
397   /// </summary>
398 0 public bool IsFixedSize
399   {
400   get
401   {
402   return _list.IsFixedSize;
403   }
404   }
405  
406   #endregion
407  
408   #region ICollection Members
409  
410   /// <summary>
411   ///
412   /// </summary>
413 0 public bool IsSynchronized
414   {
415   get
416   {
417   return _page.IsSynchronized;
418   }
419   }
420  
421   /// <summary>
422   ///
423   /// </summary>
424 0 public int Count
425   {
426   get
427   {
428   return _page.Count;
429   }
430   }
431  
432   /// <summary>
433   ///
434   /// </summary>
435   /// <param name="array"></param>
436   /// <param name="index"></param>
437 0 public void CopyTo(Array array, int index)
438   {
439   _page.CopyTo(array, index);
440   }
441  
442   /// <summary>
443   ///
444   /// </summary>
445 0 public object SyncRoot
446   {
447   get
448   {
449   return _page.SyncRoot;
450   }
451   }
452  
453   #endregion
454  
455   #region IEnumerable Members
456  
457   /// <summary>
458   ///
459   /// </summary>
460   /// <returns></returns>
461 0 public IEnumerator GetEnumerator()
462   {
463   return _page.GetEnumerator();
464   }
465  
466   #endregion
467  
468   #region IEnumerator Members
469  
470   /// <summary>
471   /// Sets the enumerator to its initial position,
472   /// which is before the first element in the collection.
473   /// </summary>
474 0 public void Reset()
475   {
476   _page.GetEnumerator().Reset();
477   }
478  
479   /// <summary>
480   /// Gets the current element in the page.
481   /// </summary>
482 0 public object Current
483   {
484   get
485   {
486   return _page.GetEnumerator().Current;
487   }
488   }
489  
490   /// <summary>
491   /// Advances the enumerator to the next element of the collection.
492   /// </summary>
493   /// <returns>
494   /// true if the enumerator was successfully advanced to the next element;
495   /// false if the enumerator has passed the end of the collection.
496   /// </returns>
497 0 public bool MoveNext()
498   {
499   return _page.GetEnumerator().MoveNext();
500   }
501  
502   #endregion
503   }
504   }
505