package NFP.Algorithms; import java.io.IOException; import java.util.List; import org.apache.commons.httpclient.HttpException; import seg.jUCMNav.nfp.generated.*; public class AggregatePrices { private Price aggregatePrice; private Currency aggregateUnit; private List prices; private CompositionType Composition; public Price getAggregatePrice(Currency aggregateUnit, List prices, CompositionType Composition) { aggregatePrice = new Price(); this.aggregateUnit = aggregateUnit; this.Composition = Composition; this.prices = prices; aggregatePrice.setUnit(aggregateUnit); ExecuteAlgo(); return aggregatePrice; } private void ExecuteAlgo() { for (Price p : prices) { for (PriceElement pe : p.getPriceElements()) { PriceElement aggregatePE = null; for (PriceElement ape : aggregatePrice.getPriceElements()) { if (ape.getType() == pe.getType()) { aggregatePE = ape; } } if (aggregatePE == null) { aggregatePE = new PriceElement(); aggregatePE.setType(pe.getType()); aggregatePE.setValue(0); aggregatePrice.getPriceElements().add(aggregatePE); } ConvertCurrency CC = new ConvertCurrency(); double convertedValue = 0; try { convertedValue = CC.getConvertedValue(pe.getValue(), p.getUnit(), aggregateUnit); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (Composition == CompositionType.ConditionalBranching) { aggregatePE.setValue(Math.max(aggregatePE.getValue(), convertedValue)); } else { aggregatePE.setValue(aggregatePE.getValue() + convertedValue); } } } } }