public static List<ExecutionEntity> orderFromRootToLeaf(Collection<ExecutionEntity> executions){
  List<ExecutionEntity> orderedList=new ArrayList<ExecutionEntity>(executions.size());
  HashSet<String> previousIds=new HashSet<String>();
  for (  ExecutionEntity execution : executions) {
    if (execution.getParentId() == null) {
      orderedList.add(execution);
      previousIds.add(execution.getId());
    }
  }
  while (orderedList.size() < executions.size()) {
    for (    ExecutionEntity execution : executions) {
      if (!previousIds.contains(execution.getId()) && previousIds.contains(execution.getParentId())) {
        orderedList.add(execution);
        previousIds.add(execution.getId());
      }
    }
  }
  return orderedList;
}

public static List < ExecutionEntity > orderFromRootToLeaf ( Collection < ExecutionEntity > executions ) { List < ExecutionEntity > orderedList = new ArrayList < ExecutionEntity > ( executions . size ( ) ) ; HashSet < String > previousIds = new HashSet < String > ( ) ; for ( ExecutionEntity execution : executions ) { if ( execution . getParentId ( ) == null ) { orderedList . add ( execution ) ; previousIds . add ( execution . getId ( ) ) ; } } while ( orderedList . size ( ) < executions . size ( ) ) { for ( ExecutionEntity execution : executions ) { if ( ! previousIds . contains ( execution . getId ( ) ) && previousIds . contains ( execution . getParentId ( ) ) ) { orderedList . add ( execution ) ; previousIds . add ( execution . getId ( ) ) ; } } } return orderedList ; }
takes in a collection of executions belonging to the same process instance . orders the executions in a list , first elements are the leaf , last element is the root elements .
