KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > util > cursor > impl > ListCursorFeed


1 package org.sapia.util.cursor.impl;
2
3 import java.util.List JavaDoc;
4
5 import org.sapia.util.cursor.CursorFeed;
6
7 /**
8  * Implements the <code>CursorFeed</code> interface over the
9  * <code>java.util.List</code> interface.
10  *
11  * @author Yanick Duchesne
12  *
13  * <dl>
14  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2004 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
15  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
16  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
17  * </dl>
18  */

19 public class ListCursorFeed implements CursorFeed{
20   
21   private List JavaDoc _feed;
22   private int _currentIndex;
23   private boolean _closed;
24   
25   public ListCursorFeed(List JavaDoc feed){
26     _feed = feed;
27   }
28   
29   /**
30    * @see org.sapia.util.cursor.CursorFeed#read(java.lang.Object[])
31    */

32   public int read(Object JavaDoc[] buffer) throws Exception JavaDoc {
33     int count = 0;
34     if(_closed || _currentIndex >= _feed.size()){
35       return 0;
36     }
37     for(; count < buffer.length; _currentIndex++, count++){
38       buffer[count] =_feed.get(_currentIndex);
39     }
40     return count;
41   }
42   
43   /**
44    * @see org.sapia.util.cursor.CursorFeed#available()
45    */

46   public int available() throws Exception JavaDoc {
47     if(_closed){
48       return 0;
49     }
50     return _feed.size() - _currentIndex;
51   }
52   
53   /**
54    * @see org.sapia.util.cursor.CursorFeed#close()
55    */

56   public void close() {
57     _closed = true;
58   }
59 }
60
Popular Tags