KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > prevayler > demos > scalability > RecordIterator


1 package org.prevayler.demos.scalability;
2
3 import java.io.Serializable JavaDoc;
4 import java.util.Random JavaDoc;
5
6 /** Generates Record objects with ids from 0 to numberOfRecords - 1.
7 */

8 public class RecordIterator implements Serializable JavaDoc {
9
10     private int nextRecordId = 0;
11     private final int numberOfRecords;
12     private final Random JavaDoc _random = new Random JavaDoc(0);
13
14
15     public RecordIterator(int numberOfRecords) {
16         this.numberOfRecords = numberOfRecords;
17     }
18
19     public boolean hasNext() {
20         return nextRecordId < numberOfRecords;
21     }
22
23     public Record next() {
24         indicateProgress();
25         return new Record(nextRecordId++, _random);
26     }
27
28     private void indicateProgress() {
29         if (nextRecordId == 0) {
30             out("Creating " + numberOfRecords + " objects...");
31             return;
32         }
33         if (nextRecordId % 100000 == 0) out("" + nextRecordId + "...");
34     }
35
36     static private void out(Object JavaDoc message) {
37         System.out.println(message);
38     }
39 }
40
Popular Tags