Java Reference
In-Depth Information
PricingTier(int value) {
this.value = value;
}
public int getValue() {
return value;
}
public static PricingTier convert(Integer i) {
if(i != null && i >= 0) {
return values()[i];
} else {
return UNDEFINED;
}
}
public String toString() {
return name();
}
}
Now you can create your ItemProcessor. In this case, you assign the PricingTier based on the value
of the transactionCount field. With this simple logic, Listing 10-32 has the code for the new
PricingTierItemProcessor .
Listing 10-32. PricingTierItemProcessor
package com.apress.springbatch.statement.processor;
import java.util.ArrayList;
import java.util.List;
import org.springframework.batch.item.ItemProcessor;
import com.apress.springbatch.statement.domain.AccountTransactionQuantity;
import com.apress.springbatch.statement.domain.PricingTier;
public class PricingTierItemProcessor implements ItemProcessor<AccountTransactionQuantity,
AccountTransactionQuantity> {
private List<Integer> accountsProcessed = new ArrayList<Integer>();
public AccountTransactionQuantity process(AccountTransactionQuantity atq)
throws Exception {
if(atq.getTransactionCount() <= 1000) {
atq.setTier(PricingTier.I);
} else if(atq.getTransactionCount() > 1000 &&
atq.getTransactionCount() <= 100000) {
atq.setTier(PricingTier.II);
 
Search WWH ::




Custom Search