Java Reference
In-Depth Information
private Random generator = new Random();
public CustomerItemReader() {
customers = new ArrayList<Customer>();
for(int i = 0; i < 100; i++) {
customers.add(buildCustomer());
}
}
private Customer buildCustomer() {
Customer customer = new Customer();
customer.setFirstName(
firstNames[generator.nextInt(firstNames.length - 1)]);
customer.setMiddleInitial(
String.valueOf(middleInitial.charAt(
generator.nextInt(middleInitial.length() - 1))));
customer.setLastName(
lastNames[generator.nextInt(lastNames.length - 1)]);
customer.setAddress(generator.nextInt(9999) + " " +
streets[generator.nextInt(streets.length - 1)]);
customer.setCity(cities[generator.nextInt(cities.length - 1)]);
customer.setState(states[generator.nextInt(states.length - 1)]);
customer.setZip(String.valueOf(generator.nextInt(99999)));
return customer;
}
public Customer read() {
Customer cust = null;
if(curIndex == 50) {
throw new RuntimeException("This will end your execution");
}
if(curIndex < customers.size()) {
cust = customers.get(curIndex);
curIndex++;
}
return cust;
}
public void close() throws ItemStreamException {
}
public void open(ExecutionContext executionContext) throws ItemStreamException {
if(executionContext.containsKey(INDEX_KEY)) {
int index = executionContext.getInt(INDEX_KEY);
if(index == 50) {
Search WWH ::




Custom Search