1package org.junit.runner.manipulation;
2
3import java.util.Comparator;
4
5import org.junit.runner.Description;
6
7/**
8 * A <code>Sorter</code> orders tests. In general you will not need
9 * to use a <code>Sorter</code> directly. Instead, use {@link org.junit.runner.Request#sortWith(Comparator)}.
10 *
11 *
12 */
13public class Sorter implements Comparator<Description> {
14	/**
15	 * NULL is a <code>Sorter</code> that leaves elements in an undefined order
16	 */
17	public static Sorter NULL= new Sorter(new Comparator<Description>() {
18		public int compare(Description o1, Description o2) {
19			return 0;
20		}});
21	private final Comparator<Description> fComparator;
22
23	/**
24	 * Creates a <code>Sorter</code> that uses <code>comparator</code>
25	 * to sort tests
26	 * @param comparator the {@link Comparator} to use when sorting tests
27	 */
28	public Sorter(Comparator<Description> comparator) {
29		fComparator= comparator;
30	}
31
32	/**
33	 * Sorts the test in <code>runner</code> using <code>comparator</code>
34	 * @param object
35	 */
36	public void apply(Object object) {
37		if (object instanceof Sortable) {
38			Sortable sortable = (Sortable) object;
39			sortable.sort(this);
40		}
41	}
42
43	public int compare(Description o1, Description o2) {
44		return fComparator.compare(o1, o2);
45	}
46}
47