@Test public void testSortingTwoDependencies(){ Set<String> dep1 = new HashSet<>(Arrays.asList("e")); Set<String> dep2 = new HashSet<>(Arrays.asList("a", "c")); JobDefinition a = new JobDefinition(1, 1, "a", 0, dep1, null); JobDefinition b = new JobDefinition(1, 1, "b", 0, dep2, null); JobDefinition c = new JobDefinition(1, 1, "c", 0, null, null); JobDefinition d = new JobDefinition(1, 1, "d", 0, null, null); JobDefinition e = new JobDefinition(1, 1, "e", 0, null, null); List<JobDefinition> jobs = Arrays.asList(a,b,c,d,e); jobs = SeedingSchedule.getSortedToSatisfyDependencies(jobs); Assert.assertEquals("c",jobs.get(0).cut); Assert.assertEquals("d",jobs.get(1).cut); Assert.assertEquals("e",jobs.get(2).cut); Assert.assertEquals("a",jobs.get(3).cut); Assert.assertEquals("b",jobs.get(4).cut); }
protected static List<JobDefinition> getSortedToSatisfyDependencies(List<JobDefinition> jobs){ Queue<JobDefinition> toAssign = new LinkedList<>(jobs); List<JobDefinition> postponed = new LinkedList<>(); List<JobDefinition> out = new ArrayList<>(jobs.size()); Set<String> assigned = new HashSet<>(); mainLoop: while(!toAssign.isEmpty() || !postponed.isEmpty()){ JobDefinition chosenJob = null; if(!postponed.isEmpty()){ Iterator<JobDefinition> iterator = postponed.iterator(); postponedLoop : while(iterator.hasNext()){ JobDefinition job = iterator.next(); if(job.areDependenciesSatisfied(jobs,assigned)){ chosenJob = job; iterator.remove(); break postponedLoop; } } } if(chosenJob == null && toAssign.isEmpty()){ assert !postponed.isEmpty(); chosenJob = postponed.remove(0); } if(chosenJob == null){ assert !toAssign.isEmpty(); toExecuteLoop : while(!toAssign.isEmpty()){ JobDefinition job = toAssign.poll(); if(job.areDependenciesSatisfied(jobs,assigned)){ chosenJob = job; break toExecuteLoop; } else { postponed.add(job); } } if(chosenJob == null){ assert !postponed.isEmpty() && toAssign.isEmpty(); continue mainLoop; } } out.add(chosenJob); assigned.add(chosenJob.cut); } return out; }
SeedingSchedule extends OneTimeSchedule { protected static List<JobDefinition> getSortedToSatisfyDependencies(List<JobDefinition> jobs){ Queue<JobDefinition> toAssign = new LinkedList<>(jobs); List<JobDefinition> postponed = new LinkedList<>(); List<JobDefinition> out = new ArrayList<>(jobs.size()); Set<String> assigned = new HashSet<>(); mainLoop: while(!toAssign.isEmpty() || !postponed.isEmpty()){ JobDefinition chosenJob = null; if(!postponed.isEmpty()){ Iterator<JobDefinition> iterator = postponed.iterator(); postponedLoop : while(iterator.hasNext()){ JobDefinition job = iterator.next(); if(job.areDependenciesSatisfied(jobs,assigned)){ chosenJob = job; iterator.remove(); break postponedLoop; } } } if(chosenJob == null && toAssign.isEmpty()){ assert !postponed.isEmpty(); chosenJob = postponed.remove(0); } if(chosenJob == null){ assert !toAssign.isEmpty(); toExecuteLoop : while(!toAssign.isEmpty()){ JobDefinition job = toAssign.poll(); if(job.areDependenciesSatisfied(jobs,assigned)){ chosenJob = job; break toExecuteLoop; } else { postponed.add(job); } } if(chosenJob == null){ assert !postponed.isEmpty() && toAssign.isEmpty(); continue mainLoop; } } out.add(chosenJob); assigned.add(chosenJob.cut); } return out; } }
SeedingSchedule extends OneTimeSchedule { protected static List<JobDefinition> getSortedToSatisfyDependencies(List<JobDefinition> jobs){ Queue<JobDefinition> toAssign = new LinkedList<>(jobs); List<JobDefinition> postponed = new LinkedList<>(); List<JobDefinition> out = new ArrayList<>(jobs.size()); Set<String> assigned = new HashSet<>(); mainLoop: while(!toAssign.isEmpty() || !postponed.isEmpty()){ JobDefinition chosenJob = null; if(!postponed.isEmpty()){ Iterator<JobDefinition> iterator = postponed.iterator(); postponedLoop : while(iterator.hasNext()){ JobDefinition job = iterator.next(); if(job.areDependenciesSatisfied(jobs,assigned)){ chosenJob = job; iterator.remove(); break postponedLoop; } } } if(chosenJob == null && toAssign.isEmpty()){ assert !postponed.isEmpty(); chosenJob = postponed.remove(0); } if(chosenJob == null){ assert !toAssign.isEmpty(); toExecuteLoop : while(!toAssign.isEmpty()){ JobDefinition job = toAssign.poll(); if(job.areDependenciesSatisfied(jobs,assigned)){ chosenJob = job; break toExecuteLoop; } else { postponed.add(job); } } if(chosenJob == null){ assert !postponed.isEmpty() && toAssign.isEmpty(); continue mainLoop; } } out.add(chosenJob); assigned.add(chosenJob.cut); } return out; } SeedingSchedule(JobScheduler scheduler); protected  SeedingSchedule(JobScheduler scheduler, OneTimeSchedule base); }
SeedingSchedule extends OneTimeSchedule { protected static List<JobDefinition> getSortedToSatisfyDependencies(List<JobDefinition> jobs){ Queue<JobDefinition> toAssign = new LinkedList<>(jobs); List<JobDefinition> postponed = new LinkedList<>(); List<JobDefinition> out = new ArrayList<>(jobs.size()); Set<String> assigned = new HashSet<>(); mainLoop: while(!toAssign.isEmpty() || !postponed.isEmpty()){ JobDefinition chosenJob = null; if(!postponed.isEmpty()){ Iterator<JobDefinition> iterator = postponed.iterator(); postponedLoop : while(iterator.hasNext()){ JobDefinition job = iterator.next(); if(job.areDependenciesSatisfied(jobs,assigned)){ chosenJob = job; iterator.remove(); break postponedLoop; } } } if(chosenJob == null && toAssign.isEmpty()){ assert !postponed.isEmpty(); chosenJob = postponed.remove(0); } if(chosenJob == null){ assert !toAssign.isEmpty(); toExecuteLoop : while(!toAssign.isEmpty()){ JobDefinition job = toAssign.poll(); if(job.areDependenciesSatisfied(jobs,assigned)){ chosenJob = job; break toExecuteLoop; } else { postponed.add(job); } } if(chosenJob == null){ assert !postponed.isEmpty() && toAssign.isEmpty(); continue mainLoop; } } out.add(chosenJob); assigned.add(chosenJob.cut); } return out; } SeedingSchedule(JobScheduler scheduler); protected  SeedingSchedule(JobScheduler scheduler, OneTimeSchedule base);  }
SeedingSchedule extends OneTimeSchedule { protected static List<JobDefinition> getSortedToSatisfyDependencies(List<JobDefinition> jobs){ Queue<JobDefinition> toAssign = new LinkedList<>(jobs); List<JobDefinition> postponed = new LinkedList<>(); List<JobDefinition> out = new ArrayList<>(jobs.size()); Set<String> assigned = new HashSet<>(); mainLoop: while(!toAssign.isEmpty() || !postponed.isEmpty()){ JobDefinition chosenJob = null; if(!postponed.isEmpty()){ Iterator<JobDefinition> iterator = postponed.iterator(); postponedLoop : while(iterator.hasNext()){ JobDefinition job = iterator.next(); if(job.areDependenciesSatisfied(jobs,assigned)){ chosenJob = job; iterator.remove(); break postponedLoop; } } } if(chosenJob == null && toAssign.isEmpty()){ assert !postponed.isEmpty(); chosenJob = postponed.remove(0); } if(chosenJob == null){ assert !toAssign.isEmpty(); toExecuteLoop : while(!toAssign.isEmpty()){ JobDefinition job = toAssign.poll(); if(job.areDependenciesSatisfied(jobs,assigned)){ chosenJob = job; break toExecuteLoop; } else { postponed.add(job); } } if(chosenJob == null){ assert !postponed.isEmpty() && toAssign.isEmpty(); continue mainLoop; } } out.add(chosenJob); assigned.add(chosenJob.cut); } return out; } SeedingSchedule(JobScheduler scheduler); protected  SeedingSchedule(JobScheduler scheduler, OneTimeSchedule base);   }