1 package org.prevayler.demos.scalability; 2 3 import java.io.Serializable ; 4 import java.util.Random ; 5 6 8 public class RecordIterator implements Serializable { 9 10 private int nextRecordId = 0; 11 private final int numberOfRecords; 12 private final Random _random = new Random (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 message) { 37 System.out.println(message); 38 } 39 } 40 | Popular Tags |