File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\model\queue\AbstractQueueSorterImpl.java.html

1 package hudson.model.queue;
2
3 import hudson.model.Queue.BuildableItem;
4
5 import java.util.Collections;
6 import java.util.Comparator;
7 import java.util.List;
8
9 /**
10 * Partial implementation of {@link QueueSorter} in terms of {@link Comparator}.
11 *
12 * @author Kohsuke Kawaguchi
13 * @since 1.343
14 */
15 public abstract class AbstractQueueSorterImpl extends QueueSorter implements Comparator<BuildableItem> {
16 @Override
17 public void sortBuildableItems(List<BuildableItem> buildables) {
18 Collections.sort(buildables,this); // sort is ascending order
19 }
20
21 /**
22 * Override this method to provide the ordering of the sort.
23 *
24 * <p>
25 * if lhs should be build before rhs, return a negative value. Or put another way, think of the comparison
26 * as a process of converting a {@link BuildableItem} into a number, then doing num(lhs)-num(rhs).
27 *
28 * <p>
29 * The default implementation does FIFO.
30 */
31 public int compare(BuildableItem lhs, BuildableItem rhs) {
32 return compare(lhs.buildableStartMilliseconds,rhs.buildableStartMilliseconds);
33 }
34
35 /**
36 * sign(a-b).
37 */
38 protected static int compare(long a, long b) {
39 if (a>b) return 1;
40 if (a<b) return -1;
41 return 0;
42 }
43
44 /**
45 * sign(a-b).
46 */
47 protected static int compare(int a, int b) {
48 if (a>b) return 1;
49 if (a<b) return -1;
50 return 0;
51 }
52 }
53