KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > util > cursor > CursorFactory


1 package org.sapia.util.cursor;
2
3 import org.sapia.util.cursor.impl.CursorImpl;
4
5 /**
6  * This class is a factory of <code>Cursor</code> instances.
7  * <p>
8  * Usage:
9  * <pre>
10  * // creating a cursor...
11  * CursorFactory cursors = new CursorFactory();
12  * cursors.setBatchSize(25);
13  * Cursor cursor = cursors.newInstance(someFeed);
14  *
15  * // playing with it...
16  *
17  * batch current = null;
18  *
19  * // moving forward
20  * while(cursor.hasNextBatch()){
21  * current = cursor.nextBatch();
22  * while(current.hasNext()){
23  * doSomethingWith(current.next());
24  * }
25  * }
26  *
27  * // moving backwards...
28  *
29  * if(current != null){
30  * while(current.hasPrevious()){
31  * doSomethingWith(current.previous());
32  * }
33  * while(cursor.hasPreviousBatch()){
34  * current = cursor.previousBatch();
35  * while(current.hasPrevious()){
36  * doSomethingWith(current.previous());
37  * }
38  * }
39  * }
40  *
41  * </pre>
42  *
43  * @author Yanick Duchesne
44  *
45  * <dl>
46  * <dt><b>Copyright: </b>
47  * <dd>Copyright &#169; 2002-2004 <a HREF="http://www.sapia-oss.org">Sapia Open
48  * Source Software </a>. All Rights Reserved.</dd>
49  * </dt>
50  * <dt><b>License: </b>
51  * <dd>Read the license.txt file of the jar or visit the <a
52  * HREF="http://www.sapia-oss.org/license.html">license page </a> at the Sapia
53  * OSS web site</dd>
54  * </dt>
55  * </dl>
56  */

57 public class CursorFactory {
58
59   /**
60    * The default batch size of the cursors that this instance creates.
61    */

62   public static final int DEFAULT_BATCH_SIZE = 10;
63
64   private int _batchSize = DEFAULT_BATCH_SIZE;
65
66   /**
67    * Creates a new cursor and returns it.
68    *
69    * @param feed
70    * a <code>CursorFeed</code> that will be used by the cursor to
71    * internally create <code>Batch</code> instances.
72    */

73   public Cursor newInstance(CursorFeed feed) {
74     return new CursorImpl(feed, null, _batchSize);
75   }
76
77   /**
78    * Creates a new cursor and returns it.
79    *
80    * @param feed
81    * a <code>CursorFeed</code>.
82    * @param listener
83    * a <code>CursorListener</code>.
84    * @return a <code>Cursor</code>.
85    */

86   public Cursor newInstance(CursorFeed feed, CursorListener listener) {
87     return new CursorImpl(feed, null, _batchSize);
88   }
89
90   /**
91    * @return this instance's configured batch size.
92    */

93   public int getBatchSize() {
94     return _batchSize;
95   }
96
97   /**
98    * Sets this instance's batch size.
99    *
100    * @param size
101    * a batch size.
102    */

103   public void setBatchSize(int size) {
104     _batchSize = size;
105   }
106
107 }
108
Popular Tags