@Test public void testSequence() { DependenciesScheduler<String> scheduler = new DependenciesScheduler<String>(); List<Collection<String>> schedule = scheduler.schedule(Collections.singleton(new DependsOn<String>("foo", "bar"))); assertEquals(2, schedule.size()); assertEquals(Sets.newHashSet(Collections.singleton("bar")), Sets.newHashSet(schedule.get(0))); assertEquals(Sets.newHashSet(Collections.singleton("foo")), Sets.newHashSet(schedule.get(1))); }
List<Collection<T>> schedule(Collection<DependsOn<T>> dependencies) { log.info("Scheduling: {}", dependencies); Map<T,Collection<T>> prerequisites = Maps.newHashMapWithExpectedSize(dependencies.size()); for (DependsOn<T> dependency : dependencies) { T first = dependency.getHappensFirst(); T next = dependency.getHappensNext(); if (!prerequisites.containsKey(first)) { prerequisites.put(first, Lists.<T>newArrayList()); } if (next != null) { Collection<T> required = prerequisites.get(next); if (required == null) { required = Lists.newArrayList(); prerequisites.put(next, required); } required.add(first); } } return schedule(prerequisites); }
DependenciesScheduler { List<Collection<T>> schedule(Collection<DependsOn<T>> dependencies) { log.info("Scheduling: {}", dependencies); Map<T,Collection<T>> prerequisites = Maps.newHashMapWithExpectedSize(dependencies.size()); for (DependsOn<T> dependency : dependencies) { T first = dependency.getHappensFirst(); T next = dependency.getHappensNext(); if (!prerequisites.containsKey(first)) { prerequisites.put(first, Lists.<T>newArrayList()); } if (next != null) { Collection<T> required = prerequisites.get(next); if (required == null) { required = Lists.newArrayList(); prerequisites.put(next, required); } required.add(first); } } return schedule(prerequisites); } }
DependenciesScheduler { List<Collection<T>> schedule(Collection<DependsOn<T>> dependencies) { log.info("Scheduling: {}", dependencies); Map<T,Collection<T>> prerequisites = Maps.newHashMapWithExpectedSize(dependencies.size()); for (DependsOn<T> dependency : dependencies) { T first = dependency.getHappensFirst(); T next = dependency.getHappensNext(); if (!prerequisites.containsKey(first)) { prerequisites.put(first, Lists.<T>newArrayList()); } if (next != null) { Collection<T> required = prerequisites.get(next); if (required == null) { required = Lists.newArrayList(); prerequisites.put(next, required); } required.add(first); } } return schedule(prerequisites); }  }
DependenciesScheduler { List<Collection<T>> schedule(Collection<DependsOn<T>> dependencies) { log.info("Scheduling: {}", dependencies); Map<T,Collection<T>> prerequisites = Maps.newHashMapWithExpectedSize(dependencies.size()); for (DependsOn<T> dependency : dependencies) { T first = dependency.getHappensFirst(); T next = dependency.getHappensNext(); if (!prerequisites.containsKey(first)) { prerequisites.put(first, Lists.<T>newArrayList()); } if (next != null) { Collection<T> required = prerequisites.get(next); if (required == null) { required = Lists.newArrayList(); prerequisites.put(next, required); } required.add(first); } } return schedule(prerequisites); }   }
DependenciesScheduler { List<Collection<T>> schedule(Collection<DependsOn<T>> dependencies) { log.info("Scheduling: {}", dependencies); Map<T,Collection<T>> prerequisites = Maps.newHashMapWithExpectedSize(dependencies.size()); for (DependsOn<T> dependency : dependencies) { T first = dependency.getHappensFirst(); T next = dependency.getHappensNext(); if (!prerequisites.containsKey(first)) { prerequisites.put(first, Lists.<T>newArrayList()); } if (next != null) { Collection<T> required = prerequisites.get(next); if (required == null) { required = Lists.newArrayList(); prerequisites.put(next, required); } required.add(first); } } return schedule(prerequisites); }    }