我有一个应该解析XML文件的类,如下所示:
...
123456
Mike
...
233658
...
12345
10.0
5
...
...
我将与JAXB解组,然后处理结果对象以获取统计信息(例如最大订单量,总订单量等)
在这种情况下,使用3级foreach循环是不好的做法吗?
public void getStatistics() {
for (Customer customer: this.customers.getCustomer()) {
BigDecimal customerTotalAmount = new BigDecimal(0);
for (Order order : customer.getOrders().getOrder()) {
BigDecimal orderAmount = new BigDecimal(0);
for (Position position : order.getPositions().getPosition()) {
orderAmount = orderAmount.add( position.getPrice().multiply(new BigDecimal(position.getCount())) );
}
customerTotalAmount = customerTotalAmount.add(orderAmount);
this.totalOrders++;
}
this.totalAmount = this.totalAmount.add(customerTotalAmount);
}
}
客户,订单和头寸类已从XSD架构自动生成,我认为更改它们不是很好.
我究竟做错了什么?如何避免这些嵌套循环?
谢谢.