Example #1
0
  /** Construct the ExertionSorter */
  public ExertionSorter(Exertion topLevelJob) throws ContextException, SortingException {

    dag = new DAG();
    projectMap = new HashMap();
    contextIdsMap = new HashMap<String, String>();
    revContextIdsMap = new HashMap<String, String>();
    this.topLevelJob = topLevelJob;

    addVertex(this.topLevelJob);

    try {
      getMapping(this.topLevelJob);
      checkParentCycle(this.topLevelJob);

      List sortedProjects = new ArrayList();
      for (Iterator i = TopologicalSorter.sort(dag).iterator(); i.hasNext(); ) {
        String id = (String) i.next();
        sortedProjects.add(projectMap.get(id));
      }

      this.sortedProjects = Collections.unmodifiableList(sortedProjects);
      reorderJob(this.topLevelJob, this.sortedProjects);
    } catch (CycleDetectedException ce) {
      throw new SortingException(ce.getMessage());
    }
  }