private static ProcessWrapper[] topologicallyOrder( ProcessWrapper[] processes ) throws ProcessException
    {
    while( !isTopologicallyOrdered( processes ) )
      {
      List<ProcessWrapper> sorted = new LinkedList<ProcessWrapper>();

      sorted.add( processes[ 0 ] );

      for( int i = 1; i < processes.length; i++ )
        {
        ProcessWrapper process = processes[ i ];

        ListIterator<ProcessWrapper> iterator = sorted.listIterator();
        boolean inserted = false;

        while( iterator.hasNext() )
          {
          ProcessWrapper current = iterator.next();

          if( equalsOrContains( process.getDependencyIncoming(), current.getDependencyIncoming() ) )
            {
            iterator.add( process );
            inserted = true;
            break;
            }

          if( equalsOrContains( process.getDependencyIncoming(), current.getDependencyOutgoing() ) )
            {
            iterator.add( process );
            inserted = true;
            break;
            }

          if( equalsOrContains( current.getDependencyIncoming(), process.getDependencyOutgoing() ) )
            {
            iterator.remove();
            iterator.add( process );
            iterator.add( current );
            inserted = true;
            break;
            }
          }

        if( !inserted )
          sorted.add( 0, process );
        }

      processes = sorted.toArray( new ProcessWrapper[sorted.size()] );
      }

    return processes;
    }