public void processSplitData ( Task task , List < TimephasedWork > timephasedComplete , List < TimephasedWork > timephasedPlanned ) { Date splitsComplete = null ; TimephasedWork lastComplete = null ; TimephasedWork firstPlanned = null ; if ( ! timephasedComplete . isEmpty ( ) ) { lastComplete = timephasedComplete . get ( timephasedComplete . size ( ) - 1 ) ; splitsComplete = lastComplete . getFinish ( ) ; } if ( ! timephasedPlanned . isEmpty ( ) ) { firstPlanned = timephasedPlanned . get ( 0 ) ; } LinkedList < DateRange > splits = new LinkedList < DateRange > ( ) ; TimephasedWork lastAssignment = null ; DateRange lastRange = null ; for ( TimephasedWork assignment : timephasedComplete ) { if ( lastAssignment != null && lastRange != null && lastAssignment . getTotalAmount ( ) . getDuration ( ) != 0 && assignment . getTotalAmount ( ) . getDuration ( ) != 0 ) { splits . removeLast ( ) ; lastRange = new DateRange ( lastRange . getStart ( ) , assignment . getFinish ( ) ) ; } else { lastRange = new DateRange ( assignment . getStart ( ) , assignment . getFinish ( ) ) ; } splits . add ( lastRange ) ; lastAssignment = assignment ; } // // We may not have a split, we may just have a partially // complete split. // Date splitStart = null ; if ( lastComplete != null && firstPlanned != null && lastComplete . getTotalAmount ( ) . getDuration ( ) != 0 && firstPlanned . getTotalAmount ( ) . getDuration ( ) != 0 ) { lastRange = splits . removeLast ( ) ; splitStart = lastRange . getStart ( ) ; } lastAssignment = null ; lastRange = null ; for ( TimephasedWork assignment : timephasedPlanned ) { if ( splitStart == null ) { if ( lastAssignment != null && lastRange != null && lastAssignment . getTotalAmount ( ) . getDuration ( ) != 0 && assignment . getTotalAmount ( ) . getDuration ( ) != 0 ) { splits . removeLast ( ) ; lastRange = new DateRange ( lastRange . getStart ( ) , assignment . getFinish ( ) ) ; } else { lastRange = new DateRange ( assignment . getStart ( ) , assignment . getFinish ( ) ) ; } } else { lastRange = new DateRange ( splitStart , assignment . getFinish ( ) ) ; } splits . add ( lastRange ) ; splitStart = null ; lastAssignment = assignment ; } // // We must have a minimum of 3 entries for this to be a valid split task // if ( splits . size ( ) > 2 ) { task . getSplits ( ) . addAll ( splits ) ; task . setSplitCompleteDuration ( splitsComplete ) ; } else { task . setSplits ( null ) ; task . setSplitCompleteDuration ( null ) ; } }
Process the timephased resource assignment data to work out the split structure of the task .