*
* @param segments list of segment selected
* @return the final segment
*/
public Segment process(Collection<SelectedSegment> segments) {
Segment finalSegment = new Segment();
int amountOfSements = segments.size();
Iterator<SelectedSegment> it = segments.iterator();
int minAmount = Integer.MAX_VALUE;
while(it.hasNext()){
int current = it.next().getSegment().size();
minAmount = (minAmount>current)?current:minAmount;
}
int j = 0;
BigDecimal prom;
while ((minAmount>j)) {
prom = BigDecimal.ZERO;
Iterator<SelectedSegment> itSegments = segments.iterator();
while (itSegments.hasNext()) {
SelectedSegment selectedSegment = itSegments.next();
if ((selectedSegment.getSegment().size() > j)) {
prom = prom.add(selectedSegment.getSegment().elementAt(j));
}
}
finalSegment.add(prom.divide(new BigDecimal(amountOfSements),MathUtils.CONTEXT));
j++;
}
finalSegment = finalSegment.removeTrend();
return finalSegment;
}