### Question:
ProjectComparator { static <K> Comparator<K> create0(DependencyGraph<K> dependencyGraph, Map<String, AtomicLong> historicalServiceTimes, Function<K, String> toKey) { final long defaultServiceTime = average(historicalServiceTimes.values()); final Map<K, Long> serviceTimes = new HashMap<>(); final Set<K> rootProjects = new HashSet<>(); dependencyGraph.getProjects().forEach(project -> { long serviceTime = getServiceTime(historicalServiceTimes, project, defaultServiceTime, toKey); serviceTimes.put(project, serviceTime); if (dependencyGraph.isRoot(project)) { rootProjects.add(project); } }); final Map<K, Long> projectWeights = calculateWeights(dependencyGraph, serviceTimes, rootProjects); return Comparator.comparingLong((ToLongFunction<K>) projectWeights::get) .thenComparing(toKey, String::compareTo) .reversed(); }  static Comparator<MavenProject> create(DependencyGraph<MavenProject> graph);  }### Answer:
@Test public void testPriorityQueueOrder() { MavenProject a = newProject("a"), b = newProject("b"), c = newProject("c"); TestProjectDependencyGraph graph = new TestProjectDependencyGraph(a, b, c); graph.addDependency(b, a); DependencyGraph<MavenProject> dp = DependencyGraph.fromMaven(graph, null); Comparator<MavenProject> cmp = ProjectComparator.create0(dp, new HashMap<>(), ProjectComparator::id); Queue<MavenProject> queue = new PriorityQueue<>(3, cmp); queue.add(a); queue.add(b); queue.add(c); Assertions.assertEquals(a, queue.poll()); Assertions.assertEquals(c, queue.poll()); Assertions.assertEquals(b, queue.poll()); }