Java Reference
In-Depth Information
2. Once the input is exhausted, the service method must return a null. This
indicates to Spring Batch that the input is exhausted for this step.
For this example, you will use a service hardcoded to return a Customer object for each call until the
list is exhausted. Once the List is exhausted, null will be returned for every call after. The
CustomerService in Listing 7-54 generates a random list of Customer objects for your use.
Listing 7-54. CustomerService
package com.apress.springbatch.chapter7;
import Java.util.ArrayList;
import Java.util.List;
import Java.util.Random;
public class CustomerService {
private List<Customer> customers;
private int curIndex;
private String [] firstNames = {"Michael", "Warren", "Ann", "Terrence",
"Erica", "Laura", "Steve", "Larry"};
private String middleInitial = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private String [] lastNames = {"Gates", "Darrow", "Donnelly", "Jobs",
"Buffett", "Ellison", "Obama"};
private String [] streets = {"4th Street", "Wall Street", "Fifth Avenue",
"Mt. Lee Drive", "Jeopardy Lane",
"Infinite Loop Drive", "Farnam Street",
"Isabella Ave", "S. Greenwood Ave"};
private String [] cities = {"Chicago", "New York", "Hollywood", "Aurora",
"Omaha", "Atherton"};
private String [] states = {"IL", "NY", "CA", "NE"};
private Random generator = new Random();
public CustomerService() {
curIndex = 0;
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(
Search WWH ::




Custom Search