Use the composite pattern to create composite line aggregator. This example comes from the samples:
Code:
public class DelegatingTradeLineAggregator implements LineAggregator<Object> {
private LineAggregator<Trade> tradeLineAggregator;
private LineAggregator<CustomerCredit> customerLineAggregator;
public String aggregate(Object item) {
if (item instanceof Trade) {
return this.tradeLineAggregator.aggregate((Trade) item);
}
else if (item instanceof CustomerCredit) {
return this.customerLineAggregator.aggregate((CustomerCredit) item);
}
else {
throw new RuntimeException();
}
}
}