blob: 7af863a37c3fc4a53c1c2a2a3275c6cb779f4d04 (
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
40
|
// Copyright 2017 Yahoo Holdings. 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 Tony Vaagenes
*/
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();
}
}
|