protected void mergeSameCost ( LinkedList < TimephasedCost > list ) { LinkedList < TimephasedCost > result = new LinkedList < TimephasedCost > ( ) ; TimephasedCost previousAssignment = null ; for ( TimephasedCost assignment : list ) { if ( previousAssignment == null ) { assignment . setAmountPerDay ( assignment . getTotalAmount ( ) ) ; result . add ( assignment ) ; } else { Number previousAssignmentCost = previousAssignment . getAmountPerDay ( ) ; Number assignmentCost = assignment . getTotalAmount ( ) ; if ( NumberHelper . equals ( previousAssignmentCost . doubleValue ( ) , assignmentCost . doubleValue ( ) , 0.01 ) ) { Date assignmentStart = previousAssignment . getStart ( ) ; Date assignmentFinish = assignment . getFinish ( ) ; double total = previousAssignment . getTotalAmount ( ) . doubleValue ( ) ; total += assignmentCost . doubleValue ( ) ; TimephasedCost merged = new TimephasedCost ( ) ; merged . setStart ( assignmentStart ) ; merged . setFinish ( assignmentFinish ) ; merged . setAmountPerDay ( assignmentCost ) ; merged . setTotalAmount ( Double . valueOf ( total ) ) ; result . removeLast ( ) ; assignment = merged ; } else { assignment . setAmountPerDay ( assignment . getTotalAmount ( ) ) ; } result . add ( assignment ) ; } previousAssignment = assignment ; } list . clear ( ) ; list . addAll ( result ) ; }
This method merges together assignment data for the same cost .