blob: f0b12e26a1b1191150927283f266322ad2dc743a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.component.chain.dependencies.ordering;
import java.util.Comparator;
import java.util.PriorityQueue;
/**
* Ensures that Searchers are ordered deterministically.
*
* @author tonytv
*/
class OrderedReadyNodes {
private class PriorityComparator implements Comparator<Node> {
@Override
public int compare(Node lhs, Node rhs) {
int result = new Integer(lhs.classPriority()).compareTo(rhs.classPriority());
return result != 0 ?
result :
new Integer(lhs.priority).compareTo(rhs.priority);
}
}
final private PriorityQueue<Node> nodes =
new PriorityQueue<>(10, new PriorityComparator());
public void add(Node node) {
nodes.add(node);
}
public Node pop() {
return nodes.poll();
}
public boolean isEmpty() {
return nodes.isEmpty();
}
}
|