📄 comparatortest.java
字号:
//: c09:ComparatorTest.java
// Implementing a Comparator for a class.
import com.bruceeckel.simpletest.*;
import com.bruceeckel.util.*;
import java.util.*;
class CompTypeComparator implements Comparator {
public int compare(Object o1, Object o2) {
int j1 = ((CompType)o1).j;
int j2 = ((CompType)o2).j;
return (j1 < j2 ? -1 : (j1 == j2 ? 0 : 1));
}
}
public class ComparatorTest {
public static void main(String[] args) {
SimpleTest monitor =
new SimpleTest("ComparatorTest");
CompType[] a = new CompType[10];
Arrays2.fill(a, CompType.generator());
Arrays2.print("before sorting, a = ", a);
Arrays.sort(a, new CompTypeComparator());
Arrays2.print("after sorting, a = ", a);
monitor.expectRegularExpression(new Object[] {
new RegularExpression("before sorting, a = \\((\\[i = \\d{1,2}, j = \\d{1,2}\\](, ){0,1}){10}\\)"),
new RegularExpression("after sorting, a = \\((\\[i = \\d{1,2}, j = \\d{1,2}\\](, ){0,1}){10}\\)")});
}
} ///:~
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -