private int pruneHeadTasks ( Predicate < ReceiveMessageBatchTask > pruneCondition ) { int numberPruned = 0 ; while ( ! finishedTasks . isEmpty ( ) ) { if ( pruneCondition . test ( finishedTasks . getFirst ( ) ) ) { finishedTasks . removeFirst ( ) ; numberPruned ++ ; } else { break ; } } return numberPruned ; }
Prune all tasks at the beginning of the finishedTasks list that meet the given condition . Once a task is found that does not meet the given condition the pruning stops . This method assumes that you are holding the finishedTasks lock when invoking it .